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 96D7727321 for ; Thu, 14 Feb 2019 08:44:45 -0500 (EST) 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 n_hySHXuOl4p for ; Thu, 14 Feb 2019 08:44:45 -0500 (EST) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (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 47DA227215 for ; Thu, 14 Feb 2019 08:44:45 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Subject: [tarantool-patches] Re: [PATCH] sql: prohibit duplication of FK action clause From: "n.pettik" In-Reply-To: <20190214085640.5fkerrtzxfc5mluu@tarantool.org> Date: Thu, 14 Feb 2019 16:44:42 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <1099A8B2-A13F-4EAC-9C91-FC2C421C9660@tarantool.org> References: <68664d5ad6be9959c4364a288ccc2feed84cd8b4.1550037810.git.kyukhin@tarantool.org> <50B90E82-7ECC-4C12-B7EF-132E77EDDDEC@tarantool.org> <20190214085640.5fkerrtzxfc5mluu@tarantool.org> 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: Kirill Yukhin > 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) ::=3D AUTOINCR. {X =3D 1;} > %type refargs {int} > refargs(A) ::=3D . { A =3D FKEY_NO_ACTION; } > refargs(A) ::=3D refargs(A) refarg(Y). { if ((A & Y.mask) =3D=3D 0) { > - A =3D (A & ~Y.mask) | = Y.value; > + A =3D (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=E2=80=99t 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) ::=3D AUTOINCR. {X =3D 1;} // %type refargs {int} refargs(A) ::=3D . { A =3D FKEY_NO_ACTION; } -refargs(A) ::=3D refargs(A) refarg(Y). { if ((A & Y.mask) =3D=3D 0) { - A =3D (A & ~Y.mask) | Y.value; - } else { - sqlErrorMsg(pParse, - "near \"%T\": = duplicate FK action clause.", - = &pParse->sLastToken); - } - } +refargs(A) ::=3D refargs(A) refarg(Y). { + if ((A & Y.mask) =3D=3D 0) { + A =3D (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)=E2=80=9D) 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)=E2=80=9D) Obviously, it happens since NO ACTION and SIMPLE are represented as zero valued members of enum. I don=E2=80=99t like idea to start enum = from value 1. Firstly, according to ANSI grammar, MATCH clause always comes before triggered actions: ::=3D REFERENCES [ MATCH ] [ ] So, we can simplify grammar to smth like this: refagrs(A) :: =3D 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) :: =3D ON DELETE reface(X). { if(A.is_delete_action_set) //raise an error A.is_delete_action_set =3D true; A.value =3D X; } refarg(A) :: =3D ON UPDATE reface(X). {A.is_update_action_set =3D true; = A.value =3D X; } ... That is my suggestion. I didn=E2=80=99t test it, but idea seems to be = valid. Alternatively, you can come up with better solution.