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 15D1C2A8B0 for ; Thu, 28 Mar 2019 08:08:03 -0400 (EDT) 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 qPzv3P_kF130 for ; Thu, 28 Mar 2019 08:08:02 -0400 (EDT) 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 BD75C29C65 for ; Thu, 28 Mar 2019 08:08:02 -0400 (EDT) From: Nikita Pettik Subject: [tarantool-patches] [PATCH v2 1/4] sql: rework ALTER TABLE grammar Date: Thu, 28 Mar 2019 15:07:55 +0300 Message-Id: <812a298598a9aea10c0a0f887bbf0428835fe67d.1553729426.git.korablev@tarantool.org> In-Reply-To: References: In-Reply-To: References: 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: v.shpilevoy@tarantool.org, Nikita Pettik Since ALTER TABLE ADD CONSTRAINT is going to be used to add various constraint types (foreign key, unique etc), let's a bit refactor it to make it more extendable. Needed for #3097 --- src/box/sql/parse.y | 31 ++++++++++++++++++++++++------- test/sql-tap/alter2.test.lua | 2 +- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y index 4eff61777..0c4603e83 100644 --- a/src/box/sql/parse.y +++ b/src/box/sql/parse.y @@ -1600,18 +1600,35 @@ cmd ::= DROP TRIGGER ifexists(NOERR) fullname(X). { } //////////////////////// ALTER TABLE table ... //////////////////////////////// -cmd ::= ALTER TABLE fullname(X) RENAME TO nm(Z). { - rename_entity_def_init(&pParse->rename_entity_def, X, &Z); - sql_alter_table_rename(pParse); +%include { + struct alter_args { + struct SrcList *table_name; + /** Name of constraint OR new name of table in case of RENAME. */ + struct Token name; + }; +} + +%type alter_table_start {struct SrcList *} +alter_table_start(A) ::= ALTER TABLE fullname(T) . { A = T; } + +%type alter_add_constraint {struct alter_args} +alter_add_constraint(A) ::= alter_table_start(T) ADD CONSTRAINT nm(N). { + A.table_name = T; + A.name = N; } -cmd ::= ALTER TABLE fullname(X) ADD CONSTRAINT nm(Z) FOREIGN KEY - LP eidlist(FA) RP REFERENCES nm(T) eidlist_opt(TA) matcharg(M) - refargs(R) defer_subclause_opt(D). { - create_fk_def_init(&pParse->create_fk_def, X, &Z, FA, &T, TA, M, R, D); +cmd ::= alter_add_constraint(N) FOREIGN KEY LP eidlist(FA) RP REFERENCES + nm(T) eidlist_opt(TA) matcharg(M) refargs(R) defer_subclause_opt(D). { + create_fk_def_init(&pParse->create_fk_def, N.table_name, &N.name, FA, &T, TA, + M, R, D); sql_create_foreign_key(pParse); } +cmd ::= alter_table_start(A) RENAME TO nm(N). { + rename_entity_def_init(&pParse->rename_entity_def, A, &N); + sql_alter_table_rename(pParse); +} + cmd ::= ALTER TABLE fullname(X) DROP CONSTRAINT nm(Z). { drop_fk_def_init(&pParse->drop_fk_def, X, &Z, false); sql_drop_foreign_key(pParse); diff --git a/test/sql-tap/alter2.test.lua b/test/sql-tap/alter2.test.lua index beb6f5d8a..cc1ff5088 100755 --- a/test/sql-tap/alter2.test.lua +++ b/test/sql-tap/alter2.test.lua @@ -223,7 +223,7 @@ test:do_catchsql_test( ALTER TABLE child ADD CONSTRAINT fk FOREIGN KEY REFERENCES child(id); ]], { -- - 1, "Syntax error near 'REFERENCES'" + 1, "Keyword 'REFERENCES' is reserved. Please use double quotes if 'REFERENCES' is an identifier." -- }) -- 2.15.1