[tarantool-patches] Re: [PATCH 4/7] sql: refactor ALTER RENAME code generation

n.pettik korablev at tarantool.org
Mon Sep 3 02:52:08 MSK 2018


>> +	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>
     })



More information about the Tarantool-patches mailing list