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 56B1A27AA9 for ; Tue, 21 May 2019 10:10:34 -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 OkBpX4pBHOZf for ; Tue, 21 May 2019 10:10:34 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (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 AB4BD205FC for ; Tue, 21 May 2019 10:10:33 -0400 (EDT) From: Nikita Pettik Subject: [tarantool-patches] [PATCH] sql: remove implicit CAST for assignment of int field Date: Tue, 21 May 2019 17:10:30 +0300 Message-Id: <20190521141030.59856-1-korablev@tarantool.org> 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 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