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 7A9B92627B for ; Mon, 16 Jul 2018 08:28:06 -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 fGatrz8Y-i63 for ; Mon, 16 Jul 2018 08:28:06 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (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 31B3625E7A for ; Mon, 16 Jul 2018 08:28:06 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v1 2/4] sql: refactor sqlite3AddNotNull function Date: Mon, 16 Jul 2018 15:28:00 +0300 Message-Id: <4f4e7934d0eac2f295adadb1e5572f8ff4dbf752.1531743627.git.kshcherbatov@tarantool.org> 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: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, Kirill Shcherbatov --- 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