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 DB0726EC45; Fri, 13 Aug 2021 06:21:36 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DB0726EC45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628824897; bh=zombOxKgmuWBKdgU6LJkKD6iDAmR0LTGebczmCSvd5Y=; 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=DoFYrr0PPDH7Mszyz3PGVWSSs8/qBiZuUzduyFKgxHUKoJ0q8JXGsW9secsaNXbPO mPsXm6ldptkJgmkYWTPE2MgTv8ZCIsN9LHLYPmbpts0KFs9vFcV6/YZ59X7Pa5Gdnf +73qsj2P9DJ+q+LYSGAfRid5tLAcPHCarTc5aXpI= 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 D865B6E478 for ; Fri, 13 Aug 2021 06:17:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D865B6E478 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mENhG-0003NE-4I; Fri, 13 Aug 2021 06:17:26 +0300 To: vdavydov@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 13 Aug 2021 06:17:25 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD910164DC12A5633065676A9727AC27C74182A05F5380850404F2BEAE0B62B34FD5790584521ED0F3C96440B0292588C483AEC02CE2907B8C7 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7661D1C86A3B4DE39EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637E88AB9B4A10918C78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D80BD96E78F893B4BBEA766CEAF3EDCC48117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B66F6A3E018CF4DC80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C69415AB31670C86C1F837705E891A5196856B55FD476ADFC9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFE37876E7723AB534DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D348F9E8EBB46231487531B0CA24CFB1A972DBF708B8536E8FADE98D64328CDA0C91E87DA2093D793241D7E09C32AA3244C34F94CADA890E5B36E00CF859AA762AD81560E2432555DBB729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj0dLV0c3jbkwX7QQdfHkj4w== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D3864718BE2A50909E94433D6246CC17983D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 09/10] sql: fix quote() function 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" Ater this patch SQL built-in function quite will return the same number in case it receives number as an argument. If the argument is not number, string representation of the argument will be returned. Part of #6105 --- src/box/sql/func.c | 18 ++------- test/sql-tap/built-in-functions.test.lua | 47 +++++++++++++++++++++++- test/sql-tap/trigger5.test.lua | 3 +- test/sql/types.result | 14 +++---- 4 files changed, 59 insertions(+), 23 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 8d9c5a7d9..98f7169c0 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1092,26 +1092,13 @@ quoteFunc(sql_context * context, int argc, sql_value ** argv) assert(argc == 1); UNUSED_PARAMETER(argc); switch (argv[0]->type) { - case MEM_TYPE_DOUBLE:{ - double r1, r2; - char zBuf[50]; - r1 = mem_get_double_unsafe(argv[0]); - sql_snprintf(sizeof(zBuf), zBuf, "%!.15g", r1); - sqlAtoF(zBuf, &r2, 20); - if (r1 != r2) { - sql_snprintf(sizeof(zBuf), zBuf, "%!.20e", - r1); - } - sql_result_text(context, zBuf, -1, - SQL_TRANSIENT); - break; - } case MEM_TYPE_UUID: { char buf[UUID_STR_LEN + 1]; tt_uuid_to_string(&argv[0]->u.uuid, &buf[0]); sql_result_text(context, buf, UUID_STR_LEN, SQL_TRANSIENT); break; } + case MEM_TYPE_DOUBLE: case MEM_TYPE_UINT: case MEM_TYPE_INT: { sql_result_value(context, argv[0]); @@ -2094,6 +2081,9 @@ static struct sql_func_definition definitions[] = { FIELD_TYPE_INTEGER, position_func, NULL}, {"PRINTF", -1, {FIELD_TYPE_ANY}, FIELD_TYPE_STRING, printfFunc, NULL}, + {"QUOTE", 1, {FIELD_TYPE_INTEGER}, FIELD_TYPE_INTEGER, quoteFunc, NULL}, + {"QUOTE", 1, {FIELD_TYPE_DOUBLE}, FIELD_TYPE_DOUBLE, quoteFunc, NULL}, + {"QUOTE", 1, {FIELD_TYPE_NUMBER}, FIELD_TYPE_NUMBER, quoteFunc, NULL}, {"QUOTE", 1, {FIELD_TYPE_ANY}, FIELD_TYPE_STRING, quoteFunc, NULL}, {"RANDOM", 0, {}, FIELD_TYPE_INTEGER, randomFunc, NULL}, {"RANDOMBLOB", 1, {FIELD_TYPE_INTEGER}, FIELD_TYPE_VARBINARY, diff --git a/test/sql-tap/built-in-functions.test.lua b/test/sql-tap/built-in-functions.test.lua index 6fae811dc..5fae8f357 100755 --- a/test/sql-tap/built-in-functions.test.lua +++ b/test/sql-tap/built-in-functions.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool local test = require("sqltester") -test:plan(52) +test:plan(56) -- -- Make sure that number of arguments check is checked properly for SQL built-in @@ -545,4 +545,49 @@ test:do_test( {name = "COLUMN_2", type = "scalar"}, }) +-- +-- Make sure QUOTE() returns the same number if it takes a number as an +-- argument, otherwise it returns a string. +-- +test:do_execsql_test( + "builtins-4.1", + [[ + SELECT QUOTE(1), 1 = QUOTE(1); + ]], + { + 1, true + } +) + +test:do_execsql_test( + "builtins-4.2", + [[ + SELECT QUOTE(1.5), 1.5 = QUOTE(1.5); + ]], + { + 1.5, true + } +) + +test:do_execsql_test( + "builtins-4.3", + [[ + SELECT QUOTE(CAST(1 AS NUMBER)), + CAST(1 AS NUMBER) = QUOTE(CAST(1 AS NUMBER)); + ]], + { + 1, true + } +) + +test:do_execsql_test( + "builtins-4.4", + [[ + SELECT QUOTE('1'), QUOTE(x'31'), QUOTE(true); + ]], + { + "'1'","X'31'","TRUE" + } +) + test:finish_test() diff --git a/test/sql-tap/trigger5.test.lua b/test/sql-tap/trigger5.test.lua index 8336cdcf2..7f3762126 100755 --- a/test/sql-tap/trigger5.test.lua +++ b/test/sql-tap/trigger5.test.lua @@ -31,7 +31,8 @@ test:do_execsql_test( INSERT INTO Undo VALUES ((SELECT coalesce(max(id),0) + 1 FROM Undo), (SELECT 'INSERT INTO Item (a,b,c) VALUES (' || CAST(coalesce(old.a,'NULL') AS TEXT) - || ',' || quote(old.b) || ',' || CAST(old.c AS TEXT) || ');')); + || ',' || CAST(quote(old.b) AS STRING) || ',' || + CAST(old.c AS TEXT) || ');')); END; DELETE FROM Item WHERE a = 1; SELECT * FROM Undo; diff --git a/test/sql/types.result b/test/sql/types.result index 3017793c6..ec80dfc14 100644 --- a/test/sql/types.result +++ b/test/sql/types.result @@ -847,7 +847,7 @@ box.execute("SELECT quote(i) FROM t;") --- - metadata: - name: COLUMN_1 - type: string + type: integer rows: - [18446744073709551613] ... @@ -863,7 +863,7 @@ box.execute("SELECT quote(i) FROM t;") --- - metadata: - name: COLUMN_1 - type: string + type: integer rows: - [18446744073709551613] ... @@ -1883,12 +1883,12 @@ box.execute("SELECT quote(d) FROM t;") --- - metadata: - name: COLUMN_1 - type: string + type: double rows: - - ['10.0'] - - ['-2.0'] - - ['3.3'] - - ['1.8e+19'] + - [10] + - [-2] + - [3.3] + - [18000000000000000000] ... box.execute("SELECT LEAST(d, 0) FROM t;") --- -- 2.25.1