diff options
Diffstat (limited to 'sql/sql_view.cc')
-rw-r--r-- | sql/sql_view.cc | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/sql/sql_view.cc b/sql/sql_view.cc index e1e0b3ff6c4..b9379d8898f 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -155,6 +155,35 @@ err: DBUG_RETURN(TRUE); } + +/** + Check if auto generated column names are conforming and + possibly generate a conforming name for them if not. + + @param item_list List of Items which should be checked +*/ + +static void make_valid_column_names(List<Item> &item_list) +{ + Item *item; + uint name_len; + List_iterator_fast<Item> it(item_list); + char buff[NAME_LEN]; + DBUG_ENTER("make_valid_column_names"); + + for (uint column_no= 1; (item= it++); column_no++) + { + if (!item->is_autogenerated_name || !check_column_name(item->name)) + continue; + name_len= my_snprintf(buff, NAME_LEN, "Name_exp_%u", column_no); + item->orig_name= item->name; + item->set_name(buff, name_len, system_charset_info); + } + + DBUG_VOID_RETURN; +} + + /* Fill defined view parts @@ -400,17 +429,14 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, DBUG_ASSERT(!lex->proc_list.first && !lex->result && !lex->param_list.elements); - if (mode != VIEW_CREATE_NEW) + if (mode == VIEW_ALTER && fill_defined_view_parts(thd, view)) { - if (mode == VIEW_ALTER && - fill_defined_view_parts(thd, view)) - { - res= TRUE; - goto err; - } - sp_cache_invalidate(); + res= TRUE; + goto err; } + sp_cache_invalidate(); + if (!lex->definer) { /* @@ -551,6 +577,9 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, } } + /* Check if the auto generated column names are conforming. */ + make_valid_column_names(select_lex->item_list); + if (check_duplicate_names(select_lex->item_list, 1)) { res= TRUE; |