[tarantool-patches] [PATCH v1 2/4] sql: refactor sqlite3AddNotNull function

  • From: Kirill Shcherbatov <kshcherbatov@xxxxxxxxxxxxx>
  • To: tarantool-patches@xxxxxxxxxxxxx
  • Date: Mon, 16 Jul 2018 15:28:00 +0300

---
 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


Other related posts: