From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id A16E36EC5B; Sat, 10 Apr 2021 00:09:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A16E36EC5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618002561; bh=oiKiK2VKCBQl2oks0NGE8t9XWdJsZ6ldcCtd6zU8bKc=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=EGgh4IhyEKOgdeet4n8h2xqFo7CgNwrkenc+trMXuYtjxRLkzq+AQCw3YRWgh37LB o2pBTHDqseZQ1Kj7GS40Ae+OK2A//eVfUjkXlzoTpzPWlFgv+fn4h0E8qvVmd6m4sS H+M+rI9lOJkRn0oos21Pd99yJktBVjmRpigrfFf8= Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 24D8C6EC5B for ; Sat, 10 Apr 2021 00:08:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 24D8C6EC5B Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1lUyMY-00043z-3M; Sat, 10 Apr 2021 00:08:22 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Sat, 10 Apr 2021 00:08:21 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E74806859AC5FE18436AEED970E897805ADA4182A05F538085040160B8F570B76EB247C565C7F20B7521D41B6B3EF0C5D35E1880DA06FEE2138F7 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E50C24D7D7C3118AC2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7DCDABBCBEAF682B1EA1F7E6F0F101C67CDEEF6D7F21E0D1D9295C2E9FA3191EE1B59CA4C82EFA658023EDFA77BF302F110FE350172B35B3CF6B57BC7E64490618DEB871D839B73339E8FC8737B5C2249E232F00D8D26902CA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10FC26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C33A60492226029A77089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C97831E46709FC235F5DF6FCB540272E22000E X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CD0035DD76F8A8A4F33FD14AE6A4D7D7B96BAB48A5B82B9649C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AF61ACC197BF517A5E55726EFEE0CC0EA4F41D16A87DEB47ECE6BAA54E063D16D6655DE9A273AC6C1D7E09C32AA3244C1BFBC4650A0EE511FED288EB8F07D66D853296C06374E602FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojqcJA+pXcDulVQJgRrcDY1w== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822692524FF6A8EEB6E5AA171720CC92C7683D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v5 48/52] sql: introduce mem_get_bool() X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This patch introduces mem_get_bool(). This function is used to receive boolean value from MEM. If value of MEM is not boolean, it is converted to boolean if possible. MEM is not changed. Part of #5818 --- src/box/sql/func.c | 5 +++-- src/box/sql/mem.c | 30 ++++++++++-------------------- src/box/sql/mem.h | 13 ++++++++----- src/box/sql/sqlInt.h | 3 --- src/box/sql/vdbeapi.c | 6 ------ 5 files changed, 21 insertions(+), 36 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index aeab06e2a..6a6970647 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1130,8 +1130,9 @@ quoteFunc(sql_context * context, int argc, sql_value ** argv) break; } case MP_BOOL: { - sql_result_text(context, - SQL_TOKEN_BOOLEAN(sql_value_boolean(argv[0])), + bool b; + mem_get_bool(argv[0], &b); + sql_result_text(context, SQL_TOKEN_BOOLEAN(b), -1, SQL_TRANSIENT); break; } diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 930c44bec..6f787f7cc 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -1313,6 +1313,16 @@ mem_get_double(const struct Mem *mem, double *d) return -1; } +int +mem_get_bool(const struct Mem *mem, bool *b) +{ + if ((mem->flags & MEM_Bool) != 0) { + *b = mem->u.b; + return 0; + } + return -1; +} + int mem_copy(struct Mem *to, const struct Mem *from) { @@ -2477,16 +2487,6 @@ releaseMemArray(Mem * p, int N) } } -int -mem_value_bool(const struct Mem *mem, bool *b) -{ - if ((mem->flags & MEM_Bool) != 0) { - *b = mem->u.b; - return 0; - } - return -1; -} - /**************************** sql_value_ ****************************** * The following routines extract information from a Mem or sql_value * structure. @@ -2513,16 +2513,6 @@ sql_value_bytes(sql_value * pVal) return sqlValueBytes(pVal); } -bool -sql_value_boolean(sql_value *val) -{ - bool b = false; - int rc = mem_value_bool((struct Mem *) val, &b); - assert(rc == 0); - (void) rc; - return b; -} - const unsigned char * sql_value_text(sql_value * pVal) { diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 34b0b3f13..e48e8788c 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -560,6 +560,14 @@ mem_get_uint(const struct Mem *mem, uint64_t *u); int mem_get_double(const struct Mem *mem, double *d); +/** + * Return value for MEM of BOOLEAN type. For MEM of all other types convert + * value of the MEM to BOOLEAN if possible and return converted value. Original + * MEM is not changed. + */ +int +mem_get_bool(const struct Mem *mem, bool *b); + /** * Simple type to str convertor. It is used to simplify * error reporting. @@ -612,17 +620,12 @@ releaseMemArray(Mem * p, int N); /** Getters. */ -int -mem_value_bool(const struct Mem *mem, bool *b); const void * sql_value_blob(struct Mem *); int sql_value_bytes(struct Mem *); -bool -sql_value_boolean(struct Mem *val); - const unsigned char * sql_value_text(struct Mem *); diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 3f6fa1722..df9469941 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -442,9 +442,6 @@ sql_column_bytes(sql_stmt *, int iCol); int sql_column_bytes16(sql_stmt *, int iCol); -bool -sql_column_boolean(struct sql_stmt *stmt, int column); - const unsigned char * sql_column_text(sql_stmt *, int iCol); diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index b1a9aed6e..1d3c23a70 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -484,12 +484,6 @@ sql_column_bytes(sql_stmt * pStmt, int i) return sql_value_bytes(columnMem(pStmt, i)); } -bool -sql_column_boolean(struct sql_stmt *stmt, int i) -{ - return sql_value_boolean(columnMem(stmt, i)); -} - const unsigned char * sql_column_text(sql_stmt * pStmt, int i) { -- 2.25.1