diff options
author | unknown <evgen@moonbone.local> | 2005-08-15 13:21:55 +0400 |
---|---|---|
committer | unknown <evgen@moonbone.local> | 2005-08-15 13:21:55 +0400 |
commit | 6ed4935212ce5a3e8824ad25a9eb6718e2703537 (patch) | |
tree | 7562b2623c103e6a4bd19999af2883e2b61d8b76 /sql | |
parent | 7b91cd9a5866106d8f8c39c03302a59ea18b30ee (diff) | |
parent | e66cd71698e033c788adb6364fdf261143fb5601 (diff) | |
download | mariadb-git-6ed4935212ce5a3e8824ad25a9eb6718e2703537.tar.gz |
Merge epotemkin@bk-internal.mysql.com:/home/bk/mysql-5.0
into moonbone.local:/work/mysql-5.0-bug-11864
mysql-test/r/derived.result:
Auto merged
sql/sql_derived.cc:
Auto merged
sql/sql_view.cc:
Auto merged
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_derived.cc | 5 | ||||
-rw-r--r-- | sql/sql_view.cc | 96 | ||||
-rw-r--r-- | sql/sql_view.h | 2 |
3 files changed, 74 insertions, 29 deletions
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index afcf7dbd93f..da1525fc133 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -125,6 +125,11 @@ int mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *orig_table_list) if ((res= unit->prepare(thd, derived_result, 0, orig_table_list->alias))) goto exit; + if (check_duplicate_names(unit->types, 0)) + { + res= -1; + goto exit; + } derived_result->tmp_table_param.init(); derived_result->tmp_table_param.field_count= unit->types.elements; diff --git a/sql/sql_view.cc b/sql/sql_view.cc index c958185b622..c3222f951bb 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -94,6 +94,71 @@ static void make_unique_view_field_name(Item *target, target->set_name(buff, name_len, system_charset_info); } + +/* + Check if items with same names are present in list and possibly + generate unique names for them. + + SYNOPSIS + item_list list of Items which should be checked for duplicates + gen_unique_view_name flag: generate unique name or return with error when + duplicate names are found. + + DESCRIPTION + This function is used on view creation and preparation of derived tables. + It checks item_list for items with duplicate names. If it founds two + items with same name and conversion to unique names isn't allowed, or + names for both items are set by user - function fails. + Otherwise it generates unique name for one item with autogenerated name + using make_unique_view_field_name() + + RETURN VALUE + FALSE no duplicate names found, or they are converted to unique ones + TRUE duplicate names are found and they can't be converted or conversion + isn't allowed +*/ + +bool check_duplicate_names(List<Item> &item_list, bool gen_unique_view_name) +{ + DBUG_ENTER("check_duplicate_names"); + /* Test absence of duplicates names */ + { + Item *item; + List_iterator_fast<Item> it(item_list); + List_iterator_fast<Item> itc(item_list); + while ((item= it++)) + { + Item *check; + /* treat underlying fields like set by user names */ + if (item->real_item()->type() == Item::FIELD_ITEM) + item->is_autogenerated_name= FALSE; + itc.rewind(); + while ((check= itc++) && check != item) + { + if (my_strcasecmp(system_charset_info, item->name, check->name) == 0) + { + if (!gen_unique_view_name) + { + my_error(ER_DUP_FIELDNAME, MYF(0), item->name); + DBUG_RETURN(TRUE); + } + else if (item->is_autogenerated_name) + make_unique_view_field_name(item, item_list, item); + else if (check->is_autogenerated_name) + make_unique_view_field_name(check, item_list, item); + else + { + my_error(ER_DUP_FIELDNAME, MYF(0), item->name); + DBUG_RETURN(TRUE); + } + } + } + } + } + DBUG_RETURN(FALSE); +} + + /* Creating/altering VIEW procedure @@ -308,35 +373,8 @@ bool mysql_create_view(THD *thd, } } - /* Test absence of duplicates names */ - { - Item *item; - List_iterator_fast<Item> it(select_lex->item_list); - List_iterator_fast<Item> itc(select_lex->item_list); - while ((item= it++)) - { - Item *check; - /* treat underlying fields like set by user names */ - if (item->real_item()->type() == Item::FIELD_ITEM) - item->is_autogenerated_name= FALSE; - itc.rewind(); - while ((check= itc++) && check != item) - { - if (my_strcasecmp(system_charset_info, item->name, check->name) == 0) - { - if (item->is_autogenerated_name) - make_unique_view_field_name(item, select_lex->item_list, item); - else if (check->is_autogenerated_name) - make_unique_view_field_name(check, select_lex->item_list, item); - else - { - my_error(ER_DUP_FIELDNAME, MYF(0), item->name); - DBUG_RETURN(TRUE); - } - } - } - } - } + if (check_duplicate_names(select_lex->item_list, 1)) + DBUG_RETURN(TRUE); #ifndef NO_EMBEDDED_ACCESS_CHECKS /* diff --git a/sql/sql_view.h b/sql/sql_view.h index 3246dbae383..9d961feb143 100644 --- a/sql/sql_view.h +++ b/sql/sql_view.h @@ -33,5 +33,7 @@ int view_checksum(THD *thd, TABLE_LIST *view); extern TYPELIB updatable_views_with_limit_typelib; +bool check_duplicate_names(List<Item>& item_list, bool gen_unique_view_names); + #define VIEW_ANY_ACL (SELECT_ACL | UPDATE_ACL | INSERT_ACL | DELETE_ACL) |