From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 dev.tarantool.org (Postfix) with ESMTPS id 0DA4B44532D for ; Thu, 16 Jul 2020 17:46:29 +0300 (MSK) From: imeevma@tarantool.org Date: Thu, 16 Jul 2020 17:46:27 +0300 Message-Id: <5d79fe3e2d6ac29b893df3f4e443878326f51b20.1594909974.git.imeevma@gmail.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v6 13/22] sql: check args of soundex() List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: korablev@tarantool.org, tsafin@tarantool.org, tarantool-patches@dev.tarantool.org After this patch, the argument types of the soundex() function will be checked properly. Part of #4159 --- src/box/sql/func.c | 11 +++----- test/sql-tap/func.test.lua | 2 +- test/sql-tap/func5.test.lua | 51 ++++++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index d2b968702..120e37522 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1820,12 +1820,9 @@ soundexFunc(sql_context * context, int argc, sql_value ** argv) }; assert(argc == 1); enum mp_type mp_type = sql_value_type(argv[0]); - if (mp_type_is_bloblike(mp_type)) { - diag_set(ClientError, ER_SQL_TYPE_MISMATCH, - sql_value_to_diag_str(argv[0]), "text"); - context->is_aborted = true; - return; - } + if (mp_type == MP_NIL) + return sql_result_null(context); + assert(mp_type == MP_BIN || mp_type == MP_STR); zIn = (u8 *) sql_value_text(argv[0]); if (zIn == 0) zIn = (u8 *) ""; @@ -2798,7 +2795,7 @@ static struct { }, { .name = "SOUNDEX", .param_count = 1, - .first_arg = FIELD_TYPE_ANY, + .first_arg = FIELD_TYPE_STRING, .args = FIELD_TYPE_ANY, .is_blob_like_str = false, .returns = FIELD_TYPE_STRING, diff --git a/test/sql-tap/func.test.lua b/test/sql-tap/func.test.lua index 9d8bf94ed..35e7be562 100755 --- a/test/sql-tap/func.test.lua +++ b/test/sql-tap/func.test.lua @@ -2938,7 +2938,7 @@ test:do_catchsql_test( SELECT SOUNDEX(X'FF') ]], { -- - 1, "Type mismatch: can not convert varbinary to text" + 1, "Type mismatch: can not convert varbinary to string" -- }) diff --git a/test/sql-tap/func5.test.lua b/test/sql-tap/func5.test.lua index 3351e398b..d2cddc56d 100755 --- a/test/sql-tap/func5.test.lua +++ b/test/sql-tap/func5.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool test = require("sqltester") -test:plan(127) +test:plan(134) --!./tcltestrunner.lua -- 2010 August 27 @@ -1032,4 +1032,53 @@ test:do_catchsql_test( 1, "Type mismatch: can not convert varbinary to double" }) +test:do_execsql_test( + "func-5-6.16.1", [[ + SELECT soundex(NULL); + ]],{ + "" + }) + +test:do_catchsql_test( + "func-5-6.16.2", [[ + SELECT soundex(123); + ]], { + 1, "Type mismatch: can not convert 123 to string" + }) + +test:do_catchsql_test( + "func-5-6.16.3", [[ + SELECT soundex(-123); + ]], { + 1, "Type mismatch: can not convert -123 to string" + }) + +test:do_catchsql_test( + "func-5-6.16.4", [[ + SELECT soundex(-5.5); + ]], { + 1, "Type mismatch: can not convert -5.5 to string" + }) + +test:do_execsql_test( + "func-5-6.16.5", [[ + SELECT soundex('-123'); + ]], { + "?000" + }) + +test:do_catchsql_test( + "func-5-6.16.6", [[ + SELECT soundex(false); + ]], { + 1, "Type mismatch: can not convert FALSE to string" + }) + +test:do_catchsql_test( + "func-5-6.16.7", [[ + SELECT soundex(X'3334'); + ]], { + 1, "Type mismatch: can not convert varbinary to string" + }) + test:finish_test() -- 2.25.1