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 8D86826E01 for ; Fri, 16 Aug 2019 09:27:03 -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 gwIV9JRHdB8U for ; Fri, 16 Aug 2019 09:27:03 -0400 (EDT) Received: from smtp60.i.mail.ru (smtp60.i.mail.ru [217.69.128.40]) (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 08305272C9 for ; Fri, 16 Aug 2019 09:27:03 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v3 9/9] sql: better error messages on invalid arguments Date: Fri, 16 Aug 2019 16:26:55 +0300 Message-Id: <52af0f269862c4fe87d1fa0684143a9518327100.1565961887.git.kshcherbatov@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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, korablev@tarantool.org Cc: Kirill Shcherbatov Previous error message was not informative enough: "wrong number of arguments to function". An updated code provide more information in such case, when possible: "invalid number of arguments is passed to FUNCTION_NAME: expected n, got m". --- src/box/sql/resolve.c | 14 +++++++++++--- test/box/function1.result | 10 +++++----- test/sql-tap/func.test.lua | 22 +++++++++++----------- test/sql-tap/func2.test.lua | 18 +++++++++--------- test/sql-tap/limit.test.lua | 4 ++-- test/sql-tap/select1.test.lua | 12 ++++++------ test/sql/icu-upper-lower.result | 4 ++-- 7 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/box/sql/resolve.c b/src/box/sql/resolve.c index 682bb9c8e..2c037a5a4 100644 --- a/src/box/sql/resolve.c +++ b/src/box/sql/resolve.c @@ -678,10 +678,18 @@ resolveExprStep(Walker * pWalker, Expr * pExpr) pParse->is_aborted = true; pNC->nErr++; } else if (wrong_num_args) { - const char *err = "wrong number of arguments "\ - "to function %.*s()"; + const char *err; + if (func->def->param_count >= 0) { + err = "invalid number of arguments is " + "passed to %.*s(): expected %d, " + "got %d"; + } else { + err = "invalid number of arguments is " + "passed to %.*s()"; + } diag_set(ClientError, ER_SQL_PARSER_GENERIC, - tt_sprintf(err, nId, zId)); + tt_sprintf(err, nId, zId, + func->def->param_count, n)); pParse->is_aborted = true; pNC->nErr++; } diff --git a/test/box/function1.result b/test/box/function1.result index ebd9be700..25c470d0e 100644 --- a/test/box/function1.result +++ b/test/box/function1.result @@ -405,12 +405,12 @@ box.execute('SELECT "function1.divide"()') box.execute('SELECT "function1.divide"(6)') --- - null -- wrong number of arguments to function function1.divide() +- 'invalid number of arguments is passed to function1.divide(): expected 0, got 1' ... box.execute('SELECT "function1.divide"(6, 3)') --- - null -- wrong number of arguments to function function1.divide() +- 'invalid number of arguments is passed to function1.divide(): expected 0, got 2' ... box.func["function1.divide"]:drop() --- @@ -429,17 +429,17 @@ test_run:cmd("setopt delimiter ''"); box.execute('SELECT "function1.divide"()') --- - null -- wrong number of arguments to function function1.divide() +- 'invalid number of arguments is passed to function1.divide(): expected 2, got 0' ... box.execute('SELECT "function1.divide"(6)') --- - null -- wrong number of arguments to function function1.divide() +- 'invalid number of arguments is passed to function1.divide(): expected 2, got 1' ... box.execute('SELECT "function1.divide"(6, 3, 3)') --- - null -- wrong number of arguments to function function1.divide() +- 'invalid number of arguments is passed to function1.divide(): expected 2, got 3' ... box.execute('SELECT "function1.divide"(6, 3)') --- diff --git a/test/sql-tap/func.test.lua b/test/sql-tap/func.test.lua index ec06c903d..ae87bf61b 100755 --- a/test/sql-tap/func.test.lua +++ b/test/sql-tap/func.test.lua @@ -69,7 +69,7 @@ test:do_catchsql_test( SELECT length(*) FROM tbl1 ORDER BY t1 ]], { -- - 1, "wrong number of arguments to function LENGTH()" + 1, "invalid number of arguments is passed to LENGTH(): expected 1, got 0" -- }) @@ -79,7 +79,7 @@ test:do_catchsql_test( SELECT length(t1,5) FROM tbl1 ORDER BY t1 ]], { -- - 1, "wrong number of arguments to function LENGTH()" + 1, "invalid number of arguments is passed to LENGTH(): expected 1, got 2" -- }) @@ -365,7 +365,7 @@ test:do_test( return test:catchsql("SELECT abs(a,b) FROM t1") end, { -- - 1, "wrong number of arguments to function ABS()" + 1, "invalid number of arguments is passed to ABS(): expected 1, got 2" -- }) @@ -377,7 +377,7 @@ test:do_catchsql_test( SELECT abs() FROM t1 ]], { -- - 1, "wrong number of arguments to function ABS()" + 1, "invalid number of arguments is passed to ABS(): expected 1, got 0" -- }) @@ -428,7 +428,7 @@ test:do_catchsql_test( SELECT round(a,b,c) FROM t1 ]], { -- - 1, "wrong number of arguments to function ROUND()" + 1, "invalid number of arguments is passed to ROUND()" -- }) @@ -488,7 +488,7 @@ test:do_catchsql_test( SELECT round() FROM t1 ORDER BY a ]], { -- - 1, "wrong number of arguments to function ROUND()" + 1, "invalid number of arguments is passed to ROUND()" -- }) @@ -778,7 +778,7 @@ test:do_catchsql_test( SELECT upper(*) FROM t2 ]], { -- - 1, "wrong number of arguments to function UPPER()" + 1, "invalid number of arguments is passed to UPPER(): expected 1, got 0" -- }) @@ -1782,7 +1782,7 @@ test:do_catchsql_test( SELECT replace(1,2); ]], { -- - 1, "wrong number of arguments to function REPLACE()" + 1, "invalid number of arguments is passed to REPLACE(): expected 3, got 2" -- }) @@ -1792,7 +1792,7 @@ test:do_catchsql_test( SELECT replace(1,2,3,4); ]], { -- - 1, "wrong number of arguments to function REPLACE()" + 1, "invalid number of arguments is passed to REPLACE(): expected 3, got 4" -- }) @@ -2540,7 +2540,7 @@ test:do_catchsql_test( SELECT coalesce() ]], { -- - 1, "wrong number of arguments to function COALESCE()" + 1, "invalid number of arguments is passed to COALESCE()" -- }) @@ -2550,7 +2550,7 @@ test:do_catchsql_test( SELECT coalesce(1) ]], { -- - 1, "wrong number of arguments to function COALESCE()" + 1, "invalid number of arguments is passed to COALESCE()" -- }) diff --git a/test/sql-tap/func2.test.lua b/test/sql-tap/func2.test.lua index b70197d09..8ae565040 100755 --- a/test/sql-tap/func2.test.lua +++ b/test/sql-tap/func2.test.lua @@ -50,7 +50,7 @@ test:do_catchsql_test( SELECT SUBSTR() ]], { -- - 1, "wrong number of arguments to function SUBSTR()" + 1, "invalid number of arguments is passed to SUBSTR()" -- }) @@ -60,7 +60,7 @@ test:do_catchsql_test( SELECT SUBSTR('Supercalifragilisticexpialidocious') ]], { -- - 1, "wrong number of arguments to function SUBSTR()" + 1, "invalid number of arguments is passed to SUBSTR()" -- }) @@ -70,7 +70,7 @@ test:do_catchsql_test( SELECT SUBSTR('Supercalifragilisticexpialidocious', 1,1,1) ]], { -- - 1, "wrong number of arguments to function SUBSTR()" + 1, "invalid number of arguments is passed to SUBSTR()" -- }) @@ -673,7 +673,7 @@ if ("ሴ" ~= "u1234") SELECT SUBSTR() ]], { -- - 1, "wrong number of arguments to function SUBSTR()" + 1, "invalid number of arguments is passed to SUBSTR()" -- }) @@ -683,7 +683,7 @@ if ("ሴ" ~= "u1234") SELECT SUBSTR('hiሴho') ]], { -- - 1, "wrong number of arguments to function SUBSTR()" + 1, "invalid number of arguments is passed to SUBSTR()" -- }) @@ -693,7 +693,7 @@ if ("ሴ" ~= "u1234") SELECT SUBSTR('hiሴho', 1,1,1) ]], { -- - 1, "wrong number of arguments to function SUBSTR()" + 1, "invalid number of arguments is passed to SUBSTR()" -- }) @@ -1038,7 +1038,7 @@ test:do_catchsql_test( SELECT SUBSTR() ]], { -- - 1, "wrong number of arguments to function SUBSTR()" + 1, "invalid number of arguments is passed to SUBSTR()" -- }) @@ -1048,7 +1048,7 @@ test:do_catchsql_test( SELECT SUBSTR(x'1234') ]], { -- - 1, "wrong number of arguments to function SUBSTR()" + 1, "invalid number of arguments is passed to SUBSTR()" -- }) @@ -1058,7 +1058,7 @@ test:do_catchsql_test( SELECT SUBSTR(x'1234', 1,1,1) ]], { -- - 1, "wrong number of arguments to function SUBSTR()" + 1, "invalid number of arguments is passed to SUBSTR()" -- }) diff --git a/test/sql-tap/limit.test.lua b/test/sql-tap/limit.test.lua index 8445ab18e..76c5cba4d 100755 --- a/test/sql-tap/limit.test.lua +++ b/test/sql-tap/limit.test.lua @@ -771,7 +771,7 @@ test:do_catchsql_test( SELECT * FROM t1 LIMIT replace(1) ]], { -- - 1, "wrong number of arguments to function REPLACE()" + 1, "invalid number of arguments is passed to REPLACE(): expected 3, got 1" -- }) @@ -781,7 +781,7 @@ test:do_catchsql_test( SELECT * FROM t1 LIMIT 5 OFFSET replace(1) ]], { -- - 1, 'wrong number of arguments to function REPLACE()' + 1, 'invalid number of arguments is passed to REPLACE(): expected 3, got 1' -- }) diff --git a/test/sql-tap/select1.test.lua b/test/sql-tap/select1.test.lua index 924c0ccb1..096bd23c1 100755 --- a/test/sql-tap/select1.test.lua +++ b/test/sql-tap/select1.test.lua @@ -244,7 +244,7 @@ test:do_catchsql_test( SELECT count(f1,f2) FROM test1 ]], { -- - 1, "wrong number of arguments to function COUNT()" + 1, "invalid number of arguments is passed to COUNT()" -- }) @@ -324,7 +324,7 @@ test:do_catchsql_test( SELECT min(*) FROM test1 ]], { -- - 1, "wrong number of arguments to function MIN()" + 1, "invalid number of arguments is passed to MIN(): expected 1, got 0" -- }) @@ -389,7 +389,7 @@ test:do_catchsql_test( SELECT MAX(*) FROM test1 ]], { -- - 1, "wrong number of arguments to function MAX()" + 1, "invalid number of arguments is passed to MAX(): expected 1, got 0" -- }) @@ -469,7 +469,7 @@ test:do_catchsql_test( SELECT SUM(*) FROM test1 ]], { -- - 1, "wrong number of arguments to function SUM()" + 1, "invalid number of arguments is passed to SUM(): expected 1, got 0" -- }) @@ -489,7 +489,7 @@ test:do_catchsql_test( SELECT sum(f1,f2) FROM test1 ]], { -- - 1, "wrong number of arguments to function SUM()" + 1, "invalid number of arguments is passed to SUM(): expected 1, got 2" -- }) @@ -691,7 +691,7 @@ test:do_catchsql_test( SELECT f1 FROM test1 WHERE count(f1,f2)!=11 ]], { -- - 1, "wrong number of arguments to function COUNT()" + 1, "invalid number of arguments is passed to COUNT()" -- }) diff --git a/test/sql/icu-upper-lower.result b/test/sql/icu-upper-lower.result index 88266c8c5..e853c25e4 100644 --- a/test/sql/icu-upper-lower.result +++ b/test/sql/icu-upper-lower.result @@ -277,7 +277,7 @@ test_run:cmd("setopt delimiter ''"); box.execute("select upper('1', 2)") --- - null -- wrong number of arguments to function UPPER() +- 'invalid number of arguments is passed to UPPER(): expected 1, got 2' ... box.execute("select upper(\"1\")") --- @@ -287,5 +287,5 @@ box.execute("select upper(\"1\")") box.execute("select upper()") --- - null -- wrong number of arguments to function UPPER() +- 'invalid number of arguments is passed to UPPER(): expected 1, got 0' ... -- 2.22.1