From: Georgy Kirichenko <georgy@tarantool.org> To: tarantool-patches@freelists.org Cc: Georgy Kirichenko <georgy@tarantool.org> Subject: [tarantool-patches] [PATCH 2/6] Split on_conflict_action and affinity Date: Mon, 20 Aug 2018 11:49:55 +0300 [thread overview] Message-ID: <7a17021e23097a86e814c6048226eed3d9949c74.1534754600.git.georgy@tarantool.org> (raw) In-Reply-To: <cover.1534754600.git.georgy@tarantool.org> Introduce a separate field to store expressions on_conflict_action and convert expression affinity into an enum --- src/box/sql/expr.c | 14 +++++++------- src/box/sql/fkey.c | 2 +- src/box/sql/parse.y | 4 ++-- src/box/sql/sqliteInt.h | 3 ++- src/box/sql/treeview.c | 6 ++++-- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c index a41ea8f13..a9bb013cc 100644 --- a/src/box/sql/expr.c +++ b/src/box/sql/expr.c @@ -4299,20 +4299,20 @@ sqlite3ExprCodeTarget(Parse * pParse, Expr * pExpr, int target) break; } case TK_RAISE:{ - assert(pExpr->affinity == ON_CONFLICT_ACTION_ROLLBACK - || pExpr->affinity == ON_CONFLICT_ACTION_ABORT - || pExpr->affinity == ON_CONFLICT_ACTION_FAIL - || pExpr->affinity == ON_CONFLICT_ACTION_IGNORE); + assert(pExpr->on_conflict_action == ON_CONFLICT_ACTION_ROLLBACK + || pExpr->on_conflict_action == ON_CONFLICT_ACTION_ABORT + || pExpr->on_conflict_action == ON_CONFLICT_ACTION_FAIL + || pExpr->on_conflict_action == ON_CONFLICT_ACTION_IGNORE); if (!pParse->pTriggerTab) { sqlite3ErrorMsg(pParse, "RAISE() may only be used within a trigger-program"); return 0; } - if (pExpr->affinity == ON_CONFLICT_ACTION_ABORT) { + if (pExpr->on_conflict_action == ON_CONFLICT_ACTION_ABORT) { sqlite3MayAbort(pParse); } assert(!ExprHasProperty(pExpr, EP_IntValue)); - if (pExpr->affinity == ON_CONFLICT_ACTION_IGNORE) { + if (pExpr->on_conflict_action == ON_CONFLICT_ACTION_IGNORE) { sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_OK, ON_CONFLICT_ACTION_IGNORE, 0, pExpr->u.zToken, @@ -4321,7 +4321,7 @@ sqlite3ExprCodeTarget(Parse * pParse, Expr * pExpr, int target) } else { sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER, - pExpr->affinity, + pExpr->on_conflict_action, pExpr->u.zToken, 0, 0); } diff --git a/src/box/sql/fkey.c b/src/box/sql/fkey.c index 1208fe3da..4e59111af 100644 --- a/src/box/sql/fkey.c +++ b/src/box/sql/fkey.c @@ -844,7 +844,7 @@ fkey_action_trigger(struct Parse *pParse, struct Table *pTab, struct fkey *fkey, struct Expr *r = sqlite3Expr(db, TK_RAISE, "FOREIGN KEY "\ "constraint failed"); if (r != NULL) - r->affinity = ON_CONFLICT_ACTION_ABORT; + r->on_conflict_action = ON_CONFLICT_ACTION_ABORT; select = sqlite3SelectNew(pParse, sql_expr_list_append(db, NULL, r), sqlite3SrcListAppend(db, NULL, &err), diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y index 200d57a7d..3358a1e6c 100644 --- a/src/box/sql/parse.y +++ b/src/box/sql/parse.y @@ -1408,14 +1408,14 @@ expr(A) ::= RAISE(X) LP IGNORE RP(Y). { spanSet(&A,&X,&Y); /*A-overwrites-X*/ A.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0); if( A.pExpr ){ - A.pExpr->affinity = ON_CONFLICT_ACTION_IGNORE; + A.pExpr->on_conflict_action = ON_CONFLICT_ACTION_IGNORE; } } expr(A) ::= RAISE(X) LP raisetype(T) COMMA STRING(Z) RP(Y). { spanSet(&A,&X,&Y); /*A-overwrites-X*/ A.pExpr = sqlite3ExprAlloc(pParse->db, TK_RAISE, &Z, 1); if( A.pExpr ) { - A.pExpr->affinity = (char)T; + A.pExpr->on_conflict_action = (char)T; } } diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index 189d16150..df335a298 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -2201,7 +2201,8 @@ typedef int ynVar; */ struct Expr { u8 op; /* Operation performed by this node */ - char affinity; /* The affinity of the column or 0 if not a column */ + enum affinity_type affinity; /* The affinity of the column or 0 if not a column */ + enum on_conflict_action on_conflict_action; u32 flags; /* Various flags. EP_* See below */ union { char *zToken; /* Token value. Zero terminated and dequoted */ diff --git a/src/box/sql/treeview.c b/src/box/sql/treeview.c index 4261e733e..90f5c466b 100644 --- a/src/box/sql/treeview.c +++ b/src/box/sql/treeview.c @@ -566,8 +566,8 @@ sqlite3TreeViewExpr(TreeView * pView, const Expr * pExpr, u8 moreToFollow) break; } case TK_RAISE:{ - const char *zType = "unk"; - switch (pExpr->affinity) { + const char *zType; + switch (pExpr->on_conflict_action) { case ON_CONFLICT_ACTION_ROLLBACK: zType = "rollback"; break; @@ -580,6 +580,8 @@ sqlite3TreeViewExpr(TreeView * pView, const Expr * pExpr, u8 moreToFollow) case ON_CONFLICT_ACTION_IGNORE: zType = "ignore"; break; + default: + zType = "unk"; } sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken); -- 2.18.0
next prev parent reply other threads:[~2018-08-20 8:50 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-08-20 8:49 [tarantool-patches] [PATCH 0/6] SQL types Georgy Kirichenko 2018-08-20 8:49 ` [tarantool-patches] [PATCH 1/6] Specify types for internal tables Georgy Kirichenko 2018-08-20 8:49 ` Georgy Kirichenko [this message] 2018-08-20 8:49 ` [tarantool-patches] [PATCH 3/6] Annotate a sql function with affinity Georgy Kirichenko 2018-08-20 8:49 ` [tarantool-patches] [PATCH 4/6] Enforce space format for sql columns Georgy Kirichenko 2018-08-20 8:49 ` [tarantool-patches] [PATCH 5/6] Enforce internal data type conversions Georgy Kirichenko 2018-08-20 8:49 ` [tarantool-patches] [PATCH 6/6] Evaluate an affinity for all producing expressions Georgy Kirichenko
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=7a17021e23097a86e814c6048226eed3d9949c74.1534754600.git.georgy@tarantool.org \ --to=georgy@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH 2/6] Split on_conflict_action and affinity' \ /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