Tarantool development patches archive
 help / color / mirror / Atom feed
From: imeevma@tarantool.org
To: korablev@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [tarantool-patches] [PATCH v3 6/9] sql: rework six syntax errors
Date: Sat,  2 Mar 2019 16:07:58 +0300	[thread overview]
Message-ID: <80be508ddcba4ffe5f5f4e99068ccce61e05a764.1551530224.git.imeevma@gmail.com> (raw)
In-Reply-To: <cover.1551530224.git.imeevma@gmail.com>

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(
         );
     ]], {
         -- <check-3.1>
-        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"
         -- </check-3.1>
     })
 
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

  parent reply	other threads:[~2019-03-02 13:08 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-02 13:07 [tarantool-patches] [PATCH v3 0/9] sql: use diag_set() for errors in SQL imeevma
2019-03-02 13:07 ` [tarantool-patches] [PATCH v3 1/9] sql: rework syntax errors imeevma
2019-03-04 17:47   ` [tarantool-patches] " n.pettik
2019-03-05  8:31   ` Konstantin Osipov
2019-03-02 13:07 ` [tarantool-patches] [PATCH v3 2/9] sql: save SQL parser errors in diag_set() imeevma
2019-03-05  8:40   ` [tarantool-patches] " Konstantin Osipov
2019-03-05  9:06   ` n.pettik
2019-03-02 13:07 ` [tarantool-patches] [PATCH v3 3/9] sql: remove field nErr of struct Parse imeevma
2019-03-05  8:41   ` [tarantool-patches] " Konstantin Osipov
2019-03-05  9:06   ` n.pettik
2019-03-02 13:07 ` [tarantool-patches] [PATCH v3 4/9] sql: remove field rc " imeevma
2019-03-05  8:42   ` [tarantool-patches] " Konstantin Osipov
2019-03-05  9:06   ` n.pettik
2019-03-02 13:07 ` [tarantool-patches] [PATCH v3 5/9] sql: remove field zErrMsg " imeevma
2019-03-05  8:43   ` [tarantool-patches] " Konstantin Osipov
2019-03-05  9:06   ` n.pettik
2019-03-02 13:07 ` imeevma [this message]
2019-03-05  8:45   ` [tarantool-patches] Re: [PATCH v3 6/9] sql: rework six syntax errors Konstantin Osipov
2019-03-05  9:07   ` n.pettik
2019-03-02 13:08 ` [tarantool-patches] [PATCH v3 7/9] sql: rework four semantic errors imeevma
2019-03-05  8:46   ` [tarantool-patches] " Konstantin Osipov
2019-03-05  9:16   ` n.pettik
2019-03-02 13:08 ` [tarantool-patches] [PATCH v3 8/9] sql: rework three errors of "unsupported" type imeevma
2019-03-05  8:47   ` [tarantool-patches] " Konstantin Osipov
2019-03-05  9:34   ` n.pettik
2019-03-05  9:43     ` Konstantin Osipov
2019-03-02 13:08 ` [tarantool-patches] [PATCH v3 9/9] sql: remove sqlErrorMsg() imeevma
2019-03-05  8:48   ` [tarantool-patches] " Konstantin Osipov
2019-03-05 12:16   ` n.pettik
2019-03-05 15:44     ` Konstantin Osipov

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=80be508ddcba4ffe5f5f4e99068ccce61e05a764.1551530224.git.imeevma@gmail.com \
    --to=imeevma@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH v3 6/9] sql: rework six syntax errors' \
    /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