From: Nikita Pettik <korablev@tarantool.org> To: tarantool-patches@freelists.org Cc: Georgy Kirichenko <georgy@tarantool.org> Subject: [tarantool-patches] [PATCH 1/6] sql: split conflict action and affinity for Expr Date: Mon, 17 Sep 2018 23:32:25 +0300 [thread overview] Message-ID: <38b42cc370c2e531bb864e6172b8282d14073d56.1537216078.git.korablev@tarantool.org> (raw) In-Reply-To: <cover.1537216077.git.korablev@tarantool.org> In-Reply-To: <cover.1537216077.git.korablev@tarantool.org> From: Georgy Kirichenko <georgy@tarantool.org> Lets introduce separate field in struct Expr to store conflict action of RAISE() function, instead of messing it with affinity. --- src/box/sql/expr.c | 46 ++++++++++++++++++---------------------------- src/box/sql/fkey.c | 2 +- src/box/sql/parse.y | 4 ++-- src/box/sql/sqliteInt.h | 5 ++++- src/box/sql/treeview.c | 6 ++++-- 5 files changed, 29 insertions(+), 34 deletions(-) diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c index 50505b1d3..b57e3811d 100644 --- a/src/box/sql/expr.c +++ b/src/box/sql/expr.c @@ -4298,35 +4298,25 @@ sqlite3ExprCodeTarget(Parse * pParse, Expr * pExpr, int target) sqlite3VdbeResolveLabel(v, endLabel); 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); - if (!pParse->pTriggerTab) { - sqlite3ErrorMsg(pParse, - "RAISE() may only be used within a trigger-program"); - return 0; - } - if (pExpr->affinity == ON_CONFLICT_ACTION_ABORT) { - sqlite3MayAbort(pParse); - } - assert(!ExprHasProperty(pExpr, EP_IntValue)); - if (pExpr->affinity == ON_CONFLICT_ACTION_IGNORE) { - sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_OK, - ON_CONFLICT_ACTION_IGNORE, 0, - pExpr->u.zToken, - 0); - VdbeCoverage(v); - } else { - sqlite3HaltConstraint(pParse, - SQLITE_CONSTRAINT_TRIGGER, - pExpr->affinity, - pExpr->u.zToken, 0, 0); - } - - break; + case TK_RAISE: + if (pParse->pTriggerTab == NULL) { + sqlite3ErrorMsg(pParse, "RAISE() may only be used " + "within a trigger-program"); + return 0; } + if (pExpr->on_conflict_action == ON_CONFLICT_ACTION_ABORT) + sqlite3MayAbort(pParse); + assert(!ExprHasProperty(pExpr, EP_IntValue)); + if (pExpr->on_conflict_action == ON_CONFLICT_ACTION_IGNORE) { + sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_OK, + ON_CONFLICT_ACTION_IGNORE, 0, + pExpr->u.zToken, 0); + } else { + sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER, + pExpr->on_conflict_action, + pExpr->u.zToken, 0, 0); + } + break; } sqlite3ReleaseTempReg(pParse, regFree1); sqlite3ReleaseTempReg(pParse, regFree2); diff --git a/src/box/sql/fkey.c b/src/box/sql/fkey.c index 62337792b..2897e2969 100644 --- a/src/box/sql/fkey.c +++ b/src/box/sql/fkey.c @@ -845,7 +845,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 d8532d378..460147769 100644 --- a/src/box/sql/parse.y +++ b/src/box/sql/parse.y @@ -1404,14 +1404,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 = (enum on_conflict_action) T; } } diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index 1d32c9a03..5ca628aac 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -2106,7 +2106,10 @@ 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 */ + /** The affinity of the column or 0 if not a column. */ + enum affinity_type affinity; + /** Conflict action for RAISE() function. */ + 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..f6a1755f4 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: + unreachable(); } sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken); -- 2.15.1
next prev parent reply other threads:[~2018-09-17 20:33 UTC|newest] Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-09-17 20:32 [tarantool-patches] [PATCH 0/6] Introduce strict typing for SQL Nikita Pettik 2018-09-17 20:32 ` Nikita Pettik [this message] 2018-09-19 2:16 ` [tarantool-patches] Re: [PATCH 1/6] sql: split conflict action and affinity for Expr Konstantin Osipov 2018-09-27 20:24 ` Vladislav Shpilevoy 2018-10-12 11:18 ` n.pettik 2018-09-17 20:32 ` [tarantool-patches] [PATCH 2/6] sql: annotate SQL functions with return type Nikita Pettik 2018-09-27 20:23 ` [tarantool-patches] " Vladislav Shpilevoy 2018-10-12 11:18 ` n.pettik 2018-09-17 20:32 ` [tarantool-patches] [PATCH 3/6] sql: pass true types of columns to Tarantool Nikita Pettik 2018-09-19 2:23 ` [tarantool-patches] " Konstantin Osipov 2018-10-12 11:19 ` n.pettik 2018-09-27 20:23 ` Vladislav Shpilevoy 2018-10-12 11:18 ` n.pettik 2018-10-17 21:45 ` Vladislav Shpilevoy 2018-10-23 23:28 ` n.pettik 2018-10-29 21:32 ` Vladislav Shpilevoy 2018-11-02 2:36 ` n.pettik 2018-09-17 20:32 ` [tarantool-patches] [PATCH 4/6] sql: enforce implicit type conversions Nikita Pettik 2018-09-19 2:25 ` [tarantool-patches] " Konstantin Osipov 2018-09-27 20:24 ` Vladislav Shpilevoy 2018-10-12 11:19 ` n.pettik 2018-10-17 21:45 ` Vladislav Shpilevoy 2018-10-23 23:28 ` n.pettik 2018-10-29 21:32 ` Vladislav Shpilevoy 2018-11-02 2:36 ` n.pettik 2018-11-02 11:15 ` Vladislav Shpilevoy 2018-11-02 13:26 ` n.pettik 2018-09-17 20:32 ` [tarantool-patches] [PATCH 5/6] sql: return result-set type via IProto Nikita Pettik 2018-09-19 2:26 ` [tarantool-patches] " Konstantin Osipov 2018-09-27 20:24 ` Vladislav Shpilevoy 2018-10-12 11:19 ` n.pettik 2018-10-17 21:45 ` Vladislav Shpilevoy 2018-10-23 23:28 ` n.pettik 2018-09-17 20:32 ` [tarantool-patches] [PATCH 6/6] sql: discard numeric conversion by unary plus Nikita Pettik 2018-09-27 20:24 ` [tarantool-patches] " Vladislav Shpilevoy 2018-10-12 11:19 ` n.pettik 2018-09-27 20:24 ` [tarantool-patches] Re: [PATCH 0/6] Introduce strict typing for SQL Vladislav Shpilevoy 2018-10-12 11:18 ` n.pettik 2018-11-03 2:41 ` Kirill Yukhin
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=38b42cc370c2e531bb864e6172b8282d14073d56.1537216078.git.korablev@tarantool.org \ --to=korablev@tarantool.org \ --cc=georgy@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH 1/6] sql: split conflict action and affinity for Expr' \ /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