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 3511E276DD for ; Mon, 25 Feb 2019 12:14:28 -0500 (EST) 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 ZrDPMXeFs35M for ; Mon, 25 Feb 2019 12:14:28 -0500 (EST) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (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 E30B3276C8 for ; Mon, 25 Feb 2019 12:14:27 -0500 (EST) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v2 3/5] sql: save SQL parser errors in diag_set() Date: Mon, 25 Feb 2019 20:14:25 +0300 Message-Id: <85c9010267eba42be66e8c945d2b69098238a979.1551114402.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 After this patch all SQL parser errors will be saved in diag_set() instead of field zErrMsg of struct Parse. Part of #3965 --- src/box/errcode.h | 1 + src/box/sql/build.c | 3 ++- src/box/sql/util.c | 6 +++--- test/box/misc.result | 1 + test/sql-tap/check.test.lua | 2 +- test/sql/triggers.result | 4 ++-- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/box/errcode.h b/src/box/errcode.h index 6546b2f..779d927 100644 --- a/src/box/errcode.h +++ b/src/box/errcode.h @@ -238,6 +238,7 @@ struct errcode_record { /*183 */_(ER_SQL_KEYWORD_IS_RESERVED, "Keyword '%.*s' is reserved. Please use double quotes if '%.*s' is an identifier.") \ /*184 */_(ER_SQL_SYNTAX_NEAR, "Unrecognized syntax near '%.*s'") \ /*185 */_(ER_SQL_UNKNOWN_TOKEN, "Syntax error: unrecognized token: '%.*s'") \ + /*186 */_(ER_SQL_PARSER_GENERIC, "%s") \ /* * !IMPORTANT! Please follow instructions at start of the file diff --git a/src/box/sql/build.c b/src/box/sql/build.c index f112c9f..deb5b89 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -194,7 +194,8 @@ sql_finish_coding(struct Parse *parse_context) sqlVdbeMakeReady(v, parse_context); parse_context->rc = SQL_DONE; } else { - parse_context->rc = SQL_ERROR; + if (parse_context->rc != SQL_TARANTOOL_ERROR) + parse_context->rc = SQL_ERROR; } } /** diff --git a/src/box/sql/util.c b/src/box/sql/util.c index c89e2e8..e4c93cb 100644 --- a/src/box/sql/util.c +++ b/src/box/sql/util.c @@ -236,10 +236,10 @@ sqlErrorMsg(Parse * pParse, const char *zFormat, ...) va_start(ap, zFormat); zMsg = sqlVMPrintf(db, zFormat, ap); va_end(ap); + diag_set(ClientError, ER_SQL_PARSER_GENERIC, zMsg); + sqlDbFree(db, zMsg); pParse->nErr++; - sqlDbFree(db, pParse->zErrMsg); - pParse->zErrMsg = zMsg; - pParse->rc = SQL_ERROR; + pParse->rc = SQL_TARANTOOL_ERROR; } void diff --git a/test/box/misc.result b/test/box/misc.result index a1c94bf..47393d1 100644 --- a/test/box/misc.result +++ b/test/box/misc.result @@ -514,6 +514,7 @@ t; 182: box.error.SQL_STATEMENT_EMPTY 184: box.error.SQL_SYNTAX_NEAR 185: box.error.SQL_UNKNOWN_TOKEN + 186: box.error.SQL_PARSER_GENERIC ... test_run:cmd("setopt delimiter ''"); --- diff --git a/test/sql-tap/check.test.lua b/test/sql-tap/check.test.lua index f7d3ffe..8ce3184 100755 --- a/test/sql-tap/check.test.lua +++ b/test/sql-tap/check.test.lua @@ -319,7 +319,7 @@ test:do_catchsql_test( ); ]], { -- - 1, "Failed to create space 'T3': SQL error: subqueries prohibited in CHECK constraints" + 1, "Failed to create space 'T3': subqueries prohibited in CHECK constraints" -- }) diff --git a/test/sql/triggers.result b/test/sql/triggers.result index bbfff33..9ab169b 100644 --- a/test/sql/triggers.result +++ b/test/sql/triggers.result @@ -398,14 +398,14 @@ space_id = box.space.T1.id ... box.sql.execute("CREATE TRIGGER tr1 AFTER INSERT ON t1 WHEN new.a = ? BEGIN SELECT 1; END;") --- -- error: 'SQL error: bindings are not allowed in DDL' +- error: bindings are not allowed in DDL ... tuple = {"TR1", space_id, {sql = [[CREATE TRIGGER tr1 AFTER INSERT ON t1 WHEN new.a = ? BEGIN SELECT 1; END;]]}} --- ... box.space._trigger:insert(tuple) --- -- error: 'SQL error: bindings are not allowed in DDL' +- error: bindings are not allowed in DDL ... box.sql.execute("DROP TABLE t1;") --- -- 2.7.4