#At file:///home/uchum/work/bzr/mysql-5.0-bugteam/ based on revid:matthias.leich@stripped
2748 Gleb Shchepa 2009-05-18
Bug#40825: Error 1356 while selecting from a view
with a "HAVING" clause though query works
SELECT from views defined like:
CREATE VIEW v1 (view_column)
AS SELECT c AS alias FROM t1 HAVING alias
fails with an error 1356:
View '...' references invalid table(s) or column(s)
or function(s) or definer/invoker of view lack rights
to use them
CREATE VIEW form with a (column list) substitutes
SELECT column names/aliases with names from a
view column list.
However, alias references in HAVING clause was
not substituted.
The Item_ref::print function has been modified
to write correct aliased names of underlying
items into VIEW definition generation/.frm file.
@ mysql-test/r/view.result
Added test file for bug #40825.
@ mysql-test/t/view.test
Added test file for bug #40825.
@ sql/item.cc
Bug#40825: Error 1356 while selecting from a view
with a "HAVING" clause though query works
The Item_ref::print function has been modified
to write correct aliased names of underlying
items into VIEW definition generation/.frm file.
modified:
mysql-test/r/view.result
mysql-test/t/view.test
sql/item.cc
=== modified file 'mysql-test/r/view.result'
--- a/mysql-test/r/view.result 2009-03-03 20:34:18 +0000
+++ b/mysql-test/r/view.result 2009-05-18 18:43:06 +0000
@@ -3705,5 +3705,24 @@ ERROR HY000: Key 'c2' doesn't exist in t
DROP VIEW v1;
DROP TABLE t1;
# -----------------------------------------------------------------
+# -- Bug#40825: Error 1356 while selecting from a view
+# -- with a "HAVING" clause though query works
+# -----------------------------------------------------------------
+
+CREATE TABLE t1 (c INT);
+
+CREATE VIEW v1 (view_column) AS SELECT c AS alias FROM t1 HAVING alias;
+SHOW CREATE VIEW v1;
+View Create View
+v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`c` AS `view_column` from `t1` having `view_column`
+SELECT * FROM v1;
+view_column
+
+DROP VIEW v1;
+DROP TABLE t1;
+
+# -- End of test case for Bug#40825
+
+# -----------------------------------------------------------------
# -- End of 5.0 tests.
# -----------------------------------------------------------------
=== modified file 'mysql-test/t/view.test'
--- a/mysql-test/t/view.test 2009-03-03 20:34:18 +0000
+++ b/mysql-test/t/view.test 2009-05-18 18:43:06 +0000
@@ -3681,5 +3681,28 @@ DROP VIEW v1;
DROP TABLE t1;
--echo # -----------------------------------------------------------------
+--echo # -- Bug#40825: Error 1356 while selecting from a view
+--echo # -- with a "HAVING" clause though query works
+--echo # -----------------------------------------------------------------
+--echo
+
+CREATE TABLE t1 (c INT);
+
+--echo
+
+CREATE VIEW v1 (view_column) AS SELECT c AS alias FROM t1 HAVING alias;
+SHOW CREATE VIEW v1;
+SELECT * FROM v1;
+
+--echo
+
+DROP VIEW v1;
+DROP TABLE t1;
+
+--echo
+--echo # -- End of test case for Bug#40825
+--echo
+
+--echo # -----------------------------------------------------------------
--echo # -- End of 5.0 tests.
--echo # -----------------------------------------------------------------
=== modified file 'sql/item.cc'
--- a/sql/item.cc 2009-04-28 00:19:13 +0000
+++ b/sql/item.cc 2009-05-18 18:43:06 +0000
@@ -5648,7 +5648,8 @@ void Item_ref::print(String *str)
!table_name && name && alias_name_used)
{
THD *thd= current_thd;
- append_identifier(thd, str, name, (uint) strlen(name));
+ append_identifier(thd, str, (*ref)->real_item()->name,
+ (*ref)->real_item()->name_length);
}
else
(*ref)->print(str);
Attachment: [text/bzr-bundle] bzr/gshchepa@mysql.com-20090518184306-s67bsoxiwzj0a7us.bundle
| Thread |
|---|
| • bzr commit into mysql-5.0-bugteam branch (gshchepa:2748) Bug#40825 | Gleb Shchepa | 18 May |