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 E47B624728 for ; Wed, 9 Jan 2019 07:13:28 -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 K_xsSZfF998u for ; Wed, 9 Jan 2019 07:13:28 -0500 (EST) Received: from smtp50.i.mail.ru (smtp50.i.mail.ru [94.100.177.110]) (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 938051FE0E for ; Wed, 9 Jan 2019 07:13:28 -0500 (EST) From: Nikita Pettik Subject: [tarantool-patches] [PATCH 2/6] sql: rework ALTER TABLE grammar Date: Wed, 9 Jan 2019 14:13:16 +0200 Message-Id: <0117c011c631182ddd64cff7a46e2b3e940bf03c.1547035183.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 can be used to add various constraint types (foreign key, unique etc), we should rework its grammar. As a reference for it lets use one from ANSI. Needed for #3097 --- src/box/sql/parse.y | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y index f4fdf58f2..874a67a9b 100644 --- a/src/box/sql/parse.y +++ b/src/box/sql/parse.y @@ -318,10 +318,8 @@ tcons ::= UNIQUE LP sortlist(X) RP. SQL_INDEX_TYPE_CONSTRAINT_UNIQUE);} tcons ::= CHECK LP expr(E) RP onconf. {sql_add_check_constraint(pParse,&E);} -tcons ::= FOREIGN KEY LP eidlist(FA) RP - REFERENCES nm(T) eidlist_opt(TA) refargs(R) defer_subclause_opt(D). { - sql_create_foreign_key(pParse, FA, &T, TA, D, R); -} +tcons ::= foreign_key_def. + %type defer_subclause_opt {int} defer_subclause_opt(A) ::= . {A = 0;} defer_subclause_opt(A) ::= defer_subclause(A). @@ -1444,22 +1442,38 @@ cmd ::= ANALYZE. {sqlite3Analyze(pParse, 0);} cmd ::= ANALYZE nm(X). {sqlite3Analyze(pParse, &X);} //////////////////////// ALTER TABLE table ... //////////////////////////////// -cmd ::= ALTER TABLE fullname(X) RENAME TO nm(Z). { - pParse->constraint->table_name = X; +cmd ::= alter_table_start alter_table_action . + +alter_table_start ::= ALTER TABLE fullname(Z) . { + pParse->constraint->table_name = Z; + pParse->constraint->name.n = 0; +} + +alter_table_action ::= add_constraint_def. +alter_table_action ::= drop_constraint_def. +/** RENAME is ANSI extension, so it comes as a very special case. */ +alter_table_action ::= rename. + +rename ::= RENAME TO nm(Z). { sql_alter_table_rename(pParse, &Z); } -cmd ::= ALTER TABLE fullname(X) ADD CONSTRAINT nm(Z) FOREIGN KEY - LP eidlist(FA) RP REFERENCES nm(T) eidlist_opt(TA) refargs(R) - defer_subclause_opt(D). { - pParse->constraint->table_name = X; - pParse->constraint->name = Z; - sql_create_foreign_key(pParse, FA, &T, TA, D, R); +add_constraint_def ::= add_constraint_start constraint_def. + +add_constraint_start ::= ADD CONSTRAINT nm(Z). { + pParse->constraint->name = Z; } -cmd ::= ALTER TABLE fullname(X) DROP CONSTRAINT nm(Z). { - pParse->constraint->table_name = X; - sql_drop_foreign_key(pParse, &Z); +constraint_def ::= foreign_key_def. + +foreign_key_def ::= FOREIGN KEY LP eidlist(FA) RP REFERENCES nm(T) + eidlist_opt(TA) refargs(R) defer_subclause_opt(D). { + sql_create_foreign_key(pParse, FA, &T, TA, D, R); +} + + +drop_constraint_def ::= DROP CONSTRAINT nm(Z). { + sql_drop_foreign_key(pParse, &Z); } //////////////////////// COMMON TABLE EXPRESSIONS //////////////////////////// -- 2.15.1