From: imeevma@tarantool.org To: korablev@tarantool.org Cc: tarantool-patches@freelists.org Subject: [tarantool-patches] [PATCH v1 2/3] sql: rework diag_set() in OP_Halt Date: Fri, 12 Apr 2019 15:34:18 +0300 [thread overview] Message-ID: <79e3d0e51a64bf35cf5b505d2541996f60b02b8c.1555072183.git.imeevma@gmail.com> (raw) In-Reply-To: <cover.1555072183.git.imeevma@gmail.com> 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 ]], { -- <limit-1.2.13> - 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" -- </limit-1.2.13> }) @@ -94,7 +94,7 @@ test:do_catchsql_test( SELECT x FROM t1 ORDER BY x+1 LIMIT 2, -5 ]], { -- <limit-1.2.4> - 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" -- </limit-1.2.4> }) @@ -115,7 +115,7 @@ test:do_catchsql_test( SELECT x FROM t1 ORDER BY x+1 LIMIT -2, 5 ]], { -- <limit-1.2.6> - 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" -- </limit-1.2.6> }) @@ -135,7 +135,7 @@ test:do_catchsql_test( SELECT x FROM t1 ORDER BY x+1 LIMIT -2, -5 ]], { -- <limit-1.2.8> - 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" -- </limit-1.2.8> }) @@ -384,7 +384,7 @@ test:do_catchsql_test( SELECT * FROM t6 LIMIT -1 OFFSET -1; ]], { -- <limit-6.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" -- </limit-6.2> }) @@ -394,7 +394,7 @@ test:do_catchsql_test( SELECT * FROM t6 LIMIT 2 OFFSET -123; ]], { -- <limit-6.3> - 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" -- </limit-6.3> }) @@ -414,7 +414,7 @@ test:do_catchsql_test( SELECT * FROM t6 LIMIT -432 OFFSET 2; ]], { -- <limit-6.4> - 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" -- </limit-6.4> }) @@ -434,7 +434,7 @@ test:do_catchsql_test( SELECT * FROM t6 LIMIT -1 ]], { -- <limit-6.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" -- </limit-6.5> }) @@ -454,7 +454,7 @@ test:do_catchsql_test( SELECT * FROM t6 LIMIT -1 OFFSET 1 ]], { -- <limit-6.6> - 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" -- </limit-6.6> }) @@ -734,7 +734,7 @@ test:do_test( return test:catchsql("SELECT x FROM t1 WHERE x<10 LIMIT "..limit) end, { -- <limit-10.4> - 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" -- </limit-10.4> }) @@ -745,7 +745,7 @@ test:do_test( return test:catchsql("SELECT x FROM t1 WHERE x<10 LIMIT "..limit) end, { -- <limit-10.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" -- </limit-10.5> }) @@ -1320,7 +1320,7 @@ test:do_catchsql_test( SELECT 123 LIMIT -1 OFFSET 0 ]], { -- <limit-14.6.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" -- </limit-14.6.1> }) @@ -1340,7 +1340,7 @@ test:do_catchsql_test( SELECT 123 LIMIT -1 OFFSET 1 ]], { -- <limit-14.7.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" -- </limit-14.7.1> }) 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 ]], { -- <select4-10.4.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" -- </select4-10.4.1> }) test:do_execsql_test( @@ -1009,7 +1009,7 @@ test:do_catchsql_test( SELECT DISTINCT log FROM t1 ORDER BY log LIMIT -1 OFFSET 2 ]], { -- <select4-10.5.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" -- </select4-10.5.1> }) 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
next prev parent reply other threads:[~2019-04-12 12:34 UTC|newest] Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-04-12 12:34 [tarantool-patches] [PATCH v1 0/3] sql: make SQL_TARANTOOL_ERROR the only errcode of OP_Halt imeevma 2019-04-12 12:34 ` [tarantool-patches] [PATCH v1 1/3] sql: remove mayAbort field from struct Parse imeevma 2019-04-15 14:06 ` [tarantool-patches] " n.pettik 2019-04-22 7:49 ` Imeev Mergen 2019-04-26 7:25 ` Mergen Imeev 2019-04-28 23:35 ` n.pettik 2019-04-12 12:34 ` imeevma [this message] 2019-04-15 15:21 ` [tarantool-patches] Re: [PATCH v1 2/3] sql: rework diag_set() in OP_Halt n.pettik 2019-04-22 8:24 ` Imeev Mergen 2019-04-24 12:19 ` n.pettik 2019-04-26 7:48 ` Mergen Imeev 2019-04-28 23:35 ` n.pettik 2019-04-29 15:05 ` Imeev Mergen 2019-05-05 11:31 ` Imeev Mergen 2019-04-12 12:34 ` [tarantool-patches] [PATCH v1 3/3] sql: make SQL_TARANTOOL_ERROR the only errcode of OP_Halt imeevma 2019-04-15 15:19 ` [tarantool-patches] " n.pettik 2019-04-22 8:47 ` Imeev Mergen 2019-04-22 9:53 ` Imeev Mergen 2019-04-26 7:37 ` Mergen Imeev 2019-04-28 23:35 ` n.pettik 2019-05-05 12:16 ` Imeev Mergen
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=79e3d0e51a64bf35cf5b505d2541996f60b02b8c.1555072183.git.imeevma@gmail.com \ --to=imeevma@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH v1 2/3] sql: rework diag_set() in OP_Halt' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox