From: Nikita Pettik <korablev@tarantool.org> To: tarantool-patches@freelists.org Cc: Nikita Pettik <korablev@tarantool.org> Subject: [tarantool-patches] [PATCH] sql: remove implicit CAST for assignment of int field Date: Tue, 21 May 2019 17:10:30 +0300 [thread overview] Message-ID: <20190521141030.59856-1-korablev@tarantool.org> (raw) 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
next reply other threads:[~2019-05-21 14:10 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-05-21 14:10 Nikita Pettik [this message] 2019-05-27 20:47 ` [tarantool-patches] " Vladislav Shpilevoy 2019-05-28 1:42 ` 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=20190521141030.59856-1-korablev@tarantool.org \ --to=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH] sql: remove implicit CAST for assignment of int field' \ /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