mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Fix check of view updatability in case of underlying view changes its updatability.
For single table update/insert added deep check of single tables (single_table_updatable()). For multi-table view insert added additional check of target table (check_view_single_update). Multi-update was correct. Test suite for all cases added.
This commit is contained in:
@@ -103,7 +103,8 @@ static bool check_view_insertability(THD *thd, TABLE_LIST *view);
|
||||
*/
|
||||
|
||||
bool check_view_single_update(List<Item> &fields, List<Item> *values,
|
||||
TABLE_LIST *view, table_map *map)
|
||||
TABLE_LIST *view, table_map *map,
|
||||
bool insert)
|
||||
{
|
||||
/* it is join view => we need to find the table for update */
|
||||
List_iterator_fast<Item> it(fields);
|
||||
@@ -135,6 +136,14 @@ bool check_view_single_update(List<Item> &fields, List<Item> *values,
|
||||
goto error;
|
||||
|
||||
view->table= tbl->table;
|
||||
if (!tbl->single_table_updatable())
|
||||
{
|
||||
if (insert)
|
||||
my_error(ER_NON_INSERTABLE_TABLE, MYF(0), view->alias, "INSERT");
|
||||
else
|
||||
my_error(ER_NON_UPDATABLE_TABLE, MYF(0), view->alias, "UPDATE");
|
||||
return TRUE;
|
||||
}
|
||||
*map= tables;
|
||||
|
||||
return FALSE;
|
||||
@@ -179,7 +188,7 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list,
|
||||
{
|
||||
TABLE *table= table_list->table;
|
||||
|
||||
if (!table_list->updatable)
|
||||
if (!table_list->single_table_updatable())
|
||||
{
|
||||
my_error(ER_NON_INSERTABLE_TABLE, MYF(0), table_list->alias, "INSERT");
|
||||
return -1;
|
||||
@@ -251,7 +260,7 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list,
|
||||
if (check_view_single_update(fields,
|
||||
fields_and_values_from_different_maps ?
|
||||
(List<Item>*) 0 : &values,
|
||||
table_list, map))
|
||||
table_list, map, true))
|
||||
return -1;
|
||||
table= table_list->table;
|
||||
}
|
||||
@@ -337,7 +346,7 @@ static int check_update_fields(THD *thd, TABLE_LIST *insert_table_list,
|
||||
|
||||
if (insert_table_list->effective_algorithm == VIEW_ALGORITHM_MERGE &&
|
||||
check_view_single_update(update_fields, &update_values,
|
||||
insert_table_list, map))
|
||||
insert_table_list, map, false))
|
||||
return -1;
|
||||
|
||||
if (table->timestamp_field)
|
||||
|
Reference in New Issue
Block a user