Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org,
	Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] [PATCH v1 2/4] sql: refactor sqlite3AddNotNull function
Date: Mon, 16 Jul 2018 15:28:00 +0300	[thread overview]
Message-ID: <4f4e7934d0eac2f295adadb1e5572f8ff4dbf752.1531743627.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1531413184.git.kshcherbatov@tarantool.org>

---
 src/box/sql/build.c     | 22 ++++++++--------------
 src/box/sql/parse.y     |  6 +++---
 src/box/sql/sqliteInt.h | 17 ++++++++++++++++-
 3 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index 925193e..f53a37a 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -693,18 +693,12 @@ sqlite3AddColumn(Parse * pParse, Token * pName, Token * pType)
 	pParse->constraintName.n = 0;
 }
 
-/*
- * This routine is called by the parser while in the middle of
- * parsing a CREATE TABLE statement.  A "NOT NULL" constraint has
- * been seen on a column.  This routine sets the notNull flag on
- * the column currently under construction.
- */
 void
-sqlite3AddNotNull(Parse * pParse, int onError)
+sql_column_nullable_action_add(struct Parse *parser,
+			       enum on_conflict_action nullable_action)
 {
-	Table *p;
-	p = pParse->pNewTable;
-	if (p == 0 || NEVER(p->def->field_count < 1))
+	struct Table *p = parser->pNewTable;
+	if (p == NULL || NEVER(p->def->field_count < 1))
 		return;
 	struct field_def *field = &p->def->fields[p->def->field_count - 1];
 	if (field->nullable_action != on_conflict_action_MAX) {
@@ -716,12 +710,12 @@ sqlite3AddNotNull(Parse * pParse, int onError)
 				   on_conflict_action_strs[field->
 							   nullable_action]);
 		diag_set(ClientError, ER_SQL, err_msg);
-		pParse->rc = SQL_TARANTOOL_ERROR;
-		pParse->nErr++;
+		parser->rc = SQL_TARANTOOL_ERROR;
+		parser->nErr++;
 		return;
 	}
-	field->nullable_action = onError;
-	field->is_nullable = action_is_nullable(onError);
+	field->nullable_action = nullable_action;
+	field->is_nullable = action_is_nullable(nullable_action);
 }
 
 /*
diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index e2bdc4a..fe77ae0 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -277,12 +277,12 @@ ccons ::= DEFAULT id(X).              {
 // UNIQUE constraints.
 //
 ccons ::= NULL onconf(R).        {
-    sqlite3AddNotNull(pParse, ON_CONFLICT_ACTION_NONE);
+    sql_column_nullable_action_add(pParse, ON_CONFLICT_ACTION_NONE);
     /* Trigger nullability mismatch error if required. */
     if (R != ON_CONFLICT_ACTION_DEFAULT)
-        sqlite3AddNotNull(pParse, R);
+        sql_column_nullable_action_add(pParse, R);
 }
-ccons ::= NOT NULL onconf(R).    {sqlite3AddNotNull(pParse, R);}
+ccons ::= NOT NULL onconf(R).    {sql_column_nullable_action_add(pParse, R);}
 ccons ::= PRIMARY KEY sortorder(Z) onconf(R) autoinc(I).
                                  {sqlite3AddPrimaryKey(pParse,0,R,I,Z);}
 ccons ::= UNIQUE onconf(R).      {sql_create_index(pParse,0,0,0,R,0,0,
diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h
index 18bf949..c89d256 100644
--- a/src/box/sql/sqliteInt.h
+++ b/src/box/sql/sqliteInt.h
@@ -3515,7 +3515,22 @@ Table *sqlite3ResultSetOfSelect(Parse *, Select *);
 Index *sqlite3PrimaryKeyIndex(Table *);
 void sqlite3StartTable(Parse *, Token *, int);
 void sqlite3AddColumn(Parse *, Token *, Token *);
-void sqlite3AddNotNull(Parse *, int);
+
+/**
+ * This routine is called by the parser while in the middle of
+ * parsing a CREATE TABLE statement.  A "NOT NULL" constraint has
+ * been seen on a column.  This routine sets the is_nullable flag
+ * on the column currently under construction.
+ * If nullable_action has been already set, this function raises
+ * an error.
+ *
+ * @param parser SQL Parser object.
+ * @param nullable_action on_conflict_action value.
+ */
+void
+sql_column_nullable_action_add(struct Parse *parser,
+			       enum on_conflict_action nullable_action);
+
 void sqlite3AddPrimaryKey(Parse *, ExprList *, int, int, enum sort_order);
 
 /**
-- 
2.7.4

  parent reply	other threads:[~2018-07-16 12:28 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-12 16:34 [tarantool-patches] [PATCH v1 0/2] sql: restrict nullable action definitions Kirill Shcherbatov
2018-07-12 16:34 ` [tarantool-patches] [PATCH v1 1/2] " Kirill Shcherbatov
2018-07-13 10:26   ` [tarantool-patches] " Vladislav Shpilevoy
2018-07-13 16:05     ` Kirill Shcherbatov
2018-07-13 20:03       ` Vladislav Shpilevoy
2018-07-16  9:43         ` Kirill Shcherbatov
2018-07-16 10:20           ` Vladislav Shpilevoy
2018-07-16 12:27             ` Kirill Shcherbatov
2018-07-12 16:34 ` [tarantool-patches] [PATCH v1 2/2] sql: fixed possible leak in sqlite3EndTable Kirill Shcherbatov
2018-07-13 10:26   ` [tarantool-patches] " Vladislav Shpilevoy
2018-07-13 16:05     ` Kirill Shcherbatov
2018-07-13 10:26 ` [tarantool-patches] Re: [PATCH v1 0/2] sql: restrict nullable action definitions Vladislav Shpilevoy
2018-07-16 12:28 ` Kirill Shcherbatov [this message]
2018-07-16 13:41   ` [tarantool-patches] Re: [PATCH v1 2/4] sql: refactor sqlite3AddNotNull function Vladislav Shpilevoy
2018-07-16 12:28 ` [tarantool-patches] [PATCH v1 4/4] sql: get rid of Column structure Kirill Shcherbatov
2018-07-16 13:40   ` [tarantool-patches] " Vladislav Shpilevoy
2018-07-16 16:33     ` Kirill Shcherbatov
2018-07-17  9:32       ` Vladislav Shpilevoy
2018-07-17 14:08         ` Kirill Shcherbatov
2018-07-17 22:01           ` Vladislav Shpilevoy
2018-07-18  7:25             ` Kirill Shcherbatov
2018-07-18  8:04               ` Vladislav Shpilevoy
2018-07-18 16:41                 ` n.pettik

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=4f4e7934d0eac2f295adadb1e5572f8ff4dbf752.1531743627.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH v1 2/4] sql: refactor sqlite3AddNotNull function' \
    /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