From: Kirill Shcherbatov <kshcherbatov@tarantool.org> To: tarantool-patches@freelists.org, korablev@tarantool.org Cc: Kirill Shcherbatov <kshcherbatov@tarantool.org> Subject: [tarantool-patches] [PATCH v1 1/1] sql: fix boolean variables binding Date: Thu, 25 Apr 2019 17:00:13 +0300 [thread overview] Message-ID: <b4869e842a8dbdb0cc5a1d68415f7f50d69dea41.1556200796.git.kshcherbatov@tarantool.org> (raw) 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
next reply other threads:[~2019-04-25 14:00 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-04-25 14:00 Kirill Shcherbatov [this message] 2019-04-25 14:52 ` [tarantool-patches] " n.pettik 2019-04-25 14:54 ` Kirill Shcherbatov 2019-04-26 10:37 ` Kirill Yukhin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=b4869e842a8dbdb0cc5a1d68415f7f50d69dea41.1556200796.git.kshcherbatov@tarantool.org \ --to=kshcherbatov@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH v1 1/1] sql: fix boolean variables binding' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox