From b0b75bbfbb8df74a0bc31cabe7d75c93dff5410e Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 Jul 2004 18:51:02 +0300 Subject: [PATCH] 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 --- mysql-test/r/view.result | 13 +++++++++++-- mysql-test/t/view.test | 14 ++++++++++++-- sql/item.cc | 31 +++++++++++++++---------------- sql/sql_select.cc | 29 ++++++++++++----------------- sql/sql_view.cc | 7 ++++++- 5 files changed, 56 insertions(+), 38 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 1e772b65412..768b870075e 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -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`; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index ebc14f3753b..2ff6b278d4d 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -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`; diff --git a/sql/item.cc b/sql/item.cc index bc77dae25a9..b6dfb97d128 100644 --- a/sql/item.cc +++ b/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 */ diff --git a/sql/sql_select.cc b/sql/sql_select.cc index cf95a75be12..7b0a57d3e86 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -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('`'); } } diff --git a/sql/sql_view.cc b/sql/sql_view.cc index c558d1c5d34..a5565c95417 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -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()));