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 24AEB28BE5 for ; Sat, 2 Mar 2019 08:08:01 -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 GZqt2VPh3nqi for ; Sat, 2 Mar 2019 08:08:01 -0500 (EST) Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 D3A9028BE4 for ; Sat, 2 Mar 2019 08:08:00 -0500 (EST) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v3 6/9] sql: rework six syntax errors Date: Sat, 2 Mar 2019 16:07:58 +0300 Message-Id: <80be508ddcba4ffe5f5f4e99068ccce61e05a764.1551530224.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 This patch rewords six more syntax errors. Part of #3965 --- src/box/errcode.h | 3 +++ src/box/sql/build.c | 4 +-- src/box/sql/resolve.c | 62 +++++++++++++++++++++---------------------- test/box/misc.result | 3 +++ test/sql-tap/check.test.lua | 2 +- test/sql-tap/colname.test.lua | 2 +- 6 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/box/errcode.h b/src/box/errcode.h index d234d26..057a6d3 100644 --- a/src/box/errcode.h +++ b/src/box/errcode.h @@ -239,6 +239,9 @@ struct errcode_record { /*184 */_(ER_SQL_UNRECOGNIZED_SYNTAX, "Syntax error near '%.*s'") \ /*185 */_(ER_SQL_UNKNOWN_TOKEN, "Syntax error: unrecognized token: '%.*s'") \ /*186 */_(ER_SQL_PARSER_GENERIC, "%s") \ + /*187 */_(ER_INDEX_DEF, "%s prohibited in an index definition") \ + /*188 */_(ER_CHECK_CONSTRAINT_DEF, "%s prohibited in prohibited in a CHECK constraint definition") \ + /*189 */_(ER_PRIMARY_KEY_DEF, "Expressions are prohibited in a primary key definition") \ /* * !IMPORTANT! Please follow instructions at start of the file diff --git a/src/box/sql/build.c b/src/box/sql/build.c index a1f4b1b..651e02a 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -607,8 +607,8 @@ sqlAddPrimaryKey(Parse * pParse, /* Parsing context */ sqlExprSkipCollate(pList->a[i].pExpr); assert(pCExpr != 0); if (pCExpr->op != TK_ID) { - sqlErrorMsg(pParse, "expressions prohibited" - " in PRIMARY KEY"); + diag_set(ClientError, ER_PRIMARY_KEY_DEF); + pParse->is_aborted = true; goto primary_key_exit; } const char *name = pCExpr->u.zToken; diff --git a/src/box/sql/resolve.c b/src/box/sql/resolve.c index 3215db3..02eca37 100644 --- a/src/box/sql/resolve.c +++ b/src/box/sql/resolve.c @@ -510,30 +510,6 @@ sqlCreateColumnExpr(sql * db, SrcList * pSrc, int iSrc, int iCol) } /* - * Report an error that an expression is not valid for some set of - * pNC->ncFlags values determined by validMask. - */ -static void -notValid(Parse * pParse, /* Leave error message here */ - NameContext * pNC, /* The name context */ - const char *zMsg, /* Type of error */ - int validMask /* Set of contexts for which prohibited */ - ) -{ - assert((validMask & ~(NC_IsCheck | NC_IdxExpr)) == 0); - if ((pNC->ncFlags & validMask) != 0) { - const char *zIn; - if (pNC->ncFlags & NC_IdxExpr) - zIn = "index expressions"; - else if (pNC->ncFlags & NC_IsCheck) - zIn = "CHECK constraints"; - else - unreachable(); - sqlErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn); - } -} - -/* * Expression p should encode a floating point value between 1.0 and 0.0. * Return 1024 times this value. Or return -1 if p is not a floating point * value between 1.0 and 0.0. @@ -605,7 +581,10 @@ resolveExprStep(Walker * pWalker, Expr * pExpr) Expr *pRight; /* if( pSrcList==0 ) break; */ - notValid(pParse, pNC, "the \".\" operator", NC_IdxExpr); + if (pNC->ncFlags & NC_IdxExpr) { + diag_set(ClientError, ER_INDEX_DEF, "'.' operator is"); + pParse->is_aborted = true; + } pRight = pExpr->pRight; if (pRight->op == TK_ID) { zTable = pExpr->pLeft->u.zToken; @@ -690,9 +669,12 @@ resolveExprStep(Walker * pWalker, Expr * pExpr) * that might change over time cannot be used * in an index. */ - notValid(pParse, pNC, - "non-deterministic functions", - NC_IdxExpr); + if (pNC->ncFlags & NC_IdxExpr) { + diag_set(ClientError, ER_INDEX_DEF, + "Non-deterministic functions "\ + "are"); + pParse->is_aborted = true; + } } } if (is_agg && (pNC->ncFlags & NC_AllowAgg) == 0) { @@ -754,8 +736,16 @@ resolveExprStep(Walker * pWalker, Expr * pExpr) testcase(pExpr->op == TK_IN); if (ExprHasProperty(pExpr, EP_xIsSelect)) { int nRef = pNC->nRef; - notValid(pParse, pNC, "subqueries", - NC_IsCheck | NC_IdxExpr); + if (pNC->ncFlags & NC_IdxExpr) { + diag_set(ClientError, ER_INDEX_DEF, + "Subqueries are"); + pParse->is_aborted = true; + } else if (pNC->ncFlags & NC_IsCheck) { + diag_set(ClientError, + ER_CHECK_CONSTRAINT_DEF, + "Subqueries are"); + pParse->is_aborted = true; + } sqlWalkSelect(pWalker, pExpr->x.pSelect); assert(pNC->nRef >= nRef); if (nRef != pNC->nRef) { @@ -766,8 +756,16 @@ resolveExprStep(Walker * pWalker, Expr * pExpr) break; } case TK_VARIABLE:{ - notValid(pParse, pNC, "parameters", - NC_IsCheck | NC_IdxExpr); + if (pNC->ncFlags & NC_IdxExpr) { + diag_set(ClientError, ER_INDEX_DEF, + "Parameter markers are"); + pParse->is_aborted = true; + } else if (pNC->ncFlags & NC_IsCheck) { + diag_set(ClientError, + ER_CHECK_CONSTRAINT_DEF, + "Parameter markers are"); + pParse->is_aborted = true; + } break; } case TK_BETWEEN: diff --git a/test/box/misc.result b/test/box/misc.result index 9f0b2c7..a3bc7b7 100644 --- a/test/box/misc.result +++ b/test/box/misc.result @@ -515,6 +515,9 @@ t; 184: box.error.SQL_UNRECOGNIZED_SYNTAX 185: box.error.SQL_UNKNOWN_TOKEN 186: box.error.SQL_PARSER_GENERIC + 187: box.error.INDEX_DEF + 188: box.error.CHECK_CONSTRAINT_DEF + 189: box.error.PRIMARY_KEY_DEF ... test_run:cmd("setopt delimiter ''"); --- diff --git a/test/sql-tap/check.test.lua b/test/sql-tap/check.test.lua index 0d8bf15..e1d2d48 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': subqueries prohibited in CHECK constraints" + 1, "Failed to create space 'T3': Subqueries are prohibited in prohibited in a CHECK constraint definition" -- }) diff --git a/test/sql-tap/colname.test.lua b/test/sql-tap/colname.test.lua index 29fdf13..77c4280 100755 --- a/test/sql-tap/colname.test.lua +++ b/test/sql-tap/colname.test.lua @@ -637,7 +637,7 @@ test:do_test( test:do_catchsql_test( "colname-11.1", [[ create table t1(a INT, b INT, c INT, primary key('A'))]], - {1, "expressions prohibited in PRIMARY KEY"}) + {1, "Expressions are prohibited in a primary key definition"}) test:do_catchsql_test( "colname-11.2", -- 2.7.4