From d8f599bcdcf7248c872dc8f0d5117e744a6bc119 Mon Sep 17 00:00:00 2001 From: unknown <bell@sanja.is.com.ua> Date: Tue, 24 Aug 2004 23:07:34 +0300 Subject: [PATCH] fixes name outout for SHOW CREATE VIEW command (BUG#5162) mysql-test/r/view.result: SHOW CREATE VIEW output changed test of SHOW CREATE VIEW for view with spaces in the name mysql-test/t/view.test: test of SHOW CREATE VIEW for view with spaces in the name sql/sql_show.cc: fixes name outout for SHOW CREATE VIEW command --- mysql-test/r/view.result | 29 +++++++++++++++++------------ mysql-test/t/view.test | 7 +++++++ sql/sql_show.cc | 4 ++-- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index d99743c9a0..ddad7395ce 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -32,10 +32,10 @@ c 11 show create table v1; Table Create Table -v1 CREATE VIEW test.v1 AS select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1` +v1 CREATE VIEW `test`.`v1` AS select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1` show create view v1; Table Create Table -v1 CREATE VIEW test.v1 AS select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1` +v1 CREATE VIEW `test`.`v1` AS select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1` show create view t1; ERROR HY000: 'test.t1' is not VIEW drop table t1; @@ -55,7 +55,7 @@ Note 1003 select (`test`.`t1`.`b` + 1) AS `c` from `test`.`v1` create algorithm=temptable view v2 (c) as select b+1 from t1; show create table v2; Table Create Table -v2 CREATE ALGORITHM=TMPTABLE VIEW test.v2 AS select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1` +v2 CREATE ALGORITHM=TMPTABLE VIEW `test`.`v2` AS select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1` select c from v2; c 3 @@ -306,14 +306,14 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found show create table mysqltest.v1; Table Create Table -v1 CREATE VIEW mysqltest.v1 AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1` +v1 CREATE VIEW `mysqltest`.`v1` AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1` explain select c from mysqltest.v2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found 2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table show create table mysqltest.v2; Table Create Table -v2 CREATE ALGORITHM=TMPTABLE VIEW mysqltest.v2 AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1` +v2 CREATE ALGORITHM=TMPTABLE VIEW `mysqltest`.`v2` AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1` explain select c from mysqltest.v3; ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table show create table mysqltest.v3; @@ -328,27 +328,27 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found show create table mysqltest.v1; Table Create Table -v1 CREATE VIEW mysqltest.v1 AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1` +v1 CREATE VIEW `mysqltest`.`v1` AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1` explain select c from mysqltest.v2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found 2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table show create table mysqltest.v2; Table Create Table -v2 CREATE ALGORITHM=TMPTABLE VIEW mysqltest.v2 AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1` +v2 CREATE ALGORITHM=TMPTABLE VIEW `mysqltest`.`v2` AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1` explain select c from mysqltest.v3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 system NULL NULL NULL NULL 0 const row not found show create table mysqltest.v3; Table Create Table -v3 CREATE VIEW mysqltest.v3 AS select (`mysqltest`.`t2`.`a` + 1) AS `c`,(`mysqltest`.`t2`.`b` + 1) AS `d` from `mysqltest`.`t2` +v3 CREATE VIEW `mysqltest`.`v3` AS select (`mysqltest`.`t2`.`a` + 1) AS `c`,(`mysqltest`.`t2`.`b` + 1) AS `d` from `mysqltest`.`t2` explain select c from mysqltest.v4; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found 2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table show create table mysqltest.v4; Table Create Table -v4 CREATE ALGORITHM=TMPTABLE VIEW mysqltest.v4 AS select (`mysqltest`.`t2`.`a` + 1) AS `c`,(`mysqltest`.`t2`.`b` + 1) AS `d` from `mysqltest`.`t2` +v4 CREATE ALGORITHM=TMPTABLE VIEW `mysqltest`.`v4` AS select (`mysqltest`.`t2`.`a` + 1) AS `c`,(`mysqltest`.`t2`.`b` + 1) AS `d` from `mysqltest`.`t2` revoke all privileges on mysqltest.* from mysqltest_1@localhost; delete from mysql.user where user='mysqltest_1'; drop database mysqltest; @@ -946,7 +946,7 @@ create table t1 ("a*b" int); create view v1 as select "a*b" from t1; show create view v1; Table Create Table -v1 CREATE VIEW test.v1 AS select `test`.`t1`.`a*b` AS `a*b` from `test`.`t1` +v1 CREATE VIEW "test"."v1" AS select `test`.`t1`.`a*b` AS `a*b` from `test`.`t1` drop view v1; drop table t1; set sql_mode=default; @@ -1055,7 +1055,7 @@ drop table t1; CREATE VIEW v1 (f1,f2,f3,f4) AS SELECT connection_id(), pi(), current_user(), version(); SHOW CREATE VIEW v1; Table Create Table -v1 CREATE VIEW test.v1 AS select sql_no_cache connection_id() AS `f1`,pi() AS `f2`,current_user() AS `f3`,version() AS `f4` +v1 CREATE VIEW `test`.`v1` AS select sql_no_cache connection_id() AS `f1`,pi() AS `f2`,current_user() AS `f3`,version() AS `f4` drop view v1; create table t1 (s1 int); create table t2 (s2 int); @@ -1089,6 +1089,11 @@ create view v1 as select a from t1; create view v2 as select a from t2 where a in (select a from v1); show create view v2; Table Create Table -v2 CREATE VIEW test.v2 AS select `test`.`t2`.`a` AS `a` from `test`.`t2` where `a` in (select `v1`.`a` AS `a` from `test`.`v1`) +v2 CREATE VIEW `test`.`v2` AS select `test`.`t2`.`a` AS `a` from `test`.`t2` where `a` in (select `v1`.`a` AS `a` from `test`.`v1`) drop view v2, v1; drop table t1, t2; +CREATE VIEW `v 1` AS select 5 AS `5`; +show create view `v 1`; +Table Create Table +v 1 CREATE VIEW `test`.`v 1` AS select 5 AS `5` +drop view `v 1`; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 82f6f46d80..1c3064e864 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -1038,3 +1038,10 @@ create view v2 as select a from t2 where a in (select a from v1); show create view v2; drop view v2, v1; drop table t1, t2; + +# +# SHOW VIEW view with name with spaces +# +CREATE VIEW `v 1` AS select 5 AS `5`; +show create view `v 1`; +drop view `v 1`; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index c11207eac2..fa8b81f8ea 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1575,9 +1575,9 @@ view_store_create_info(THD *thd, TABLE_LIST *table, String *buff) buff->append("MERGE ", 6); } buff->append("VIEW ", 5); - buff->append(table->view_db.str, table->view_db.length); + append_identifier(thd, buff, table->view_db.str, table->view_db.length); buff->append('.'); - buff->append(table->view_name.str, table->view_name.length); + append_identifier(thd, buff, table->view_name.str, table->view_name.length); buff->append(" AS ", 4); buff->append(table->query.str, table->query.length); return 0; -- 2.30.9