Tarantool development patches archive
 help / color / mirror / Atom feed
From: "n.pettik" <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH 4/7] sql: refactor ALTER RENAME code generation
Date: Mon, 3 Sep 2018 02:52:08 +0300	[thread overview]
Message-ID: <0A51AE71-AC33-4DAE-BA04-CE27B5C41C6B@tarantool.org> (raw)
In-Reply-To: <b7a52099-dc4c-7706-1019-17c4d1d31a7f@tarantool.org>


>> +	assert(src_tab->nSrc == 1);
>> +	struct sqlite3 *db = parse->db;
>> +	char *new_name = sqlite3NameFromToken(db, new_name_tk);
>> +	if (new_name == NULL)
>>  		goto exit_rename_table;
>> +	/* Check that new name isn't occupied by another table. */
>> +	uint32_t space_id = box_space_id_by_name(new_name, strlen(new_name));
>> +	if (space_id != BOX_ID_NIL) {
>> +		diag_set(ClientError, ER_SQL_EXECUTE, tt_sprintf("there is "
>> +			"already another table with this name: %s", new_name));
> 
> 1. ER_SPACE_EXISTS

Fixed, see below.

> 
>> +		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 = src_tab->a[0].zName;
>> +	space_id = box_space_id_by_name(tbl_name, strlen(tbl_name));
>> +	if (space_id == BOX_ID_NIL) {
>> +		diag_set(ClientError, ER_NO_SUCH_SPACE, tbl_name);
>> +		goto tnt_error;
>>  	}
>> -	/* Begin a transaction for database. */
>> -	v = sqlite3GetVdbe(pParse);
>> -	if (v == 0) {
>> -		goto exit_rename_table;
>> +	struct space *space = space_by_id(space_id);
>> +	assert(space != NULL);
>> +	if (space->def->opts.is_view) {
>> +		diag_set(ClientError, ER_SQL_EXECUTE,
>> +			 "view may not be altered");
>> +		goto tnt_error;
> 
> 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 = box_space_id_by_name(new_name, strlen(new_name));
        if (space_id != 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 = src_tab->a[0].zName;
@@ -62,7 +61,7 @@ sql_alter_table_rename(struct Parse *parse, struct SrcList *src_tab,
        struct space *space = space_by_id(space_id);
        assert(space != 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;
     ]], {
         -- <alter-2.2>
-        1, "Failed to execute SQL statement: there is already another table with this name: T3"
+        1, "Space 'T3' already exists"
         -- </alter-2.2>
     })

  reply	other threads:[~2018-09-02 23:52 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-23 22:55 [tarantool-patches] [PATCH 0/7] Finish SQL DD integration Nikita Pettik
     [not found] ` <cover.1535064700.git.korablev@tarantool.org>
2018-08-23 22:55   ` [tarantool-patches] [PATCH 1/7] sql: remove struct schema from struct Table Nikita Pettik
2018-08-29  0:58     ` [tarantool-patches] " Vladislav Shpilevoy
2018-09-02 23:51       ` n.pettik
2018-09-16 19:32     ` Vladislav Shpilevoy
2018-09-19 10:58       ` n.pettik
2018-08-23 22:55   ` [tarantool-patches] [PATCH 2/7] sql: remove SQLite original struct Index Nikita Pettik
2018-08-29  0:58     ` [tarantool-patches] " Vladislav Shpilevoy
2018-09-02 23:51       ` n.pettik
2018-09-06 19:54         ` Vladislav Shpilevoy
2018-09-16 19:04           ` n.pettik
2018-08-23 22:55   ` [tarantool-patches] [PATCH 3/7] sql: remove struct Table from analyze routine Nikita Pettik
2018-08-29  0:58     ` [tarantool-patches] " Vladislav Shpilevoy
2018-09-02 23:52       ` n.pettik
2018-08-23 22:55   ` [tarantool-patches] [PATCH 4/7] sql: refactor ALTER RENAME code generation Nikita Pettik
2018-08-29  0:58     ` [tarantool-patches] " Vladislav Shpilevoy
2018-09-02 23:52       ` n.pettik [this message]
2018-08-23 22:55   ` [tarantool-patches] [PATCH 5/7] sql: remove lookups in Table hash Nikita Pettik
2018-08-29  0:58     ` [tarantool-patches] " Vladislav Shpilevoy
2018-09-02 23:52       ` n.pettik
2018-08-23 22:55   ` [tarantool-patches] [PATCH 6/7] sql: don't add system spaces to " Nikita Pettik
2018-08-29  0:58     ` [tarantool-patches] " Vladislav Shpilevoy
2018-09-02 23:52       ` n.pettik
2018-09-06 19:54         ` Vladislav Shpilevoy
2018-09-16 19:04           ` n.pettik
2018-08-23 22:55   ` [tarantool-patches] [PATCH 7/7] sql: finish DD integration Nikita Pettik
2018-08-29  0:58     ` [tarantool-patches] " Vladislav Shpilevoy
2018-09-20 14:45       ` Kirill Yukhin

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=0A51AE71-AC33-4DAE-BA04-CE27B5C41C6B@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='[tarantool-patches] Re: [PATCH 4/7] sql: refactor ALTER RENAME code generation' \
    /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