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 239132C6B8 for ; Fri, 12 Apr 2019 08:34:22 -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 bEJ6gek_yyEd for ; Fri, 12 Apr 2019 08:34:22 -0400 (EDT) Received: from smtp43.i.mail.ru (smtp43.i.mail.ru [94.100.177.103]) (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 ACE052C6B6 for ; Fri, 12 Apr 2019 08:34:21 -0400 (EDT) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v1 2/3] sql: rework diag_set() in OP_Halt Date: Fri, 12 Apr 2019 15:34:18 +0300 Message-Id: <79e3d0e51a64bf35cf5b505d2541996f60b02b8c.1555072183.git.imeevma@gmail.com> In-Reply-To: References: 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: korablev@tarantool.org Cc: tarantool-patches@freelists.org Before this patch it was possible to have an error code with wrong error description. This patch fixes it. Part of #4074 --- src/box/sql/build.c | 9 ++------- src/box/sql/select.c | 17 ++++++++--------- src/box/sql/trigger.c | 12 ++++-------- src/box/sql/vdbe.c | 3 +-- test/sql-tap/e_select1.test.lua | 4 ++-- test/sql-tap/limit.test.lua | 26 +++++++++++++------------- test/sql-tap/select4.test.lua | 4 ++-- test/sql/iproto.result | 18 ++++++++++++------ 8 files changed, 44 insertions(+), 49 deletions(-) diff --git a/src/box/sql/build.c b/src/box/sql/build.c index febb2e8..17cd0a0 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -1013,12 +1013,10 @@ vdbe_emit_fk_constraint_create(struct Parse *parse_context, * Lets check that constraint with this name hasn't * been created before. */ - const char *error_msg = - tt_sprintf(tnt_errcode_desc(ER_CONSTRAINT_EXISTS), name_copy); if (vdbe_emit_halt_with_presence_test(parse_context, BOX_FK_CONSTRAINT_ID, 0, constr_tuple_reg, 2, - ER_CONSTRAINT_EXISTS, error_msg, + ER_CONSTRAINT_EXISTS, name_copy, false, OP_NoConflict) != 0) return; sqlVdbeAddOp2(vdbe, OP_Bool, 0, constr_tuple_reg + 3); @@ -1400,13 +1398,10 @@ vdbe_emit_fk_constraint_drop(struct Parse *parse_context, char *constraint_name, sqlVdbeAddOp4(vdbe, OP_String8, 0, key_reg, 0, constraint_name, P4_DYNAMIC); sqlVdbeAddOp2(vdbe, OP_Integer, child_id, key_reg + 1); - const char *error_msg = - tt_sprintf(tnt_errcode_desc(ER_NO_SUCH_CONSTRAINT), - constraint_name); if (vdbe_emit_halt_with_presence_test(parse_context, BOX_FK_CONSTRAINT_ID, 0, key_reg, 2, ER_NO_SUCH_CONSTRAINT, - error_msg, false, + constraint_name, false, OP_Found) != 0) { sqlDbFree(parse_context->db, constraint_name); return; diff --git a/src/box/sql/select.c b/src/box/sql/select.c index b1ec8c7..c0c526d 100644 --- a/src/box/sql/select.c +++ b/src/box/sql/select.c @@ -2113,6 +2113,7 @@ computeLimitRegisters(Parse * pParse, Select * p, int iBreak) 0, 0, wrong_limit_error, P4_STATIC); + sqlVdbeChangeP5(v, ER_SQL_EXECUTE); sqlVdbeResolveLabel(v, positive_limit_label); sqlReleaseTempReg(pParse, r1); @@ -2140,13 +2141,12 @@ computeLimitRegisters(Parse * pParse, Select * p, int iBreak) sqlVdbeAddOp2(v, OP_Integer, 1, r1); int no_err = sqlVdbeMakeLabel(v); sqlVdbeAddOp3(v, OP_Eq, iLimit, no_err, r1); - const char *error = - "SQL error: Expression subquery could " - "be limited only with 1"; + const char *error = "Expression subquery could " + "be limited only with 1"; sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR, 0, 0, error, P4_STATIC); - sqlVdbeChangeP5(v, ER_SQL_EXECUTE); + sqlVdbeChangeP5(v, ER_SQL); sqlVdbeResolveLabel(v, no_err); sqlReleaseTempReg(pParse, r1); @@ -2176,6 +2176,7 @@ computeLimitRegisters(Parse * pParse, Select * p, int iBreak) 0, 0, wrong_offset_error, P4_STATIC); + sqlVdbeChangeP5(v, ER_SQL_EXECUTE); sqlVdbeResolveLabel(v, positive_offset_label); sqlReleaseTempReg(pParse, r1); @@ -5443,11 +5444,9 @@ vdbe_code_raise_on_multiple_rows(struct Parse *parser, int limit_reg, int end_ma int r1 = sqlGetTempReg(parser); sqlVdbeAddOp2(v, OP_Integer, 0, r1); sqlVdbeAddOp3(v, OP_Ne, r1, end_mark, limit_reg); - const char *error = - "SQL error: Expression subquery returned more than 1 row"; - sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR, 0, 0, error, - P4_STATIC); - sqlVdbeChangeP5(v, ER_SQL_EXECUTE); + const char *error = "Expression subquery returned more than 1 row"; + sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR, 0, 0, error, P4_STATIC); + sqlVdbeChangeP5(v, ER_SQL); sqlReleaseTempReg(parser, r1); } diff --git a/src/box/sql/trigger.c b/src/box/sql/trigger.c index 14e4198..9dd9d9f 100644 --- a/src/box/sql/trigger.c +++ b/src/box/sql/trigger.c @@ -100,9 +100,6 @@ sql_trigger_begin(struct Parse *parse) struct Vdbe *v = sqlGetVdbe(parse); if (v != NULL) sqlVdbeCountChanges(v); - const char *error_msg = - tt_sprintf(tnt_errcode_desc(ER_TRIGGER_EXISTS), - trigger_name); char *name_copy = sqlDbStrDup(db, trigger_name); if (name_copy == NULL) goto trigger_cleanup; @@ -113,7 +110,8 @@ sql_trigger_begin(struct Parse *parse) if (vdbe_emit_halt_with_presence_test(parse, BOX_TRIGGER_ID, 0, name_reg, 1, ER_TRIGGER_EXISTS, - error_msg, (no_err != 0), + trigger_name, + (no_err != 0), OP_NoConflict) != 0) goto trigger_cleanup; } @@ -412,9 +410,6 @@ sql_drop_trigger(struct Parse *parser) assert(name->nSrc == 1); const char *trigger_name = name->a[0].zName; - const char *error_msg = - tt_sprintf(tnt_errcode_desc(ER_NO_SUCH_TRIGGER), - trigger_name); char *name_copy = sqlDbStrDup(db, trigger_name); if (name_copy == NULL) goto drop_trigger_cleanup; @@ -422,7 +417,8 @@ sql_drop_trigger(struct Parse *parser) sqlVdbeAddOp4(v, OP_String8, 0, name_reg, 0, name_copy, P4_DYNAMIC); if (vdbe_emit_halt_with_presence_test(parser, BOX_TRIGGER_ID, 0, name_reg, 1, ER_NO_SUCH_TRIGGER, - error_msg, no_err, OP_Found) != 0) + trigger_name, + no_err, OP_Found) != 0) goto drop_trigger_cleanup; vdbe_code_drop_trigger(parser, trigger_name, true); diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index ed7bf88..3d20aa9 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -1073,8 +1073,7 @@ case OP_Halt: { if (pOp->p4.z == NULL) { assert(! diag_is_empty(diag_get())); } else { - box_error_set(__FILE__, __LINE__, pOp->p5, - pOp->p4.z); + diag_set(ClientError, pOp->p5, pOp->p4.z); } } else if (pOp->p5 != 0) { static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK", diff --git a/test/sql-tap/e_select1.test.lua b/test/sql-tap/e_select1.test.lua index 8e9a2bb..6f54b7f 100755 --- a/test/sql-tap/e_select1.test.lua +++ b/test/sql-tap/e_select1.test.lua @@ -2172,7 +2172,7 @@ for _, val in ipairs({ "e_select-9.2."..tn, select, { - 1, "Only positive integers are allowed in the LIMIT clause"}) + 1, "Failed to execute SQL statement: Only positive integers are allowed in the LIMIT clause"}) end -- EVIDENCE-OF: R-03014-26414 If the LIMIT expression evaluates to a @@ -2226,7 +2226,7 @@ for _, val in ipairs({ test:do_catchsql_test( "e_select-9.7."..tn, select, { - 1, "Only positive integers are allowed in the OFFSET clause" + 1, "Failed to execute SQL statement: Only positive integers are allowed in the OFFSET clause" }) end diff --git a/test/sql-tap/limit.test.lua b/test/sql-tap/limit.test.lua index 632c634..7ebf7b3 100755 --- a/test/sql-tap/limit.test.lua +++ b/test/sql-tap/limit.test.lua @@ -84,7 +84,7 @@ test:do_catchsql_test( SELECT x FROM t1 ORDER BY x+1 LIMIT 5 OFFSET -2 ]], { -- - 1 ,"Only positive integers are allowed in the OFFSET clause" + 1 ,"Failed to execute SQL statement: Only positive integers are allowed in the OFFSET clause" -- }) @@ -94,7 +94,7 @@ test:do_catchsql_test( SELECT x FROM t1 ORDER BY x+1 LIMIT 2, -5 ]], { -- - 1, "Only positive integers are allowed in the LIMIT clause" + 1, "Failed to execute SQL statement: Only positive integers are allowed in the LIMIT clause" -- }) @@ -115,7 +115,7 @@ test:do_catchsql_test( SELECT x FROM t1 ORDER BY x+1 LIMIT -2, 5 ]], { -- - 1, "Only positive integers are allowed in the OFFSET clause" + 1, "Failed to execute SQL statement: Only positive integers are allowed in the OFFSET clause" -- }) @@ -135,7 +135,7 @@ test:do_catchsql_test( SELECT x FROM t1 ORDER BY x+1 LIMIT -2, -5 ]], { -- - 1, "Only positive integers are allowed in the LIMIT clause" + 1, "Failed to execute SQL statement: Only positive integers are allowed in the LIMIT clause" -- }) @@ -384,7 +384,7 @@ test:do_catchsql_test( SELECT * FROM t6 LIMIT -1 OFFSET -1; ]], { -- - 1, "Only positive integers are allowed in the LIMIT clause" + 1, "Failed to execute SQL statement: Only positive integers are allowed in the LIMIT clause" -- }) @@ -394,7 +394,7 @@ test:do_catchsql_test( SELECT * FROM t6 LIMIT 2 OFFSET -123; ]], { -- - 1, "Only positive integers are allowed in the OFFSET clause" + 1, "Failed to execute SQL statement: Only positive integers are allowed in the OFFSET clause" -- }) @@ -414,7 +414,7 @@ test:do_catchsql_test( SELECT * FROM t6 LIMIT -432 OFFSET 2; ]], { -- - 1, "Only positive integers are allowed in the LIMIT clause" + 1, "Failed to execute SQL statement: Only positive integers are allowed in the LIMIT clause" -- }) @@ -434,7 +434,7 @@ test:do_catchsql_test( SELECT * FROM t6 LIMIT -1 ]], { -- - 1, "Only positive integers are allowed in the LIMIT clause" + 1, "Failed to execute SQL statement: Only positive integers are allowed in the LIMIT clause" -- }) @@ -454,7 +454,7 @@ test:do_catchsql_test( SELECT * FROM t6 LIMIT -1 OFFSET 1 ]], { -- - 1, "Only positive integers are allowed in the LIMIT clause" + 1, "Failed to execute SQL statement: Only positive integers are allowed in the LIMIT clause" -- }) @@ -734,7 +734,7 @@ test:do_test( return test:catchsql("SELECT x FROM t1 WHERE x<10 LIMIT "..limit) end, { -- - 1, "Only positive integers are allowed in the LIMIT clause" + 1, "Failed to execute SQL statement: Only positive integers are allowed in the LIMIT clause" -- }) @@ -745,7 +745,7 @@ test:do_test( return test:catchsql("SELECT x FROM t1 WHERE x<10 LIMIT "..limit) end, { -- - 1, "Only positive integers are allowed in the LIMIT clause" + 1, "Failed to execute SQL statement: Only positive integers are allowed in the LIMIT clause" -- }) @@ -1320,7 +1320,7 @@ test:do_catchsql_test( SELECT 123 LIMIT -1 OFFSET 0 ]], { -- - 1, "Only positive integers are allowed in the LIMIT clause" + 1, "Failed to execute SQL statement: Only positive integers are allowed in the LIMIT clause" -- }) @@ -1340,7 +1340,7 @@ test:do_catchsql_test( SELECT 123 LIMIT -1 OFFSET 1 ]], { -- - 1, "Only positive integers are allowed in the LIMIT clause" + 1, "Failed to execute SQL statement: Only positive integers are allowed in the LIMIT clause" -- }) diff --git a/test/sql-tap/select4.test.lua b/test/sql-tap/select4.test.lua index 3aafedb..56dbaf5 100755 --- a/test/sql-tap/select4.test.lua +++ b/test/sql-tap/select4.test.lua @@ -990,7 +990,7 @@ test:do_catchsql_test( SELECT DISTINCT log FROM t1 ORDER BY log LIMIT -1 ]], { -- - 1,"Only positive integers are allowed in the LIMIT clause" + 1,"Failed to execute SQL statement: Only positive integers are allowed in the LIMIT clause" -- }) test:do_execsql_test( @@ -1009,7 +1009,7 @@ test:do_catchsql_test( SELECT DISTINCT log FROM t1 ORDER BY log LIMIT -1 OFFSET 2 ]], { -- - 1,"Only positive integers are allowed in the LIMIT clause" + 1,"Failed to execute SQL statement: Only positive integers are allowed in the LIMIT clause" -- }) test:do_execsql_test( diff --git a/test/sql/iproto.result b/test/sql/iproto.result index e734872..aa36fab 100644 --- a/test/sql/iproto.result +++ b/test/sql/iproto.result @@ -164,15 +164,18 @@ cn:execute('select * from test limit ?', {2}) ... cn:execute('select * from test limit ?', {-2}) --- -- error: Only positive integers are allowed in the LIMIT clause +- error: 'Failed to execute SQL statement: Only positive integers are allowed in the + LIMIT clause' ... cn:execute('select * from test limit ?', {2.7}) --- -- error: Only positive integers are allowed in the LIMIT clause +- error: 'Failed to execute SQL statement: Only positive integers are allowed in the + LIMIT clause' ... cn:execute('select * from test limit ?', {'Hello'}) --- -- error: Only positive integers are allowed in the LIMIT clause +- error: 'Failed to execute SQL statement: Only positive integers are allowed in the + LIMIT clause' ... cn:execute('select * from test limit 1 offset ?', {2}) --- @@ -188,15 +191,18 @@ cn:execute('select * from test limit 1 offset ?', {2}) ... cn:execute('select * from test limit 1 offset ?', {-2}) --- -- error: Only positive integers are allowed in the OFFSET clause +- error: 'Failed to execute SQL statement: Only positive integers are allowed in the + OFFSET clause' ... cn:execute('select * from test limit 1 offset ?', {2.7}) --- -- error: Only positive integers are allowed in the OFFSET clause +- error: 'Failed to execute SQL statement: Only positive integers are allowed in the + OFFSET clause' ... cn:execute('select * from test limit 1 offset ?', {'Hello'}) --- -- error: Only positive integers are allowed in the OFFSET clause +- error: 'Failed to execute SQL statement: Only positive integers are allowed in the + OFFSET clause' ... -- gh-2608 SQL iproto DDL cn:execute('create table test2(id int primary key, a int, b int, c int)') -- 2.7.4