Commit 239cdc27 authored by unknown's avatar unknown

Merge sanja.is.com.ua:/home/bell/mysql/bk/mysql-5.0

into sanja.is.com.ua:/home/bell/mysql/bk/work-error-5.0


sql/item.cc:
  Auto merged
sql/item.h:
  Auto merged
sql/sql_lex.cc:
  Auto merged
sql/sql_lex.h:
  Auto merged
sql/table.h:
  Auto merged
parents a806cba3 c774eb0e
...@@ -22,3 +22,19 @@ insert into v2aA values ((select max(col1) from v1aA)); ...@@ -22,3 +22,19 @@ insert into v2aA values ((select max(col1) from v1aA));
ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause
drop view v2Aa,v1Aa; drop view v2Aa,v1Aa;
drop table t1Aa,t2Aa; drop table t1Aa,t2Aa;
create table t1Aa (col1 int);
create view v1Aa as select col1 from t1Aa as AaA;
show create view v1AA;
View Create View
v1aa CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1aa` AS select `aaa`.`col1` AS `col1` from `test`.`t1aa` `AaA`
drop view v1AA;
select Aaa.col1 from t1Aa as AaA;
col1
create view v1Aa as select Aaa.col1 from t1Aa as AaA;
drop view v1AA;
create view v1Aa as select AaA.col1 from t1Aa as AaA;
show create view v1AA;
View Create View
v1aa CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1aa` AS select `aaa`.`col1` AS `col1` from `test`.`t1aa` `AaA`
drop view v1AA;
drop table t1Aa;
...@@ -32,3 +32,18 @@ delete from v2aA where col1 = (select max(col1) from v1aA); ...@@ -32,3 +32,18 @@ delete from v2aA where col1 = (select max(col1) from v1aA);
insert into v2aA values ((select max(col1) from v1aA)); insert into v2aA values ((select max(col1) from v1aA));
drop view v2Aa,v1Aa; drop view v2Aa,v1Aa;
drop table t1Aa,t2Aa; drop table t1Aa,t2Aa;
#
# aliases in VIEWs
#
create table t1Aa (col1 int);
create view v1Aa as select col1 from t1Aa as AaA;
show create view v1AA;
drop view v1AA;
select Aaa.col1 from t1Aa as AaA;
create view v1Aa as select Aaa.col1 from t1Aa as AaA;
drop view v1AA;
create view v1Aa as select AaA.col1 from t1Aa as AaA;
show create view v1AA;
drop view v1AA;
drop table t1Aa;
...@@ -138,7 +138,7 @@ bool Item::cleanup_processor(byte *arg) ...@@ -138,7 +138,7 @@ bool Item::cleanup_processor(byte *arg)
Item_ident::Item_ident(const char *db_name_par,const char *table_name_par, Item_ident::Item_ident(const char *db_name_par,const char *table_name_par,
const char *field_name_par) const char *field_name_par)
:orig_db_name(db_name_par), orig_table_name(table_name_par), :orig_db_name(db_name_par), orig_table_name(table_name_par),
orig_field_name(field_name_par), orig_field_name(field_name_par), alias_name_used(FALSE),
db_name(db_name_par), table_name(table_name_par), db_name(db_name_par), table_name(table_name_par),
field_name(field_name_par), cached_field_index(NO_CACHED_FIELD_INDEX), field_name(field_name_par), cached_field_index(NO_CACHED_FIELD_INDEX),
cached_table(0), depended_from(0) cached_table(0), depended_from(0)
...@@ -152,6 +152,7 @@ Item_ident::Item_ident(THD *thd, Item_ident *item) ...@@ -152,6 +152,7 @@ Item_ident::Item_ident(THD *thd, Item_ident *item)
orig_db_name(item->orig_db_name), orig_db_name(item->orig_db_name),
orig_table_name(item->orig_table_name), orig_table_name(item->orig_table_name),
orig_field_name(item->orig_field_name), orig_field_name(item->orig_field_name),
alias_name_used(item->alias_name_used),
db_name(item->db_name), db_name(item->db_name),
table_name(item->table_name), table_name(item->table_name),
field_name(item->field_name), field_name(item->field_name),
...@@ -609,6 +610,7 @@ void Item_field::set_field(Field *field_par) ...@@ -609,6 +610,7 @@ void Item_field::set_field(Field *field_par)
table_name=field_par->table_name; table_name=field_par->table_name;
field_name=field_par->field_name; field_name=field_par->field_name;
db_name=field_par->table->table_cache_key; db_name=field_par->table->table_cache_key;
alias_name_used= field_par->table->alias_name_used;
unsigned_flag=test(field_par->flags & UNSIGNED_FLAG); unsigned_flag=test(field_par->flags & UNSIGNED_FLAG);
collation.set(field_par->charset(), DERIVATION_IMPLICIT); collation.set(field_par->charset(), DERIVATION_IMPLICIT);
fixed= 1; fixed= 1;
...@@ -658,7 +660,8 @@ void Item_ident::print(String *str) ...@@ -658,7 +660,8 @@ void Item_ident::print(String *str)
THD *thd= current_thd; THD *thd= current_thd;
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME]; char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
const char *d_name= db_name, *t_name= table_name; const char *d_name= db_name, *t_name= table_name;
if (lower_case_table_names) if (lower_case_table_names== 1 ||
(lower_case_table_names == 2 && !alias_name_used))
{ {
if (table_name && table_name[0]) if (table_name && table_name[0])
{ {
...@@ -680,7 +683,7 @@ void Item_ident::print(String *str) ...@@ -680,7 +683,7 @@ void Item_ident::print(String *str)
append_identifier(thd, str, nm, strlen(nm)); append_identifier(thd, str, nm, strlen(nm));
return; return;
} }
if (db_name && db_name[0]) if (db_name && db_name[0] && !alias_name_used)
{ {
append_identifier(thd, str, d_name, strlen(d_name)); append_identifier(thd, str, d_name, strlen(d_name));
str->append('.'); str->append('.');
...@@ -2937,6 +2940,10 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) ...@@ -2937,6 +2940,10 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference)
decimals= (*ref)->decimals; decimals= (*ref)->decimals;
collation.set((*ref)->collation); collation.set((*ref)->collation);
with_sum_func= (*ref)->with_sum_func; with_sum_func= (*ref)->with_sum_func;
if ((*ref)->type() == FIELD_ITEM)
alias_name_used= ((Item_ident *) (*ref))->alias_name_used;
else
alias_name_used= TRUE; // it is not field, so it is was resolved by alias
fixed= 1; fixed= 1;
if (ref && (*ref)->check_cols(1)) if (ref && (*ref)->check_cols(1))
......
...@@ -467,6 +467,7 @@ class Item_ident :public Item ...@@ -467,6 +467,7 @@ class Item_ident :public Item
const char *db_name; const char *db_name;
const char *table_name; const char *table_name;
const char *field_name; const char *field_name;
bool alias_name_used; /* true if item was resolved against alias */
/* /*
Cached value of index for this field in table->field array, used by prep. Cached value of index for this field in table->field array, used by prep.
stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX
......
...@@ -1050,8 +1050,11 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, ...@@ -1050,8 +1050,11 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
table->reginfo.lock_type=TL_READ; /* Assume read */ table->reginfo.lock_type=TL_READ; /* Assume read */
reset: reset:
if (thd->lex->need_correct_ident())
table->alias_name_used= my_strcasecmp(table_alias_charset,
table->real_name, alias);
/* Fix alias if table name changes */ /* Fix alias if table name changes */
if (strcmp(table->table_name,alias)) if (strcmp(table->table_name, alias))
{ {
uint length=(uint) strlen(alias)+1; uint length=(uint) strlen(alias)+1;
table->table_name= (char*) my_realloc(table->table_name,length, table->table_name= (char*) my_realloc(table->table_name,length,
......
...@@ -1723,6 +1723,7 @@ bool st_lex::can_not_use_merged() ...@@ -1723,6 +1723,7 @@ bool st_lex::can_not_use_merged()
TRUE yes, we need only structure TRUE yes, we need only structure
FALSE no, we need data FALSE no, we need data
*/ */
bool st_lex::only_view_structure() bool st_lex::only_view_structure()
{ {
switch(sql_command) switch(sql_command)
...@@ -1741,6 +1742,32 @@ bool st_lex::only_view_structure() ...@@ -1741,6 +1742,32 @@ bool st_lex::only_view_structure()
} }
/*
Should Items_ident be printed correctly
SYNOPSIS
need_correct_ident()
RETURN
TRUE yes, we need only structure
FALSE no, we need data
*/
bool st_lex::need_correct_ident()
{
switch(sql_command)
{
case SQLCOM_SHOW_CREATE:
case SQLCOM_SHOW_TABLES:
case SQLCOM_CREATE_VIEW:
return TRUE;
default:
return FALSE;
}
}
/* /*
initialize limit counters initialize limit counters
......
...@@ -802,6 +802,7 @@ typedef struct st_lex ...@@ -802,6 +802,7 @@ typedef struct st_lex
bool can_use_merged(); bool can_use_merged();
bool can_not_use_merged(); bool can_not_use_merged();
bool only_view_structure(); bool only_view_structure();
bool need_correct_ident();
} LEX; } LEX;
extern TABLE_LIST fake_time_zone_tables_list; extern TABLE_LIST fake_time_zone_tables_list;
......
...@@ -160,6 +160,7 @@ struct st_table { ...@@ -160,6 +160,7 @@ struct st_table {
my_bool no_keyread, no_cache; my_bool no_keyread, no_cache;
my_bool clear_query_id; /* To reset query_id for tables and cols */ my_bool clear_query_id; /* To reset query_id for tables and cols */
my_bool auto_increment_field_not_null; my_bool auto_increment_field_not_null;
my_bool alias_name_used; /* true if table_name is alias */
Field *next_number_field, /* Set if next_number is activated */ Field *next_number_field, /* Set if next_number is activated */
*found_next_number_field, /* Set on open */ *found_next_number_field, /* Set on open */
*rowid_field; *rowid_field;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment