From: Kirill Shcherbatov <kshcherbatov@tarantool.org> To: tarantool-patches@freelists.org Cc: korablev@tarantool.org, Kirill Shcherbatov <kshcherbatov@tarantool.org> Subject: [tarantool-patches] [PATCH v4 2/6] sql: move sqlite3DeleteTrigger to sql.h Date: Wed, 20 Jun 2018 13:46:12 +0300 [thread overview] Message-ID: <89545939d761bc8aed87b49c4da2984e5c9e15c3.1529490955.git.kshcherbatov@tarantool.org> (raw) In-Reply-To: <cover.1529490955.git.kshcherbatov@tarantool.org> In-Reply-To: <cover.1529490955.git.kshcherbatov@tarantool.org> As we are going to port triggers to server, we need an instrument to release allocated memory in alter.cc. Part of #3273. --- src/box/sql.h | 9 +++++++++ src/box/sql/callback.c | 7 +++---- src/box/sql/sqliteInt.h | 3 +-- src/box/sql/status.c | 6 +++--- src/box/sql/tokenize.c | 2 +- src/box/sql/trigger.c | 30 +++++++++++++----------------- 6 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/box/sql.h b/src/box/sql.h index ef9e099..90bba1a 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 @@ -94,6 +95,14 @@ struct Select * sql_view_compile(struct sqlite3 *db, const char *view_stmt); /** + * 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..bd8db99 100644 --- a/src/box/sql/callback.c +++ b/src/box/sql/callback.c @@ -290,10 +290,9 @@ sqlite3SchemaClear(sqlite3 * db) temp1 = pSchema->tblHash; temp2 = pSchema->trigHash; sqlite3HashInit(&pSchema->trigHash); - for (pElem = sqliteHashFirst(&temp2); pElem; - pElem = sqliteHashNext(pElem)) { - sqlite3DeleteTrigger(0, (Trigger *) sqliteHashData(pElem)); - } + for (pElem = sqliteHashFirst(&temp2); pElem != NULL; + pElem = sqliteHashNext(pElem)) + sql_trigger_delete(NULL, (Trigger *) sqliteHashData(pElem)); sqlite3HashClear(&temp2); sqlite3HashInit(&pSchema->tblHash); for (pElem = sqliteHashFirst(&temp1); pElem; diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index 88644c6..a9388f1 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -4091,7 +4091,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); @@ -4099,7 +4098,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 5654e63..1e84c1e 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 ad8e243..fd1cb50 100644 --- a/src/box/sql/trigger.c +++ b/src/box/sql/trigger.c @@ -185,11 +185,10 @@ sqlite3BeginTrigger(Parse * pParse, /* The parse context of the CREATE TRIGGER s sqlite3SrcListDelete(db, pTableName); sqlite3IdListDelete(db, pColumns); sql_expr_delete(db, pWhen, false); - if (!pParse->pNewTrigger) { - sqlite3DeleteTrigger(db, pTrigger); - } else { + if (pParse->pNewTrigger == NULL) + sql_trigger_delete(db, pTrigger); + else assert(pParse->pNewTrigger == pTrigger); - } } /* @@ -328,7 +327,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 +470,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 +589,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
next prev parent reply other threads:[~2018-06-20 10:46 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-06-20 10:46 [tarantool-patches] [PATCH v4 0/6] sql: remove Triggers to server Kirill Shcherbatov 2018-06-20 10:46 ` [tarantool-patches] [PATCH v4 1/6] sql: refactor sql_expr_compile to return AST Kirill Shcherbatov 2018-06-20 10:46 ` Kirill Shcherbatov [this message] 2018-06-20 10:46 ` [tarantool-patches] [PATCH v4 3/6] box: sort error codes in misc.test Kirill Shcherbatov 2018-06-20 10:46 ` [tarantool-patches] [PATCH v4 4/6] sql: new _trigger space format with space_id Kirill Shcherbatov 2018-06-20 10:46 ` [tarantool-patches] [PATCH v4 5/6] sql: move Triggers to server Kirill Shcherbatov 2018-06-24 15:24 ` [tarantool-patches] " n.pettik 2018-06-24 20:41 ` Vladislav Shpilevoy 2018-06-25 15:27 ` Kirill Shcherbatov 2018-06-26 14:05 ` n.pettik 2018-06-26 16:13 ` Kirill Shcherbatov 2018-06-20 10:46 ` [tarantool-patches] [PATCH v4 6/6] sql: VDBE tests for trigger existence Kirill Shcherbatov 2018-06-24 15:25 ` [tarantool-patches] " n.pettik 2018-06-25 15:27 ` Kirill Shcherbatov 2018-06-26 14:49 ` 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=89545939d761bc8aed87b49c4da2984e5c9e15c3.1529490955.git.kshcherbatov@tarantool.org \ --to=kshcherbatov@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH v4 2/6] sql: move sqlite3DeleteTrigger to sql.h' \ /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