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 C5B752E117 for ; Mon, 27 May 2019 16:47:41 -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 HjtK2v-sVuIQ for ; Mon, 27 May 2019 16:47:41 -0400 (EDT) Received: from smtp1.mail.ru (smtp1.mail.ru [94.100.179.111]) (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 810CB2E100 for ; Mon, 27 May 2019 16:47:41 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH] sql: remove implicit CAST for assignment of int field References: <20190521141030.59856-1-korablev@tarantool.org> From: Vladislav Shpilevoy Message-ID: <4ad5648b-af39-70c8-e75d-5e37dec7c104@tarantool.org> Date: Mon, 27 May 2019 23:47:37 +0300 MIME-Version: 1.0 In-Reply-To: <20190521141030.59856-1-korablev@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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, 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). >