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 5EA7220672 for ; Wed, 23 May 2018 10:05:45 -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 j-AbqMPtC5PM for ; Wed, 23 May 2018 10:05:45 -0400 (EDT) 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 1B1F6205F5 for ; Wed, 23 May 2018 10:05:45 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v7 5/7] sql: change sqlite3AddCheckConstraint signature Date: Wed, 23 May 2018 17:05:32 +0300 Message-Id: In-Reply-To: References: 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 As we would store Check source expr in MsgPack we need span instead of parsed Expr only. Renamed refactored function to sql_add_check_constraint. Part of #3272. --- src/box/sql/build.c | 24 ++++++++++-------------- src/box/sql/parse.y | 4 ++-- src/box/sql/sqliteInt.h | 9 ++++++++- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/box/sql/build.c b/src/box/sql/build.c index a6ddcf0..afb1128 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -1019,26 +1019,22 @@ sqlite3AddPrimaryKey(Parse * pParse, /* Parsing context */ return; } -/* - * Add a new CHECK constraint to the table currently under construction. - */ void -sqlite3AddCheckConstraint(Parse * pParse, /* Parsing context */ - Expr * pCheckExpr /* The check expression */ - ) +sql_add_check_constraint(Parse *parser, ExprSpan *span) { #ifndef SQLITE_OMIT_CHECK - Table *pTab = pParse->pNewTable; - if (pTab) { - pTab->pCheck = - sqlite3ExprListAppend(pParse, pTab->pCheck, pCheckExpr); - if (pParse->constraintName.n) { - sqlite3ExprListSetName(pParse, pTab->pCheck, - &pParse->constraintName, 1); + struct Expr *expr = span->pExpr; + Table *table = parser->pNewTable; + if (table != NULL) { + table->pCheck = + sqlite3ExprListAppend(parser, table->pCheck, expr); + if (parser->constraintName.n) { + sqlite3ExprListSetName(parser, table->pCheck, + &parser->constraintName, 1); } } else #endif - sql_expr_delete(pParse->db, pCheckExpr, false); + sql_expr_delete(parser->db, expr, false); } /* diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y index 8eac310..cc3931d 100644 --- a/src/box/sql/parse.y +++ b/src/box/sql/parse.y @@ -284,7 +284,7 @@ ccons ::= PRIMARY KEY sortorder(Z) onconf(R) autoinc(I). ccons ::= UNIQUE onconf(R). {sql_create_index(pParse,0,0,0,R,0,0, SORT_ORDER_ASC, false, SQLITE_IDXTYPE_UNIQUE);} -ccons ::= CHECK LP expr(X) RP. {sqlite3AddCheckConstraint(pParse,X.pExpr);} +ccons ::= CHECK LP expr(X) RP. {sql_add_check_constraint(pParse,&X);} ccons ::= REFERENCES nm(T) eidlist_opt(TA) refargs(R). {sqlite3CreateForeignKey(pParse,0,&T,TA,R);} ccons ::= defer_subclause(D). {sqlite3DeferForeignKey(pParse,D);} @@ -336,7 +336,7 @@ tcons ::= UNIQUE LP sortlist(X) RP onconf(R). SORT_ORDER_ASC,false, SQLITE_IDXTYPE_UNIQUE);} tcons ::= CHECK LP expr(E) RP onconf. - {sqlite3AddCheckConstraint(pParse,E.pExpr);} + {sql_add_check_constraint(pParse,&E);} tcons ::= FOREIGN KEY LP eidlist(FA) RP REFERENCES nm(T) eidlist_opt(TA) refargs(R) defer_subclause_opt(D). { sqlite3CreateForeignKey(pParse, FA, &T, TA, R); diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index a7ef80f..a1a5269 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -3532,7 +3532,14 @@ void sqlite3StartTable(Parse *, Token *, int); void sqlite3AddColumn(Parse *, Token *, Token *); void sqlite3AddNotNull(Parse *, int); void sqlite3AddPrimaryKey(Parse *, ExprList *, int, int, enum sort_order); -void sqlite3AddCheckConstraint(Parse *, Expr *); + +/** + * Add a new CHECK constraint to the table currently under construction. + * @param parser Parsing context. + * @param span parser parsed expression object.. + */ +void sql_add_check_constraint(Parse *parser, ExprSpan *span); + void sqlite3AddDefaultValue(Parse *, ExprSpan *); void sqlite3AddCollateType(Parse *, Token *); -- 2.7.4