From: "n.pettik" <korablev@tarantool.org> To: tarantool-patches@freelists.org Cc: Kirill Yukhin <kyukhin@tarantool.org> Subject: [tarantool-patches] Re: [PATCH] sql: prohibit duplication of FK action clause Date: Thu, 14 Feb 2019 16:44:42 +0300 [thread overview] Message-ID: <1099A8B2-A13F-4EAC-9C91-FC2C421C9660@tarantool.org> (raw) In-Reply-To: <20190214085640.5fkerrtzxfc5mluu@tarantool.org> > diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y > index 8c8fdc2..7ee8dc2 100644 > --- a/src/box/sql/parse.y > +++ b/src/box/sql/parse.y > @@ -284,11 +284,11 @@ autoinc(X) ::= AUTOINCR. {X = 1;} > %type refargs {int} > refargs(A) ::= . { A = FKEY_NO_ACTION; } > refargs(A) ::= refargs(A) refarg(Y). { if ((A & Y.mask) == 0) { > - A = (A & ~Y.mask) | Y.value; > + A = (A & ~Y.mask) | Y.value; > } else { > - sqlite3ErrorMsg(pParse, > - "near \"%T\": duplicate FK action clause.", > - &pParse->sLastToken); > + sqlErrorMsg(pParse, > + "near \"%T\": duplicate FK action clause.", > + &pParse->sLastToken); > } > } Doesn’t look better. What I really meant is: diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y index 7ee8dc292..cc4afaf71 100644 --- a/src/box/sql/parse.y +++ b/src/box/sql/parse.y @@ -283,14 +283,14 @@ autoinc(X) ::= AUTOINCR. {X = 1;} // %type refargs {int} refargs(A) ::= . { A = FKEY_NO_ACTION; } -refargs(A) ::= refargs(A) refarg(Y). { if ((A & Y.mask) == 0) { - A = (A & ~Y.mask) | Y.value; - } else { - sqlErrorMsg(pParse, - "near \"%T\": duplicate FK action clause.", - &pParse->sLastToken); - } - } +refargs(A) ::= refargs(A) refarg(Y). { + if ((A & Y.mask) == 0) { + A = (A & ~Y.mask) | Y.value; + } else { + sqlErrorMsg(pParse, "near \"%T\": duplicate FK action clause.", + &pParse->sLastToken); + } +} What is more, I found this: tarantool> box.sql.execute("CREATE TABLE t3(a INT PRIMARY KEY, b INT REFERENCES t1(b) ON DELETE NO ACTION ON DELETE NO ACTION)”) Is executed correctly. The same for MATCH: tarantool> box.sql.execute("CREATE TABLE t4(a INT PRIMARY KEY, b INT REFERENCES t1(b) MATCH SIMPLE ON DELETE NO ACTION ON UPDATE SET NULL MATCH FULL)”) Obviously, it happens since NO ACTION and SIMPLE are represented as zero valued members of enum. I don’t like idea to start enum from value 1. Firstly, according to ANSI grammar, MATCH clause always comes before triggered actions: <references specification> ::= REFERENCES <referenced table and columns> [ MATCH <match type> ] [ <referential triggered action> ] So, we can simplify grammar to smth like this: refagrs(A) :: = matcharg(X) refarg(Y) refarg(Z) . // Note that refargs is no longer recursive rule. Then, we can got rid of mask at all: %type refarg {struct {int value; bool is_delete_action_set; bool is_update_action_set ;}} refarg(A) :: = ON DELETE reface(X). { if(A.is_delete_action_set) //raise an error A.is_delete_action_set = true; A.value = X; } refarg(A) :: = ON UPDATE reface(X). {A.is_update_action_set = true; A.value = X; } ... That is my suggestion. I didn’t test it, but idea seems to be valid. Alternatively, you can come up with better solution.
prev parent reply other threads:[~2019-02-14 13:44 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-02-13 6:08 [tarantool-patches] " Kirill Yukhin 2019-02-13 19:43 ` [tarantool-patches] " n.pettik 2019-02-14 8:56 ` Kirill Yukhin 2019-02-14 13:44 ` n.pettik [this message]
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=1099A8B2-A13F-4EAC-9C91-FC2C421C9660@tarantool.org \ --to=korablev@tarantool.org \ --cc=kyukhin@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='[tarantool-patches] Re: [PATCH] sql: prohibit duplication of FK action clause' \ /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