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 573CB29476 for ; Sun, 2 Sep 2018 19:52:11 -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 D-f4Wlo769YH for ; Sun, 2 Sep 2018 19:52:11 -0400 (EDT) Received: from smtp51.i.mail.ru (smtp51.i.mail.ru [94.100.177.111]) (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 1763D26340 for ; Sun, 2 Sep 2018 19:52:11 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [tarantool-patches] Re: [PATCH 4/7] sql: refactor ALTER RENAME code generation From: "n.pettik" In-Reply-To: Date: Mon, 3 Sep 2018 02:52:08 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <0A51AE71-AC33-4DAE-BA04-CE27B5C41C6B@tarantool.org> References: <793300224e2f072e2559566577d0fd7e56740295.1535064700.git.korablev@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: Vladislav Shpilevoy >> + assert(src_tab->nSrc =3D=3D 1); >> + struct sqlite3 *db =3D parse->db; >> + char *new_name =3D sqlite3NameFromToken(db, new_name_tk); >> + if (new_name =3D=3D NULL) >> goto exit_rename_table; >> + /* Check that new name isn't occupied by another table. */ >> + uint32_t space_id =3D box_space_id_by_name(new_name, = strlen(new_name)); >> + if (space_id !=3D BOX_ID_NIL) { >> + diag_set(ClientError, ER_SQL_EXECUTE, tt_sprintf("there = is " >> + "already another table with this name: %s", = new_name)); >=20 > 1. ER_SPACE_EXISTS Fixed, see below. >=20 >> + goto tnt_error; >> } >> - if (pTab->def->opts.is_view) { >> - sqlite3ErrorMsg(pParse, "view %s may not be altered", >> - pTab->def->name); >> - goto exit_rename_table; >> + const char *tbl_name =3D src_tab->a[0].zName; >> + space_id =3D box_space_id_by_name(tbl_name, strlen(tbl_name)); >> + if (space_id =3D=3D BOX_ID_NIL) { >> + diag_set(ClientError, ER_NO_SUCH_SPACE, tbl_name); >> + goto tnt_error; >> } >> - /* Begin a transaction for database. */ >> - v =3D sqlite3GetVdbe(pParse); >> - if (v =3D=3D 0) { >> - goto exit_rename_table; >> + struct space *space =3D space_by_id(space_id); >> + assert(space !=3D NULL); >> + if (space->def->opts.is_view) { >> + diag_set(ClientError, ER_SQL_EXECUTE, >> + "view may not be altered"); >> + goto tnt_error; >=20 > 2. ER_ALTER_SPACE or ER_UNSUPPORTED, on your choice. diff --git a/src/box/sql/alter.c b/src/box/sql/alter.c index 320dfdd05..3d72e311a 100644 --- a/src/box/sql/alter.c +++ b/src/box/sql/alter.c @@ -49,8 +49,7 @@ sql_alter_table_rename(struct Parse *parse, struct = SrcList *src_tab, /* Check that new name isn't occupied by another table. */ uint32_t space_id =3D box_space_id_by_name(new_name, = strlen(new_name)); if (space_id !=3D BOX_ID_NIL) { - diag_set(ClientError, ER_SQL_EXECUTE, tt_sprintf("there = is " - "already another table with this name: %s", = new_name)); + diag_set(ClientError, ER_SPACE_EXISTS, new_name); goto tnt_error; } const char *tbl_name =3D src_tab->a[0].zName; @@ -62,7 +61,7 @@ sql_alter_table_rename(struct Parse *parse, struct = SrcList *src_tab, struct space *space =3D space_by_id(space_id); assert(space !=3D NULL); if (space->def->opts.is_view) { - diag_set(ClientError, ER_SQL_EXECUTE, + diag_set(ClientError, ER_ALTER_SPACE, tbl_name, "view may not be altered"); goto tnt_error; } diff --git a/test/sql-tap/alter.test.lua b/test/sql-tap/alter.test.lua index ffd0ba6dc..355c87a09 100755 --- a/test/sql-tap/alter.test.lua +++ b/test/sql-tap/alter.test.lua @@ -83,7 +83,7 @@ test:do_catchsql_test( ALTER TABLE t2 RENAME TO t3; ]], { -- - 1, "Failed to execute SQL statement: there is already another = table with this name: T3" + 1, "Space 'T3' already exists" -- })=