Commit b0b75bbf authored by unknown's avatar unknown

fixed quoting of identifiers in VIEWs (BUG#4613)


mysql-test/r/view.result:
  fixed quoting of identifiers in VIEWs
mysql-test/t/view.test:
  fixed quoting of identifiers in VIEWs
sql/item.cc:
  fixed quoting of identifiers in VIEWs
sql/sql_select.cc:
  fixed quoting of identifiers in VIEWs
sql/sql_view.cc:
  fixed quoting of identifiers in VIEWs
parent 9050c44c
drop table if exists t1,t2,v1,v2,v3,v4,v5,v6; drop table if exists t1,t2,`t1a``b`,v1,v2,v3,v4,v5,v6;
drop view if exists t1,t2,v1,v2,v3,v4,v5,v6; drop view if exists t1,t2,`t1a``b`,v1,v2,v3,v4,v5,v6;
drop database if exists mysqltest; drop database if exists mysqltest;
use test; use test;
create view v1 (c,d) as select a,b from t1; create view v1 (c,d) as select a,b from t1;
...@@ -956,3 +956,12 @@ select * from v1, t1; ...@@ -956,3 +956,12 @@ select * from v1, t1;
a t_column a t_column
drop view v1; drop view v1;
drop table t1; drop table t1;
create table `t1a``b` (col1 char(2));
create view v1 as select * from `t1a``b`;
select * from v1;
col1
describe v1;
Field Type Null Key Default Extra
col1 char(2) YES NULL
drop view v1;
drop table `t1a``b`;
--disable_warnings --disable_warnings
drop table if exists t1,t2,v1,v2,v3,v4,v5,v6; drop table if exists t1,t2,`t1a``b`,v1,v2,v3,v4,v5,v6;
drop view if exists t1,t2,v1,v2,v3,v4,v5,v6; drop view if exists t1,t2,`t1a``b`,v1,v2,v3,v4,v5,v6;
drop database if exists mysqltest; drop database if exists mysqltest;
--enable_warnings --enable_warnings
use test; use test;
...@@ -870,3 +870,13 @@ create view v1 as select 'a'; ...@@ -870,3 +870,13 @@ create view v1 as select 'a';
select * from v1, t1; select * from v1, t1;
drop view v1; drop view v1;
drop table t1; drop table t1;
#
# quote mark inside table name
#
create table `t1a``b` (col1 char(2));
create view v1 as select * from `t1a``b`;
select * from v1;
describe v1;
drop view v1;
drop table `t1a``b`;
...@@ -98,9 +98,9 @@ void Item::print_item_w_name(String *str) ...@@ -98,9 +98,9 @@ void Item::print_item_w_name(String *str)
print(str); print(str);
if (name) if (name)
{ {
str->append(" AS `", 5); THD *thd= current_thd;
str->append(name); str->append(" AS ", 4);
str->append('`'); append_identifier(thd, str, name, strlen(name));
} }
} }
...@@ -420,33 +420,32 @@ const char *Item_ident::full_name() const ...@@ -420,33 +420,32 @@ const char *Item_ident::full_name() const
void Item_ident::print(String *str) void Item_ident::print(String *str)
{ {
str->append('`'); THD *thd= current_thd;
if (!table_name || !field_name) if (!table_name || !field_name)
{ {
str->append(field_name ? field_name : name ? name : "tmp_field"); const char *nm= field_name ? field_name : name ? name : "tmp_field";
str->append('`'); append_identifier(thd, str, nm, strlen(nm));
return; return;
} }
if (db_name && db_name[0]) if (db_name && db_name[0])
{ {
str->append(db_name); append_identifier(thd, str, db_name, strlen(db_name));
str->append("`.`", 3); str->append('.');
str->append(table_name); append_identifier(thd, str, table_name, strlen(table_name));
str->append("`.`", 3); str->append('.');
str->append(field_name); append_identifier(thd, str, field_name, strlen(field_name));
} }
else else
{ {
if (table_name[0]) if (table_name[0])
{ {
str->append(table_name); append_identifier(thd, str, table_name, strlen(table_name));
str->append("`.`", 3); str->append('.');
str->append(field_name); append_identifier(thd, str, field_name, strlen(field_name));
} }
else else
str->append(field_name); append_identifier(thd, str, field_name, strlen(field_name));
} }
str->append('`');
} }
/* ARGSUSED */ /* ARGSUSED */
......
...@@ -11250,37 +11250,32 @@ void st_table_list::print(THD *thd, String *str) ...@@ -11250,37 +11250,32 @@ void st_table_list::print(THD *thd, String *str)
} }
else if (view_name.str) else if (view_name.str)
{ {
str->append('`'); append_identifier(thd, str, view_db.str, view_db.length);
str->append(view_db.str, view_db.length); str->append('.');
str->append("`.`", 3); append_identifier(thd, str, view_name.str, view_name.length);
str->append(view_name.str, view_name.length);
if (my_strcasecmp(table_alias_charset, view_name.str, alias)) if (my_strcasecmp(table_alias_charset, view_name.str, alias))
{ {
str->append("` `", 3); str->append(' ');
str->append(alias); append_identifier(thd, str, alias, strlen(alias));
} }
str->append('`');
} }
else if (derived) else if (derived)
{ {
str->append('('); str->append('(');
derived->print(str); derived->print(str);
str->append(") `", 3); str->append(") ", 2);
str->append(alias); append_identifier(thd, str, alias, strlen(alias));
str->append('`');
} }
else else
{ {
str->append('`'); append_identifier(thd, str, db, db_length);
str->append(db); str->append('.');
str->append("`.`", 3); append_identifier(thd, str, real_name, real_name_length);
str->append(real_name);
if (my_strcasecmp(table_alias_charset, real_name, alias)) if (my_strcasecmp(table_alias_charset, real_name, alias))
{ {
str->append("` `", 3); str->append(' ');
str->append(alias); append_identifier(thd, str, alias, strlen(alias));
} }
str->append('`');
} }
} }
......
...@@ -356,7 +356,12 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, ...@@ -356,7 +356,12 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
// print query // print query
str.length(0); str.length(0);
{
ulong sql_mode= thd->variables.sql_mode & MODE_ANSI_QUOTES;
thd->variables.sql_mode&= ~MODE_ANSI_QUOTES;
thd->lex->unit.print(&str); thd->lex->unit.print(&str);
thd->variables.sql_mode|= sql_mode;
}
str.append('\0'); str.append('\0');
DBUG_PRINT("VIEW", ("View: %s", str.ptr())); DBUG_PRINT("VIEW", ("View: %s", str.ptr()));
......
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