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 0C591212D9 for ; Sat, 9 Jun 2018 05:36:12 -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 jxOjpxwZIGU1 for ; Sat, 9 Jun 2018 05:36:11 -0400 (EDT) Received: from fallback.mail.ru (fallback6.mail.ru [94.100.181.147]) (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 25B9221096 for ; Sat, 9 Jun 2018 05:36:11 -0400 (EDT) Received: from [10.161.100.15] (port=50786 helo=smtpng3.m.smailru.net) by fallback6.mail.ru with esmtp (envelope-from ) id 1fRaEf-0003R0-U4 for tarantool-patches@freelists.org; Sat, 09 Jun 2018 12:32:38 +0300 From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v2 07/11] sql: move sqlite3DeleteTrigger to sql.h Date: Sat, 9 Jun 2018 12:32:20 +0300 Message-Id: <8e81edd81ecfcb8b90330fde614c95488df15dfc.1528535873.git.kshcherbatov@tarantool.org> 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 Part of #3273. --- src/box/sql.h | 9 +++++++++ src/box/sql/callback.c | 2 +- src/box/sql/sqliteInt.h | 3 +-- src/box/sql/status.c | 6 +++--- src/box/sql/tokenize.c | 2 +- src/box/sql/trigger.c | 25 +++++++++++-------------- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/box/sql.h b/src/box/sql.h index 3f6cf22..35aacc3 100644 --- a/src/box/sql.h +++ b/src/box/sql.h @@ -66,6 +66,7 @@ struct Expr; struct Parse; struct Select; struct Table; +struct Trigger; /** * Perform parsing of provided expression. This is done by @@ -83,6 +84,14 @@ struct Expr * sql_expr_compile(struct sqlite3 *db, const char *expr, int expr_len); /** + * Free AST pointed by trigger. + * @param db SQL handle. + * @param trigger AST object. + */ +void +sql_trigger_delete(struct sqlite3 *db, struct Trigger *trigger); + +/** * Store duplicate of a parsed expression into @a parser. * @param parser Parser context. * @param select Select to extract from. diff --git a/src/box/sql/callback.c b/src/box/sql/callback.c index 8289c05..e3f36e3 100644 --- a/src/box/sql/callback.c +++ b/src/box/sql/callback.c @@ -292,7 +292,7 @@ sqlite3SchemaClear(sqlite3 * db) sqlite3HashInit(&pSchema->trigHash); for (pElem = sqliteHashFirst(&temp2); pElem; pElem = sqliteHashNext(pElem)) { - sqlite3DeleteTrigger(0, (Trigger *) sqliteHashData(pElem)); + sql_trigger_delete(0, (Trigger *) sqliteHashData(pElem)); } sqlite3HashClear(&temp2); sqlite3HashInit(&pSchema->tblHash); diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index 01351a1..ecbd573 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -4027,7 +4027,6 @@ TriggerStep *sqlite3TriggerInsertStep(sqlite3 *, Token *, IdList *, TriggerStep *sqlite3TriggerUpdateStep(sqlite3 *, Token *, ExprList *, Expr *, u8); TriggerStep *sqlite3TriggerDeleteStep(sqlite3 *, Token *, Expr *); -void sqlite3DeleteTrigger(sqlite3 *, Trigger *); void sqlite3UnlinkAndDeleteTrigger(sqlite3 *, const char *); u32 sqlite3TriggerColmask(Parse *, Trigger *, ExprList *, int, int, Table *, int); @@ -4035,7 +4034,7 @@ u32 sqlite3TriggerColmask(Parse *, Trigger *, ExprList *, int, int, Table *, #define sqlite3IsToplevel(p) ((p)->pToplevel==0) #else #define sqlite3TriggersExist(C,D,E,F) 0 -#define sqlite3DeleteTrigger(A,B) +#define sql_trigger_delete(A,B) #define sqlite3DropTriggerPtr(A,B) #define sqlite3UnlinkAndDeleteTrigger(A,B,C) #define sqlite3CodeRowTrigger(A,B,C,D,E,F,G,H,I) diff --git a/src/box/sql/status.c b/src/box/sql/status.c index 84f07cc..dda91c5 100644 --- a/src/box/sql/status.c +++ b/src/box/sql/status.c @@ -256,9 +256,9 @@ sqlite3_db_status(sqlite3 * db, /* The database connection whose status is desir for (p = sqliteHashFirst(&pSchema->trigHash); p; p = sqliteHashNext(p)) { - sqlite3DeleteTrigger(db, - (Trigger *) - sqliteHashData(p)); + sql_trigger_delete(db, + (Trigger *) + sqliteHashData(p)); } for (p = sqliteHashFirst(&pSchema->tblHash); p; p = sqliteHashNext(p)) { diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c index 5b7c97d..3f59fc8 100644 --- a/src/box/sql/tokenize.c +++ b/src/box/sql/tokenize.c @@ -534,7 +534,7 @@ sqlite3RunParser(Parse * pParse, const char *zSql, char **pzErrMsg) if (pParse->pWithToFree) sqlite3WithDelete(db, pParse->pWithToFree); - sqlite3DeleteTrigger(db, pParse->pNewTrigger); + sql_trigger_delete(db, pParse->pNewTrigger); sqlite3DbFree(db, pParse->pVList); while (pParse->pZombieTab) { Table *p = pParse->pZombieTab; diff --git a/src/box/sql/trigger.c b/src/box/sql/trigger.c index ea35211..053dadb 100644 --- a/src/box/sql/trigger.c +++ b/src/box/sql/trigger.c @@ -186,7 +186,7 @@ sqlite3BeginTrigger(Parse * pParse, /* The parse context of the CREATE TRIGGER s sqlite3IdListDelete(db, pColumns); sql_expr_delete(db, pWhen, false); if (!pParse->pNewTrigger) { - sqlite3DeleteTrigger(db, pTrigger); + sql_trigger_delete(db, pTrigger); } else { assert(pParse->pNewTrigger == pTrigger); } @@ -328,7 +328,7 @@ sqlite3FinishTrigger(Parse * pParse, /* Parser context */ /* No need to free zName sinceif we reach this point alloc for it either wasn't called at all or failed. */ } - sqlite3DeleteTrigger(db, pTrig); + sql_trigger_delete(db, pTrig); assert(!pParse->pNewTrigger); sqlite3DeleteTriggerStep(db, pStepList); } @@ -471,20 +471,17 @@ sqlite3TriggerDeleteStep(sqlite3 * db, /* Database connection */ return pTriggerStep; } -/* - * Recursively delete a Trigger structure - */ void -sqlite3DeleteTrigger(sqlite3 * db, Trigger * pTrigger) +sql_trigger_delete(struct sqlite3 *db, struct Trigger *trigger) { - if (pTrigger == 0) + if (trigger == NULL) return; - sqlite3DeleteTriggerStep(db, pTrigger->step_list); - sqlite3DbFree(db, pTrigger->zName); - sqlite3DbFree(db, pTrigger->table); - sql_expr_delete(db, pTrigger->pWhen, false); - sqlite3IdListDelete(db, pTrigger->pColumns); - sqlite3DbFree(db, pTrigger); + sqlite3DeleteTriggerStep(db, trigger->step_list); + sqlite3DbFree(db, trigger->zName); + sqlite3DbFree(db, trigger->table); + sql_expr_delete(db, trigger->pWhen, false); + sqlite3IdListDelete(db, trigger->pColumns); + sqlite3DbFree(db, trigger); } /* @@ -593,7 +590,7 @@ sqlite3UnlinkAndDeleteTrigger(sqlite3 * db, const char *zName) pp = &((*pp)->pNext)) ; *pp = (*pp)->pNext; } - sqlite3DeleteTrigger(db, pTrigger); + sql_trigger_delete(db, pTrigger); user_session->sql_flags |= SQLITE_InternChanges; } } -- 2.7.4