From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 7BFD82C8F9 for ; Thu, 25 Apr 2019 10:00:17 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QzzNz1YrQ6aL for ; Thu, 25 Apr 2019 10:00:17 -0400 (EDT) Received: from smtp45.i.mail.ru (smtp45.i.mail.ru [94.100.177.105]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 2D6732C8D6 for ; Thu, 25 Apr 2019 10:00:17 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v1 1/1] sql: fix boolean variables binding Date: Thu, 25 Apr 2019 17:00:13 +0300 Message-Id: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org, korablev@tarantool.org Cc: Kirill Shcherbatov The bindings mechanism was not updated in scope of BOOLEAN static type patch. Fixed. --- Branch: http://github.com/tarantool/tarantool/tree/kshch/fix-bindings-for-bool src/box/bind.c | 7 ++++--- src/box/bind.h | 1 + src/box/sql/sqlInt.h | 11 +++++++++++ src/box/sql/vdbeapi.c | 12 ++++++++++++ test/sql/types.result | 9 +++++++++ test/sql/types.test.lua | 3 +++ 6 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/box/bind.c b/src/box/bind.c index 5aa79751a..b01ad4a74 100644 --- a/src/box/bind.c +++ b/src/box/bind.c @@ -98,8 +98,7 @@ sql_bind_decode(struct sql_bind *bind, int i, const char **packet) bind->bytes = 1; break; case MP_BOOL: - /* sql doesn't support boolean. Use int instead. */ - bind->i64 = mp_decode_bool(packet) ? 1 : 0; + bind->b = mp_decode_bool(packet); bind->bytes = sizeof(bind->i64); break; case MP_BIN: @@ -175,9 +174,11 @@ sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p, switch (p->type) { case MP_INT: case MP_UINT: - case MP_BOOL: rc = sql_bind_int64(stmt, pos, p->i64); break; + case MP_BOOL: + rc = sql_bind_boolean(stmt, pos, p->b); + break; case MP_DOUBLE: case MP_FLOAT: rc = sql_bind_double(stmt, pos, p->d); diff --git a/src/box/bind.h b/src/box/bind.h index a915381e4..d9823431e 100644 --- a/src/box/bind.h +++ b/src/box/bind.h @@ -61,6 +61,7 @@ struct sql_bind { enum mp_type type; /** Bind value. */ union { + bool b; double d; int64_t i64; /** For string or blob. */ diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 76ea9fb17..997a46535 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -888,6 +888,17 @@ sql_bind_blob64(sql_stmt *, int, const void *, int sql_bind_double(sql_stmt *, int, double); +/** + * Perform boolean parameter binding for the prepared sql + * statement. + * @param stmt Prepared statement. + * @param i Index of the variable to be binded. + * @param value Boolean value to use. + * @retval 0 On Success, not 0 otherwise. + */ +int +sql_bind_boolean(struct sql_stmt *stmt, int i, bool value); + int sql_bind_int(sql_stmt *, int, int); diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index 4175f7e86..d2868567b 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -1348,6 +1348,18 @@ sql_bind_double(sql_stmt * pStmt, int i, double rValue) return rc; } +int +sql_bind_boolean(struct sql_stmt *stmt, int i, bool value) +{ + struct Vdbe *p = (struct Vdbe *) stmt; + int rc = vdbeUnbind(p, i); + if (rc == SQL_OK) { + rc = sql_bind_type(p, i, "BOOLEAN"); + mem_set_bool(&p->aVar[i - 1], value); + } + return rc; +} + int sql_bind_int(sql_stmt * p, int i, int iValue) { diff --git a/test/sql/types.result b/test/sql/types.result index 8f442dc7d..bc4518c01 100644 --- a/test/sql/types.result +++ b/test/sql/types.result @@ -888,3 +888,12 @@ box.execute('SELECT \'9223372036854\' + 1;') rows: - [9223372036855] ... +-- Fix BOOLEAN bindings. +box.execute('SELECT ?', {true}) +--- +- metadata: + - name: '?' + type: BOOLEAN + rows: + - [true] +... diff --git a/test/sql/types.test.lua b/test/sql/types.test.lua index 48c9bde10..c51660cb9 100644 --- a/test/sql/types.test.lua +++ b/test/sql/types.test.lua @@ -213,3 +213,6 @@ box.space.T1:drop() box.execute('SELECT 1 + 1;') box.execute('SELECT 1 + 1.1;') box.execute('SELECT \'9223372036854\' + 1;') + +-- Fix BOOLEAN bindings. +box.execute('SELECT ?', {true}) -- 2.21.0