From 9e06efb45c1a2ce808d642c020c4783d7fc1b1d8 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 29 May 2007 14:45:30 +0300 Subject: [PATCH] Bug #28605: SHOW CREATE VIEW with views using stored_procedures no longer showing SP names. SHOW CREATE VIEW uses Item::print() methods to reconstruct the statement text from the parse tree. The print() method for stored procedure calls needs allocate space to print the function's quoted name. It was incorrectly calculating the length of the buffer needed (was too short). Fixed to reflect the actual space needed. mysql-test/r/sp.result: Bug #28605: test case mysql-test/t/sp.test: Bug #28605: test case sql/item_func.cc: Bug #28605: fixed the string length calculation --- mysql-test/r/sp.result | 11 +++++++++++ mysql-test/t/sp.test | 20 ++++++++++++++++++++ sql/item_func.cc | 5 +++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index b5b79af031e..5b7f32442ae 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -6152,3 +6152,14 @@ count(*) 3 drop table t1,t2; drop function bug27354; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE FUNCTION metered(a INT) RETURNS INT RETURN 12; +CREATE VIEW v1 AS SELECT test.metered(a) as metered FROM t1; +SHOW CREATE VIEW v1; +View Create View +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`metered`(`t1`.`a`) AS `metered` from `t1` +DROP VIEW v1; +DROP FUNCTION metered; +DROP TABLE t1; +End of 5.0 tests diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index ff203a85ef7..88b8a46c48f 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -7112,3 +7112,23 @@ select count(*) from t1 /* must be 3 */; drop table t1,t2; drop function bug27354; + +# +# Bug #28605: SHOW CREATE VIEW with views using stored_procedures no longer +# showing SP names. +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); + +CREATE FUNCTION metered(a INT) RETURNS INT RETURN 12; + +CREATE VIEW v1 AS SELECT test.metered(a) as metered FROM t1; + +SHOW CREATE VIEW v1; + +DROP VIEW v1; +DROP FUNCTION metered; +DROP TABLE t1; + + +--echo End of 5.0 tests diff --git a/sql/item_func.cc b/sql/item_func.cc index 34f3c2c6add..7e1872e9a75 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -5213,10 +5213,11 @@ Item_func_sp::func_name() const { THD *thd= current_thd; /* Calculate length to avoid reallocation of string for sure */ - uint len= ((m_name->m_explicit_name ? m_name->m_db.length : 0 + + uint len= (((m_name->m_explicit_name ? m_name->m_db.length : 0) + m_name->m_name.length)*2 + //characters*quoting 2 + // ` and ` - 1 + // . + (m_name->m_explicit_name ? + 3 : 0) + // '`', '`' and '.' for the db 1 + // end of string ALIGN_SIZE(1)); // to avoid String reallocation String qname((char *)alloc_root(thd->mem_root, len), len,