Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH v1 1/1] sql: fix boolean variables binding
@ 2019-04-25 14:00 Kirill Shcherbatov
  2019-04-25 14:52 ` [tarantool-patches] " n.pettik
  2019-04-26 10:37 ` Kirill Yukhin
  0 siblings, 2 replies; 4+ messages in thread
From: Kirill Shcherbatov @ 2019-04-25 14:00 UTC (permalink / raw)
  To: tarantool-patches, korablev; +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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tarantool-patches] Re: [PATCH v1 1/1] sql: fix boolean variables binding
  2019-04-25 14:00 [tarantool-patches] [PATCH v1 1/1] sql: fix boolean variables binding Kirill Shcherbatov
@ 2019-04-25 14:52 ` n.pettik
  2019-04-25 14:54   ` Kirill Shcherbatov
  2019-04-26 10:37 ` Kirill Yukhin
  1 sibling, 1 reply; 4+ messages in thread
From: n.pettik @ 2019-04-25 14:52 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Kirill Shcherbatov


> 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);

sizeof(bind->b);

The rest is OK as obvious.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tarantool-patches] Re: [PATCH v1 1/1] sql: fix boolean variables binding
  2019-04-25 14:52 ` [tarantool-patches] " n.pettik
@ 2019-04-25 14:54   ` Kirill Shcherbatov
  0 siblings, 0 replies; 4+ messages in thread
From: Kirill Shcherbatov @ 2019-04-25 14:54 UTC (permalink / raw)
  To: n.pettik, tarantool-patches

> sizeof(bind->b);
> 
> The rest is OK as obvious..
Done. Tnx.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tarantool-patches] Re: [PATCH v1 1/1] sql: fix boolean variables binding
  2019-04-25 14:00 [tarantool-patches] [PATCH v1 1/1] sql: fix boolean variables binding Kirill Shcherbatov
  2019-04-25 14:52 ` [tarantool-patches] " n.pettik
@ 2019-04-26 10:37 ` Kirill Yukhin
  1 sibling, 0 replies; 4+ messages in thread
From: Kirill Yukhin @ 2019-04-26 10:37 UTC (permalink / raw)
  To: tarantool-patches; +Cc: korablev, Kirill Shcherbatov

Hello,

On 25 Apr 17:00, Kirill Shcherbatov wrote:
> 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

I've checked your patch into master.

--
Regards, Kirill Yukhin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-04-26 10:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-25 14:00 [tarantool-patches] [PATCH v1 1/1] sql: fix boolean variables binding Kirill Shcherbatov
2019-04-25 14:52 ` [tarantool-patches] " n.pettik
2019-04-25 14:54   ` Kirill Shcherbatov
2019-04-26 10:37 ` Kirill Yukhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox