Commit 7a6f5cf1 authored by unknown's avatar unknown

Item name for VIEW added to find_field_in_table (BUG#5147)


mysql-test/r/view.result:
  VIEW of VIEW with column renaming
mysql-test/t/view.test:
  VIEW of VIEW with column renaming
sql/mysql_priv.h:
  Item name for VIEW added to find_field_in_table
sql/sql_acl.cc:
  new parameter
sql/sql_base.cc:
  Item name for VIEW added to find_field_in_table
parent 3b8c2da8
......@@ -1151,3 +1151,18 @@ avg(vg_column)
0.0000
drop view v1;
drop table t1;
create table t1 (col1 bigint not null, primary key (col1));
create table t2 (col1 bigint not null, key (col1));
create view v1 as select * from t1;
create view v2 as select * from t2;
insert into v1 values (1);
insert into v2 values (1);
create view v3 (a,b) as select v1.col1 as a, v2.col1 as b from v1, v2 where v1.col1 = v2.col1;
select * from v3;
a b
1 1
show create view v3;
Table Create Table
v3 CREATE VIEW `test`.`v3` AS select `v1`.`col1` AS `a`,`v2`.`col1` AS `b` from `test`.`v1` join `test`.`v2` where (`v1`.`col1` = `v2`.`col1`)
drop view v3, v2, v1;
drop table t2, t1;
......@@ -1091,3 +1091,18 @@ create view v1 as select count(tg_column) as vg_column from t1;
select avg(vg_column) from v1;
drop view v1;
drop table t1;
#
# VIEW of VIEW with column renaming
#
create table t1 (col1 bigint not null, primary key (col1));
create table t2 (col1 bigint not null, key (col1));
create view v1 as select * from t1;
create view v2 as select * from t2;
insert into v1 values (1);
insert into v2 values (1);
create view v3 (a,b) as select v1.col1 as a, v2.col1 as b from v1, v2 where v1.col1 = v2.col1;
select * from v3;
show create view v3;
drop view v3, v2, v1;
drop table t2, t1;
......@@ -632,9 +632,11 @@ extern const Field *view_ref_found;
Field *find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
Item **ref, bool report_error,
bool check_privileges);
Field *find_field_in_table(THD *thd, TABLE_LIST *tables, const char *name,
Field *
find_field_in_table(THD *thd, TABLE_LIST *table_list,
const char *name, const char *item_name,
uint length, Item **ref,
bool check_grant_table, bool check_grant_view,
bool check_grants_table, bool check_grants_view,
bool allow_rowid,
uint *cached_field_index_ptr);
#ifdef HAVE_OPENSSL
......
......@@ -2310,6 +2310,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
{
uint unused_field_idx= NO_CACHED_FIELD_INDEX;
if (!find_field_in_table(thd, table_list, column->column.ptr(),
column->column.ptr(),
column->column.length(), 0, 0, 0, 0,
&unused_field_idx))
{
......
......@@ -1924,6 +1924,7 @@ const Field *view_ref_found= (Field*) 0x2;
thd thread handler
table_list table where to find
name name of field
item_name name of item if it will be created (VIEW)
length length of name
ref expression substituted in VIEW should be
passed using this reference (return
......@@ -1940,8 +1941,10 @@ const Field *view_ref_found= (Field*) 0x2;
# pointer to field
*/
Field *find_field_in_table(THD *thd, TABLE_LIST *table_list,
const char *name, uint length, Item **ref,
Field *
find_field_in_table(THD *thd, TABLE_LIST *table_list,
const char *name, const char *item_name,
uint length, Item **ref,
bool check_grants_table, bool check_grants_view,
bool allow_rowid,
uint *cached_field_index_ptr)
......@@ -1972,7 +1975,7 @@ Field *find_field_in_table(THD *thd, TABLE_LIST *table_list,
if (arena)
thd->set_n_backup_item_arena(arena, &backup);
*ref= new Item_ref(trans + i, 0, table_list->view_name.str,
name);
item_name);
if (arena)
thd->restore_backup_item_arena(arena, &backup);
/* as far as Item_ref have defined refernce it do not need tables */
......@@ -2163,7 +2166,8 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
(!db || !tables->db || !tables->db[0] || !strcmp(db,tables->db)))
{
found_table=1;
Field *find= find_field_in_table(thd, tables, name, length, ref,
Field *find= find_field_in_table(thd, tables, name, item->name,
length, ref,
(test(tables->table->grant.
want_privilege) &&
check_privileges),
......@@ -2226,7 +2230,8 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
return (Field*) not_found_field;
}
Field *field= find_field_in_table(thd, tables, name, length, ref,
Field *field= find_field_in_table(thd, tables, name, item->name,
length, ref,
(test(tables->table->grant.
want_privilege) &&
check_privileges),
......@@ -2684,6 +2689,7 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name,
/* Skip duplicate field names if NATURAL JOIN is used */
if (!natural_join_table ||
!find_field_in_table(thd, natural_join_table, field_name,
field_name,
strlen(field_name), &not_used_item, 0, 0, 0,
&not_used_field_index))
{
......@@ -2890,6 +2896,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
uint not_used_field_index= NO_CACHED_FIELD_INDEX;
if ((t2_field= find_field_in_table(thd, tab2, t1_field_name,
t1_field_name,
strlen(t1_field_name), &item_t2,
0, 0, 0,
&not_used_field_index)))
......
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