From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 09FB86EC58; Thu, 24 Jun 2021 13:31:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 09FB86EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1624530666; bh=Ati6S6hopckEaB2S0EQS4DnWYXSLW/NWpbl3QblS/dk=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=PEetQUHrZkkCcsVQRJy3xHwGCZvSwhqnwQrhCzdY4Y7L2QjaE2SUKXWM3WXGtQp1u v1n/d5Ry4AzxpTAFyGTp118o8P7kdNn6zUnnq1hB+aamkg7bQwt1j27vGyUcJqc7cE XzOHKasxuysmznSi1j9YiqW857xyh6WpdlfOVhYU= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id EFEAA6EC5F for ; Thu, 24 Jun 2021 13:30:33 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EFEAA6EC5F Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1lwMcz-0006gE-4g; Thu, 24 Jun 2021 13:30:33 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Thu, 24 Jun 2021 13:30:32 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD954DFF1DC42D673FB64496B12B6C6FB871CAFB561BC326F0E182A05F538085040C72F2DC44B6ABA0E2480F49483CDA7CF18623A648C9B0D8C8CA0738B786F6CB1 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E1AF754343915175C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE79389E7A2A88AA7BCEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BD6CF32B5F8F9D4046DCF46680E19FAD18314EDEE2E56DB15CC7F00164DA146DAFE8445B8C89999728AA50765F790063783E00425F71A4181389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC82FFDA4F57982C5F4F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8BDC0F6C5B2EEF3D0C75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CDFD85F345618D5681D5BF04C8B78D14094F290CB84C8E7279C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFF532FBFD8162E58C699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D346AD04FDA812EEFF1C4525F461A7FC998752D894615BE0995FFCB335EFECC915F2351BD76EE68C26C1D7E09C32AA3244C5E3FFADFAB56D91F280490DFC49AD99C7C0C08F7987826B9729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXiESzVYL70n5Q+AIw2MfNsV X-Mailru-Sender: 689FA8AB762F73936BC43F508A0638221C0A222CCB9C592E12BE94BE0AA3393483D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 1/2] sql: show varbinary in type mismatch error X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Currently, the word "varbinary" is printed instead of the value in the description of the type mismatch error. This is due to the problem of outputting binary values. However, this sometimes leads to confusion because in most other cases the value is printed. After this patch, instead of the word "varbinary", the actual value will be output in hexadecimal format in the description of the type mismatch error. Follow up #4356 --- src/box/sql/mem.c | 16 ++++++- test/sql-tap/cast.test.lua | 4 +- test/sql-tap/func.test.lua | 8 ++-- .../gh-5913-segfault-on-select-uuid.test.lua | 4 +- test/sql-tap/sql-errors.test.lua | 42 +++++++++++++++---- test/sql-tap/tkt-80e031a00f.test.lua | 4 +- test/sql-tap/uuid.test.lua | 4 +- test/sql/types.result | 28 ++++++------- 8 files changed, 73 insertions(+), 37 deletions(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 6f3bf52e5..c89c31fdc 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -86,8 +86,20 @@ mem_str(const struct Mem *mem) case MEM_TYPE_DOUBLE: sql_snprintf(BUF_SIZE, &buf[0], "%!.15g", mem->u.r); return tt_sprintf("%s", buf); - case MEM_TYPE_BIN: - return "varbinary"; + case MEM_TYPE_BIN: { + uint32_t svp = region_used(&fiber()->gc); + char *str = region_alloc(&fiber()->gc, mem->n * 2 + 1); + for (int i = 0; i < mem->n; ++i) { + int n = (mem->z[i] & 0xF0) >> 4; + str[2 * i] = n < 10 ? ('0' + n) : ('A' + n - 10); + n = (mem->z[i] & 0x0F); + str[2 * i + 1] = n < 10 ? ('0' + n) : ('A' + n - 10); + } + str[2 * mem->n] = '\0'; + const char *res = tt_sprintf("x'%s'", str); + region_truncate(&fiber()->gc, svp); + return res; + } case MEM_TYPE_MAP: case MEM_TYPE_ARRAY: return mp_str(mem->z); diff --git a/test/sql-tap/cast.test.lua b/test/sql-tap/cast.test.lua index 7de4b79df..4d098307c 100755 --- a/test/sql-tap/cast.test.lua +++ b/test/sql-tap/cast.test.lua @@ -70,7 +70,7 @@ test:do_catchsql_test( SELECT CAST(x'616263' AS NUMBER) ]], { -- - 1, 'Type mismatch: can not convert varbinary to number' + 1, "Type mismatch: can not convert x'616263' to number" -- }) @@ -100,7 +100,7 @@ test:do_catchsql_test( SELECT CAST(x'616263' AS integer) ]], { -- - 1, 'Type mismatch: can not convert varbinary to integer' + 1, "Type mismatch: can not convert x'616263' to integer" -- }) diff --git a/test/sql-tap/func.test.lua b/test/sql-tap/func.test.lua index 5e259f7ef..ae6bc9ddd 100755 --- a/test/sql-tap/func.test.lua +++ b/test/sql-tap/func.test.lua @@ -2931,7 +2931,7 @@ test:do_catchsql_test( SELECT ROUND(X'FF') ]], { -- - 1, "Type mismatch: can not convert varbinary to numeric" + 1, "Type mismatch: can not convert x'FF' to numeric" -- }) @@ -2941,7 +2941,7 @@ test:do_catchsql_test( SELECT RANDOMBLOB(X'FF') ]], { -- - 1, "Type mismatch: can not convert varbinary to numeric" + 1, "Type mismatch: can not convert x'FF' to numeric" -- }) @@ -2951,7 +2951,7 @@ test:do_catchsql_test( SELECT SOUNDEX(X'FF') ]], { -- - 1, "Type mismatch: can not convert varbinary to text" + 1, "Type mismatch: can not convert x'FF' to text" -- }) @@ -2961,7 +2961,7 @@ test:do_catchsql_test( SELECT SUM(X'FF') ]], { -- - 1, "Type mismatch: can not convert varbinary to number" + 1, "Type mismatch: can not convert x'FF' to number" -- }) diff --git a/test/sql-tap/gh-5913-segfault-on-select-uuid.test.lua b/test/sql-tap/gh-5913-segfault-on-select-uuid.test.lua index 7dcebe5d3..59a76000a 100755 --- a/test/sql-tap/gh-5913-segfault-on-select-uuid.test.lua +++ b/test/sql-tap/gh-5913-segfault-on-select-uuid.test.lua @@ -40,7 +40,7 @@ test:do_catchsql_test( [[ INSERT INTO t1 SELECT i, NULL, d FROM t; ]], { - 1, "Type mismatch: can not convert varbinary to decimal" + 1, "Type mismatch: can not convert x'C70501030111111C' to decimal" }) -- @@ -77,7 +77,7 @@ test:do_catchsql_test( [[ UPDATE td SET d = d; ]], { - 1, "Type mismatch: can not convert varbinary to decimal" + 1, "Type mismatch: can not convert x'C70501030111111C' to decimal" }) test:finish_test() diff --git a/test/sql-tap/sql-errors.test.lua b/test/sql-tap/sql-errors.test.lua index 469193a2b..25e14fb93 100755 --- a/test/sql-tap/sql-errors.test.lua +++ b/test/sql-tap/sql-errors.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool local test = require("sqltester") -test:plan(72) +test:plan(74) test:execsql([[ CREATE TABLE t0 (i INT PRIMARY KEY, a INT); @@ -687,7 +687,7 @@ test:do_catchsql_test( -- }) --- gh-4356: Make sure that 'varbinary' is printed instead of the +-- gh-4356: Make sure that varbinary is printed in hex instead of the -- binary data itself (since binary data can contain unprintable symbols). -- test:do_catchsql_test( @@ -696,7 +696,7 @@ test:do_catchsql_test( SELECT X'ff' + 1; ]], { -- - 1, "Type mismatch: can not convert varbinary to numeric" + 1, "Type mismatch: can not convert x'FF' to numeric" -- }) @@ -706,7 +706,7 @@ test:do_catchsql_test( SELECT X'ff' - 1; ]], { -- - 1, "Type mismatch: can not convert varbinary to numeric" + 1, "Type mismatch: can not convert x'FF' to numeric" -- }) @@ -716,7 +716,7 @@ test:do_catchsql_test( SELECT X'ff' * 1; ]], { -- - 1, "Type mismatch: can not convert varbinary to numeric" + 1, "Type mismatch: can not convert x'FF' to numeric" -- }) @@ -726,7 +726,7 @@ test:do_catchsql_test( SELECT X'ff' / 1; ]], { -- - 1, "Type mismatch: can not convert varbinary to numeric" + 1, "Type mismatch: can not convert x'FF' to numeric" -- }) @@ -736,7 +736,7 @@ test:do_catchsql_test( SELECT X'ff' AND true; ]], { -- - 1, "Type mismatch: can not convert varbinary to boolean" + 1, "Type mismatch: can not convert x'FF' to boolean" -- }) @@ -746,7 +746,7 @@ test:do_catchsql_test( SELECT X'ff' OR false; ]], { -- - 1, "Type mismatch: can not convert varbinary to boolean" + 1, "Type mismatch: can not convert x'FF' to boolean" -- }) @@ -756,7 +756,7 @@ test:do_catchsql_test( SELECT false OR X'ff'; ]], { -- - 1, "Type mismatch: can not convert varbinary to boolean" + 1, "Type mismatch: can not convert x'FF' to boolean" -- }) @@ -780,4 +780,28 @@ test:do_catchsql_test( -- }) +test:do_catchsql_test( + "sql-errors-2.10", + [[ + SELECT CAST(x'F1' AS UNSIGNED); + ]], { + -- + 1, "Type mismatch: can not convert x'F1' to unsigned" + -- + }) + +test:execsql('CREATE TABLE test (i INT PRIMARY KEY);') + +test:do_catchsql_test( + "sql-errors-2.12", + [[ + INSERT INTO test VALUES(x'F1'); + ]], { + -- + 1, "Type mismatch: can not convert x'F1' to integer" + -- + }) + +test:execsql('DROP TABLE test;') + test:finish_test() diff --git a/test/sql-tap/tkt-80e031a00f.test.lua b/test/sql-tap/tkt-80e031a00f.test.lua index 82769587b..23ef896c0 100755 --- a/test/sql-tap/tkt-80e031a00f.test.lua +++ b/test/sql-tap/tkt-80e031a00f.test.lua @@ -386,7 +386,7 @@ test:do_catchsql_test( SELECT x'303132' IN t1 ]], { -- - 1, 'Type mismatch: can not convert varbinary to integer' + 1, "Type mismatch: can not convert x'303132' to integer" -- }) @@ -396,7 +396,7 @@ test:do_catchsql_test( SELECT x'303132' NOT IN t1 ]], { -- - 1, 'Type mismatch: can not convert varbinary to integer' + 1, "Type mismatch: can not convert x'303132' to integer" -- }) diff --git a/test/sql-tap/uuid.test.lua b/test/sql-tap/uuid.test.lua index 77ba06c2d..f19eb4a9c 100755 --- a/test/sql-tap/uuid.test.lua +++ b/test/sql-tap/uuid.test.lua @@ -697,7 +697,7 @@ test:do_catchsql_test( [[ SELECT cast(randomblob(10) as UUID) FROM t2 LIMIT 1; ]], { - 1, "Type mismatch: can not convert varbinary to uuid" + 1, "Type mismatch: can not convert x'819192E578DE3FA24AF3' to uuid" }) test:execsql([[ @@ -858,7 +858,7 @@ test:do_catchsql_test( [[ INSERT INTO tsu VALUES ('8_varbinary', randomblob(10)); ]], { - 1, "Type mismatch: can not convert varbinary to uuid" + 1, "Type mismatch: can not convert x'733CA8769291A0FEE366' to uuid" }) test:execsql([[ diff --git a/test/sql/types.result b/test/sql/types.result index 687ca3b15..f9fc606a7 100644 --- a/test/sql/types.result +++ b/test/sql/types.result @@ -339,7 +339,7 @@ box.execute("INSERT INTO tboolean VALUES (TRUE);") box.execute("SELECT * FROM tboolean WHERE s1 = x'44';") --- - null -- 'Type mismatch: can not convert varbinary to boolean' +- 'Type mismatch: can not convert x''44'' to boolean' ... box.execute("SELECT * FROM tboolean WHERE s1 = 'abc';") --- @@ -1265,17 +1265,17 @@ box.execute("SELECT * FROM t WHERE v = x'616263'") box.execute("SELECT sum(v) FROM t;") --- - null -- 'Type mismatch: can not convert varbinary to number' +- 'Type mismatch: can not convert x''616263'' to number' ... box.execute("SELECT avg(v) FROM t;") --- - null -- 'Type mismatch: can not convert varbinary to number' +- 'Type mismatch: can not convert x''616263'' to number' ... box.execute("SELECT total(v) FROM t;") --- - null -- 'Type mismatch: can not convert varbinary to number' +- 'Type mismatch: can not convert x''616263'' to number' ... box.execute("SELECT min(v) FROM t;") --- @@ -1747,12 +1747,12 @@ box.execute("SELECT CAST('1.123' AS DOUBLE);") box.execute("SELECT CAST(x'' AS DOUBLE);") --- - null -- 'Type mismatch: can not convert varbinary to double' +- 'Type mismatch: can not convert x'''' to double' ... box.execute("SELECT CAST(x'35' AS DOUBLE);") --- - null -- 'Type mismatch: can not convert varbinary to double' +- 'Type mismatch: can not convert x''35'' to double' ... box.execute("SELECT CAST(CAST(x'35' AS STRING) AS DOUBLE);") --- @@ -2218,7 +2218,7 @@ box.execute([[INSERT INTO ti(i) VALUES ('33');]]) box.execute([[INSERT INTO ti(i) VALUES (X'3434');]]) --- - null -- 'Type mismatch: can not convert varbinary to integer' +- 'Type mismatch: can not convert x''3434'' to integer' ... box.execute([[SELECT * FROM ti;]]) --- @@ -2268,7 +2268,7 @@ box.execute([[INSERT INTO td(d) VALUES ('33');]]) box.execute([[INSERT INTO td(d) VALUES (X'3434');]]) --- - null -- 'Type mismatch: can not convert varbinary to double' +- 'Type mismatch: can not convert x''3434'' to double' ... box.execute([[SELECT * FROM td;]]) --- @@ -2312,7 +2312,7 @@ box.execute([[INSERT INTO tb(b) VALUES ('33');]]) box.execute([[INSERT INTO tb(b) VALUES (X'3434');]]) --- - null -- 'Type mismatch: can not convert varbinary to boolean' +- 'Type mismatch: can not convert x''3434'' to boolean' ... box.execute([[SELECT * FROM tb;]]) --- @@ -2355,7 +2355,7 @@ box.execute([[INSERT INTO tt(t) VALUES ('33');]]) box.execute([[INSERT INTO tt(t) VALUES (X'3434');]]) --- - null -- 'Type mismatch: can not convert varbinary to string' +- 'Type mismatch: can not convert x''3434'' to string' ... box.execute([[SELECT * FROM tt;]]) --- @@ -2571,7 +2571,7 @@ box.execute([[UPDATE ti SET i = '33' WHERE a = 1;]]) box.execute([[UPDATE ti SET i = X'3434' WHERE a = 1;]]) --- - null -- 'Type mismatch: can not convert varbinary to integer' +- 'Type mismatch: can not convert x''3434'' to integer' ... box.execute([[SELECT * FROM ti;]]) --- @@ -2612,7 +2612,7 @@ box.execute([[UPDATE td SET d = '33' WHERE a = 1;]]) box.execute([[UPDATE td SET d = X'3434' WHERE a = 1;]]) --- - null -- 'Type mismatch: can not convert varbinary to double' +- 'Type mismatch: can not convert x''3434'' to double' ... box.execute([[SELECT * FROM td;]]) --- @@ -2650,7 +2650,7 @@ box.execute([[UPDATE tb SET b = '33' WHERE a = 1;]]) box.execute([[UPDATE tb SET b = X'3434' WHERE a = 1;]]) --- - null -- 'Type mismatch: can not convert varbinary to boolean' +- 'Type mismatch: can not convert x''3434'' to boolean' ... box.execute([[SELECT * FROM tb;]]) --- @@ -2688,7 +2688,7 @@ box.execute([[UPDATE tt SET t = '33' WHERE a = 1;]]) box.execute([[UPDATE tt SET t = X'3434' WHERE a = 1;]]) --- - null -- 'Type mismatch: can not convert varbinary to string' +- 'Type mismatch: can not convert x''3434'' to string' ... box.execute([[SELECT * FROM tt;]]) --- -- 2.25.1