mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
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
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
drop table if exists t1,t2,v1,v2,v3,v4,v5,v6;
|
||||
drop view 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,`t1a``b`,v1,v2,v3,v4,v5,v6;
|
||||
drop database if exists mysqltest;
|
||||
use test;
|
||||
create view v1 (c,d) as select a,b from t1;
|
||||
@ -956,3 +956,12 @@ select * from v1, t1;
|
||||
a t_column
|
||||
drop view v1;
|
||||
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`;
|
||||
|
@ -1,6 +1,6 @@
|
||||
--disable_warnings
|
||||
drop table if exists t1,t2,v1,v2,v3,v4,v5,v6;
|
||||
drop view 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,`t1a``b`,v1,v2,v3,v4,v5,v6;
|
||||
drop database if exists mysqltest;
|
||||
--enable_warnings
|
||||
use test;
|
||||
@ -870,3 +870,13 @@ create view v1 as select 'a';
|
||||
select * from v1, t1;
|
||||
drop view v1;
|
||||
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`;
|
||||
|
31
sql/item.cc
31
sql/item.cc
@ -98,9 +98,9 @@ void Item::print_item_w_name(String *str)
|
||||
print(str);
|
||||
if (name)
|
||||
{
|
||||
str->append(" AS `", 5);
|
||||
str->append(name);
|
||||
str->append('`');
|
||||
THD *thd= current_thd;
|
||||
str->append(" AS ", 4);
|
||||
append_identifier(thd, str, name, strlen(name));
|
||||
}
|
||||
}
|
||||
|
||||
@ -420,33 +420,32 @@ const char *Item_ident::full_name() const
|
||||
|
||||
void Item_ident::print(String *str)
|
||||
{
|
||||
str->append('`');
|
||||
THD *thd= current_thd;
|
||||
if (!table_name || !field_name)
|
||||
{
|
||||
str->append(field_name ? field_name : name ? name : "tmp_field");
|
||||
str->append('`');
|
||||
const char *nm= field_name ? field_name : name ? name : "tmp_field";
|
||||
append_identifier(thd, str, nm, strlen(nm));
|
||||
return;
|
||||
}
|
||||
if (db_name && db_name[0])
|
||||
{
|
||||
str->append(db_name);
|
||||
str->append("`.`", 3);
|
||||
str->append(table_name);
|
||||
str->append("`.`", 3);
|
||||
str->append(field_name);
|
||||
append_identifier(thd, str, db_name, strlen(db_name));
|
||||
str->append('.');
|
||||
append_identifier(thd, str, table_name, strlen(table_name));
|
||||
str->append('.');
|
||||
append_identifier(thd, str, field_name, strlen(field_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (table_name[0])
|
||||
{
|
||||
str->append(table_name);
|
||||
str->append("`.`", 3);
|
||||
str->append(field_name);
|
||||
append_identifier(thd, str, table_name, strlen(table_name));
|
||||
str->append('.');
|
||||
append_identifier(thd, str, field_name, strlen(field_name));
|
||||
}
|
||||
else
|
||||
str->append(field_name);
|
||||
append_identifier(thd, str, field_name, strlen(field_name));
|
||||
}
|
||||
str->append('`');
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
|
@ -11250,37 +11250,32 @@ void st_table_list::print(THD *thd, String *str)
|
||||
}
|
||||
else if (view_name.str)
|
||||
{
|
||||
str->append('`');
|
||||
str->append(view_db.str, view_db.length);
|
||||
str->append("`.`", 3);
|
||||
str->append(view_name.str, view_name.length);
|
||||
append_identifier(thd, str, view_db.str, view_db.length);
|
||||
str->append('.');
|
||||
append_identifier(thd, str, view_name.str, view_name.length);
|
||||
if (my_strcasecmp(table_alias_charset, view_name.str, alias))
|
||||
{
|
||||
str->append("` `", 3);
|
||||
str->append(alias);
|
||||
str->append(' ');
|
||||
append_identifier(thd, str, alias, strlen(alias));
|
||||
}
|
||||
str->append('`');
|
||||
}
|
||||
else if (derived)
|
||||
{
|
||||
str->append('(');
|
||||
derived->print(str);
|
||||
str->append(") `", 3);
|
||||
str->append(alias);
|
||||
str->append('`');
|
||||
str->append(") ", 2);
|
||||
append_identifier(thd, str, alias, strlen(alias));
|
||||
}
|
||||
else
|
||||
{
|
||||
str->append('`');
|
||||
str->append(db);
|
||||
str->append("`.`", 3);
|
||||
str->append(real_name);
|
||||
append_identifier(thd, str, db, db_length);
|
||||
str->append('.');
|
||||
append_identifier(thd, str, real_name, real_name_length);
|
||||
if (my_strcasecmp(table_alias_charset, real_name, alias))
|
||||
{
|
||||
str->append("` `", 3);
|
||||
str->append(alias);
|
||||
str->append(' ');
|
||||
append_identifier(thd, str, alias, strlen(alias));
|
||||
}
|
||||
str->append('`');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,7 +356,12 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
|
||||
|
||||
// print query
|
||||
str.length(0);
|
||||
thd->lex->unit.print(&str);
|
||||
{
|
||||
ulong sql_mode= thd->variables.sql_mode & MODE_ANSI_QUOTES;
|
||||
thd->variables.sql_mode&= ~MODE_ANSI_QUOTES;
|
||||
thd->lex->unit.print(&str);
|
||||
thd->variables.sql_mode|= sql_mode;
|
||||
}
|
||||
str.append('\0');
|
||||
DBUG_PRINT("VIEW", ("View: %s", str.ptr()));
|
||||
|
||||
|
Reference in New Issue
Block a user