Skip to content

Commit 30a59a8

Browse files
author
Sreeharsha Ramanavarapu
committed
Bug #24595937: INCORRECT BEHAVIOR WHEN LOADING DATA TO VIEW
Issue: ------ While using the LOAD statement to insert data into an updateable view, the check to verify whether a column is actually updatable is missing. Solution for 5.5 and 5.6: ------------------------- For a view whose column-list in specified in the LOAD command, this check is not performed. This fix adds the check. This is a partial backport of Bug#21097485. Solution for 5.7 and trunk: --------------------------- For a view whose column-list is specified in the LOAD command, this check is already performed. This fix adds the same check when no column-list is specified.
1 parent d8a7b4d commit 30a59a8

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

mysql-test/r/loaddata.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ FIELDS ESCAPED BY '\\'
316316
TERMINATED BY ','
317317
ENCLOSED BY '"'
318318
LINES TERMINATED BY '\n' (c0, c2);
319-
ERROR HY000: Invalid column reference (v2.c0) in LOAD DATA
319+
ERROR HY000: Column 'c0' is not updatable
320320

321321
LOAD DATA INFILE '../../std_data/bug35469.dat' INTO TABLE v3
322322
FIELDS ESCAPED BY '\\'

mysql-test/t/loaddata.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ SELECT * FROM v2;
292292
DELETE FROM t1;
293293

294294
--echo
295-
--error ER_LOAD_DATA_INVALID_COLUMN
295+
--error ER_NONUPDATEABLE_COLUMN
296296
LOAD DATA INFILE '../../std_data/bug35469.dat' INTO TABLE v2
297297
FIELDS ESCAPED BY '\\'
298298
TERMINATED BY ','

sql/sql_load.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,24 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
296296
setup_fields(thd, 0, set_fields, MARK_COLUMNS_WRITE, 0, 0) ||
297297
check_that_all_fields_are_given_values(thd, table, table_list))
298298
DBUG_RETURN(TRUE);
299+
300+
/*
301+
Special updatability test is needed because fields_vars may contain
302+
a mix of column references and user variables.
303+
*/
304+
Item *item;
305+
List_iterator<Item> it(fields_vars);
306+
while ((item= it++))
307+
{
308+
if ((item->type() == Item::FIELD_ITEM ||
309+
item->type() == Item::REF_ITEM) &&
310+
item->filed_for_view_update() == NULL)
311+
{
312+
my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), item->name);
313+
DBUG_RETURN(true);
314+
}
315+
}
316+
299317
/*
300318
Check whenever TIMESTAMP field with auto-set feature specified
301319
explicitly.

0 commit comments

Comments
 (0)