* [tarantool-patches] [PATCH] sql: remove implicit CAST for assignment of int field
@ 2019-05-21 14:10 Nikita Pettik
2019-05-27 20:47 ` [tarantool-patches] " Vladislav Shpilevoy
2019-05-28 1:42 ` Kirill Yukhin
0 siblings, 2 replies; 3+ messages in thread
From: Nikita Pettik @ 2019-05-21 14:10 UTC (permalink / raw)
To: tarantool-patches; +Cc: Nikita Pettik
It also fixes misbehaviour during insertion of boolean values to
integer field: explicit CAST operator converts boolean to integer,
meanwhile implicit cast doesn't.
---
Branch: https://github.com/tarantool/tarantool/tree/np/bool-to-int-implicit-cast
src/box/sql/insert.c | 14 +-------------
test/sql/types.result | 14 ++++++++++++++
test/sql/types.test.lua | 7 +++++++
3 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
index 1261ab9c8..2813415be 100644
--- a/src/box/sql/insert.c
+++ b/src/box/sql/insert.c
@@ -66,20 +66,8 @@ sql_emit_table_types(struct Vdbe *v, struct space_def *def, int reg)
(enum field_type *) sqlDbMallocZero(db, sz);
if (colls_type == NULL)
return;
- for (uint32_t i = 0; i < field_count; ++i) {
+ for (uint32_t i = 0; i < field_count; ++i)
colls_type[i] = def->fields[i].type;
- /*
- * Force INTEGER type to handle queries like:
- * CREATE TABLE t1 (id INT PRIMARY KEY);
- * INSERT INTO t1 VALUES (1.123);
- *
- * In this case 1.123 should be truncated to 1.
- */
- if (colls_type[i] == FIELD_TYPE_INTEGER) {
- sqlVdbeAddOp2(v, OP_Cast, reg + i,
- FIELD_TYPE_INTEGER);
- }
- }
colls_type[field_count] = field_type_MAX;
sqlVdbeAddOp4(v, OP_ApplyType, reg, field_count, 0,
(char *)colls_type, P4_DYNAMIC);
diff --git a/test/sql/types.result b/test/sql/types.result
index bc4518c01..ebdff3fe2 100644
--- a/test/sql/types.result
+++ b/test/sql/types.result
@@ -860,6 +860,20 @@ box.space.T:drop()
box.space.T1:drop()
---
...
+-- Make sure that BOOLEAN is not implicitly converted to INTEGER
+-- while inserted to PRIMARY KEY field.
+--
+box.execute("CREATE TABLE t1 (id INT PRIMARY KEY);")
+---
+- row_count: 1
+...
+box.execute("INSERT INTO t1 VALUES (true);")
+---
+- error: 'Type mismatch: can not convert true to integer'
+...
+box.space.T1:drop()
+---
+...
--
-- gh-4103: If resulting value of arithmetic operations is
-- integers, then make sure its type also integer (not number).
diff --git a/test/sql/types.test.lua b/test/sql/types.test.lua
index c51660cb9..75e3dfd98 100644
--- a/test/sql/types.test.lua
+++ b/test/sql/types.test.lua
@@ -206,6 +206,13 @@ box.execute("SELECT s FROM t1 WHERE s IN (true, 1, 'abcd')")
box.space.T:drop()
box.space.T1:drop()
+-- Make sure that BOOLEAN is not implicitly converted to INTEGER
+-- while inserted to PRIMARY KEY field.
+--
+box.execute("CREATE TABLE t1 (id INT PRIMARY KEY);")
+box.execute("INSERT INTO t1 VALUES (true);")
+box.space.T1:drop()
+
--
-- gh-4103: If resulting value of arithmetic operations is
-- integers, then make sure its type also integer (not number).
--
2.15.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tarantool-patches] Re: [PATCH] sql: remove implicit CAST for assignment of int field
2019-05-21 14:10 [tarantool-patches] [PATCH] sql: remove implicit CAST for assignment of int field Nikita Pettik
@ 2019-05-27 20:47 ` Vladislav Shpilevoy
2019-05-28 1:42 ` Kirill Yukhin
1 sibling, 0 replies; 3+ messages in thread
From: Vladislav Shpilevoy @ 2019-05-27 20:47 UTC (permalink / raw)
To: tarantool-patches, Nikita Pettik, Kirill Yukhin
LGTM.
On 21/05/2019 17:10, Nikita Pettik wrote:
> It also fixes misbehaviour during insertion of boolean values to
> integer field: explicit CAST operator converts boolean to integer,
> meanwhile implicit cast doesn't.
> ---
> Branch: https://github.com/tarantool/tarantool/tree/np/bool-to-int-implicit-cast
>
> src/box/sql/insert.c | 14 +-------------
> test/sql/types.result | 14 ++++++++++++++
> test/sql/types.test.lua | 7 +++++++
> 3 files changed, 22 insertions(+), 13 deletions(-)
>
> diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
> index 1261ab9c8..2813415be 100644
> --- a/src/box/sql/insert.c
> +++ b/src/box/sql/insert.c
> @@ -66,20 +66,8 @@ sql_emit_table_types(struct Vdbe *v, struct space_def *def, int reg)
> (enum field_type *) sqlDbMallocZero(db, sz);
> if (colls_type == NULL)
> return;
> - for (uint32_t i = 0; i < field_count; ++i) {
> + for (uint32_t i = 0; i < field_count; ++i)
> colls_type[i] = def->fields[i].type;
> - /*
> - * Force INTEGER type to handle queries like:
> - * CREATE TABLE t1 (id INT PRIMARY KEY);
> - * INSERT INTO t1 VALUES (1.123);
> - *
> - * In this case 1.123 should be truncated to 1.
> - */
> - if (colls_type[i] == FIELD_TYPE_INTEGER) {
> - sqlVdbeAddOp2(v, OP_Cast, reg + i,
> - FIELD_TYPE_INTEGER);
> - }
> - }
> colls_type[field_count] = field_type_MAX;
> sqlVdbeAddOp4(v, OP_ApplyType, reg, field_count, 0,
> (char *)colls_type, P4_DYNAMIC);
> diff --git a/test/sql/types.result b/test/sql/types.result
> index bc4518c01..ebdff3fe2 100644
> --- a/test/sql/types.result
> +++ b/test/sql/types.result
> @@ -860,6 +860,20 @@ box.space.T:drop()
> box.space.T1:drop()
> ---
> ...
> +-- Make sure that BOOLEAN is not implicitly converted to INTEGER
> +-- while inserted to PRIMARY KEY field.
> +--
> +box.execute("CREATE TABLE t1 (id INT PRIMARY KEY);")
> +---
> +- row_count: 1
> +...
> +box.execute("INSERT INTO t1 VALUES (true);")
> +---
> +- error: 'Type mismatch: can not convert true to integer'
> +...
> +box.space.T1:drop()
> +---
> +...
> --
> -- gh-4103: If resulting value of arithmetic operations is
> -- integers, then make sure its type also integer (not number).
> diff --git a/test/sql/types.test.lua b/test/sql/types.test.lua
> index c51660cb9..75e3dfd98 100644
> --- a/test/sql/types.test.lua
> +++ b/test/sql/types.test.lua
> @@ -206,6 +206,13 @@ box.execute("SELECT s FROM t1 WHERE s IN (true, 1, 'abcd')")
> box.space.T:drop()
> box.space.T1:drop()
>
> +-- Make sure that BOOLEAN is not implicitly converted to INTEGER
> +-- while inserted to PRIMARY KEY field.
> +--
> +box.execute("CREATE TABLE t1 (id INT PRIMARY KEY);")
> +box.execute("INSERT INTO t1 VALUES (true);")
> +box.space.T1:drop()
> +
> --
> -- gh-4103: If resulting value of arithmetic operations is
> -- integers, then make sure its type also integer (not number).
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tarantool-patches] Re: [PATCH] sql: remove implicit CAST for assignment of int field
2019-05-21 14:10 [tarantool-patches] [PATCH] sql: remove implicit CAST for assignment of int field Nikita Pettik
2019-05-27 20:47 ` [tarantool-patches] " Vladislav Shpilevoy
@ 2019-05-28 1:42 ` Kirill Yukhin
1 sibling, 0 replies; 3+ messages in thread
From: Kirill Yukhin @ 2019-05-28 1:42 UTC (permalink / raw)
To: tarantool-patches; +Cc: Nikita Pettik
Hello,
On 21 May 17:10, Nikita Pettik wrote:
> It also fixes misbehaviour during insertion of boolean values to
> integer field: explicit CAST operator converts boolean to integer,
> meanwhile implicit cast doesn't.
> ---
> Branch: https://github.com/tarantool/tarantool/tree/np/bool-to-int-implicit-cast
I've checked your patch into master.
--
Regards, Kirill Yukhin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-05-28 1:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-21 14:10 [tarantool-patches] [PATCH] sql: remove implicit CAST for assignment of int field Nikita Pettik
2019-05-27 20:47 ` [tarantool-patches] " Vladislav Shpilevoy
2019-05-28 1:42 ` Kirill Yukhin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox