summaryrefslogtreecommitdiff
path: root/sql/sql_update.cc
diff options
context:
space:
mode:
authorbell@sanja.is.com.ua <>2004-01-04 23:44:33 +0200
committerbell@sanja.is.com.ua <>2004-01-04 23:44:33 +0200
commit501ae0bc5255fd0a3fa557c7af189f4f4c487469 (patch)
tree198037221b84d6cf0f9081cad662a648b171c5a6 /sql/sql_update.cc
parent7bb74b6592583656512571e4af1b04d36849d020 (diff)
downloadmariadb-git-501ae0bc5255fd0a3fa557c7af189f4f4c487469.tar.gz
allow UPDATE and DELETE stetements with tables derived from subquery if they are not updated (BUG#2117)
allow delete table by alias in multi-delete statement
Diffstat (limited to 'sql/sql_update.cc')
-rw-r--r--sql/sql_update.cc37
1 files changed, 36 insertions, 1 deletions
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index cdea32ad3f6..87421c482d5 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -434,13 +434,36 @@ int mysql_multi_update(THD *thd,
fix_tables_pointers(thd->lex->all_selects_list);
select_lex->select_limit= HA_POS_ERROR;
+
+ table_map item_tables= 0, derived_tables= 0;
+ if (thd->lex->derived_tables)
+ {
+ // Assign table map values to check updatability of derived tables
+ uint tablenr=0;
+ for (TABLE_LIST *table_list= (TABLE_LIST*) select_lex->table_list.first;
+ table_list;
+ table_list= table_list->next, tablenr++)
+ {
+ table_list->table->map= (table_map) 1 << tablenr;
+ }
+ }
if (setup_fields(thd, 0, table_list, *fields, 1, 0, 0))
DBUG_RETURN(-1);
+ if (thd->lex->derived_tables)
+ {
+ // Find tables used in items
+ List_iterator_fast<Item> it(*fields);
+ Item *item;
+ while ((item= it++))
+ {
+ item_tables|= item->used_tables();
+ }
+ }
/*
Count tables and setup timestamp handling
*/
- for (tl= select_lex->get_table_list() ; tl ; tl=tl->next)
+ for (tl= select_lex->get_table_list() ; tl ; tl= tl->next)
{
TABLE *table= tl->table;
if (table->timestamp_field)
@@ -450,6 +473,18 @@ int mysql_multi_update(THD *thd,
if (table->timestamp_field->query_id != thd->query_id)
table->time_stamp= table->timestamp_field->offset() +1;
}
+ if (tl->derived)
+ derived_tables|= table->map;
+ }
+ if (thd->lex->derived_tables && (item_tables & derived_tables))
+ {
+ // find derived table which cause error
+ for (tl= select_lex->get_table_list() ; tl ; tl= tl->next)
+ {
+ if (tl->derived && (item_tables & tl->table->map))
+ my_printf_error(ER_NON_UPDATABLE_TABLE, ER(ER_NON_UPDATABLE_TABLE),
+ MYF(0), tl->alias, "UPDATE");
+ }
}
if (!(result=new multi_update(thd, table_list, fields, values,