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 EDD032E483 for ; Tue, 7 May 2019 12:03:17 -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 R8uD6g9IXWSf for ; Tue, 7 May 2019 12:03:17 -0400 (EDT) Received: from smtp61.i.mail.ru (smtp61.i.mail.ru [217.69.128.41]) (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 439462E57B for ; Tue, 7 May 2019 12:03:16 -0400 (EDT) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v1 1/1] sql: do not replace the error with a syntax error Date: Tue, 7 May 2019 19:03:14 +0300 Message-Id: <76ecaa6e2ba8a69f421a73bb25fb857cf5bbe001.1557244912.git.imeevma@gmail.com> 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 Currently, it is possible to set a syntax error, even if there has already been another error before. For example: box.execute("insert into not_exist values(1) a") The first error is "Space 'NOT_EXIST' does not exist", but "Syntax error near 'a'" is displayed. After this patch, all syntax errors will be set only if there have been no errors before. Closes #3964 --- https://github.com/tarantool/tarantool/issues/3964 https://github.com/tarantool/tarantool/tree/imeevma/gh-3964-stop-parser-on-error src/box/sql/parse.y | 12 ++++++++++++ test/sql-tap/e_select1.test.lua | 2 +- test/sql-tap/misc1.test.lua | 2 +- test/sql-tap/sql-errors.test.lua | 12 +++++++++++- test/sql-tap/view.test.lua | 2 +- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y index 3a443a0..ac3cce0 100644 --- a/src/box/sql/parse.y +++ b/src/box/sql/parse.y @@ -32,6 +32,18 @@ %syntax_error { UNUSED_PARAMETER(yymajor); /* Silence some compiler warnings */ assert( TOKEN.z[0] ); /* The tokenizer always gives us a token */ + /* + * Do nothing if there was already an error. Before this patch, + * a syntax error can replace an already set error when the + * parser rule is violated. + * For example: + * INSERT INSERT not_exist VALUES(1) a + * + * In this case space NOT_EXIST do not exist, but this error has + * been replaced by a syntax error. + */ + if (pParse->is_aborted) + return; if (yypParser->is_fallback_failed && TOKEN.isReserved) { diag_set(ClientError, ER_SQL_KEYWORD_IS_RESERVED, TOKEN.n, TOKEN.z, TOKEN.n, TOKEN.z); diff --git a/test/sql-tap/e_select1.test.lua b/test/sql-tap/e_select1.test.lua index c4724e6..6f17471 100755 --- a/test/sql-tap/e_select1.test.lua +++ b/test/sql-tap/e_select1.test.lua @@ -808,7 +808,7 @@ data = { {"1.1", "SELECT a, b, c FROM z1 WHERE *", "Syntax error near '*'"}, {"1.2", "SELECT a, b, c FROM z1 GROUP BY *", "Syntax error near '*'"}, {"1.3", "SELECT 1 + * FROM z1", "Syntax error near '*'"}, - {"1.4", "SELECT * + 1 FROM z1", "Syntax error near '+'"}, + {"1.4", "SELECT * + 1 FROM z1", "Failed to expand '*' in SELECT statement without FROM clause"}, {"2.1", "SELECT *", "Failed to expand '*' in SELECT statement without FROM clause"}, {"2.2", "SELECT * WHERE 1", "Failed to expand '*' in SELECT statement without FROM clause"}, {"2.3", "SELECT * WHERE 0", "Failed to expand '*' in SELECT statement without FROM clause"}, diff --git a/test/sql-tap/misc1.test.lua b/test/sql-tap/misc1.test.lua index cd0e103..914f920 100755 --- a/test/sql-tap/misc1.test.lua +++ b/test/sql-tap/misc1.test.lua @@ -1047,7 +1047,7 @@ test:do_catchsql_test( VALUES(0,0x0MATCH#0; ]], { -- - 1, [[Syntax error near ';']] + 1, [[Syntax error near '#0']] -- }) diff --git a/test/sql-tap/sql-errors.test.lua b/test/sql-tap/sql-errors.test.lua index 4e173b6..83a13d2 100755 --- a/test/sql-tap/sql-errors.test.lua +++ b/test/sql-tap/sql-errors.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool test = require("sqltester") -test:plan(45) +test:plan(46) test:execsql([[ CREATE TABLE t0 (i INT PRIMARY KEY, a INT); @@ -506,4 +506,14 @@ test:do_execsql_test( -- }) +test:do_catchsql_test( + "sql-errors-1.46", + [[ + INSERT INTO not_exist VALUES(1) a; + ]], { + -- + 1, "Space 'NOT_EXIST' does not exist" + -- + }) + test:finish_test() diff --git a/test/sql-tap/view.test.lua b/test/sql-tap/view.test.lua index 0032e1b..101f4c3 100755 --- a/test/sql-tap/view.test.lua +++ b/test/sql-tap/view.test.lua @@ -961,7 +961,7 @@ test:do_catchsql_test( DROP VIEW main.nosuchview ]], { -- - 1, "Syntax error near '.'" + 1, "Space 'MAIN' does not exist" -- }) -- 2.7.4