summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorGleb Shchepa <gshchepa@mysql.com>2009-05-18 23:43:06 +0500
committerGleb Shchepa <gshchepa@mysql.com>2009-05-18 23:43:06 +0500
commita7294532b2f45342075d2a1bdac6cb8720a90ea3 (patch)
tree5e85c79ec8dded8d42753cd6706b2dcc48f95297 /mysql-test
parent1d03fb715ebcd995648793fbdba57d9a2069ede6 (diff)
downloadmariadb-git-a7294532b2f45342075d2a1bdac6cb8720a90ea3.tar.gz
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.
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/view.result19
-rw-r--r--mysql-test/t/view.test23
2 files changed, 42 insertions, 0 deletions
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 58aa614c508..a7ac971ef45 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -3705,5 +3705,24 @@ ERROR HY000: Key 'c2' doesn't exist in table 'v1'
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.
# -----------------------------------------------------------------
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index 6437e546697..89e68e4bd99 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -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 # -----------------------------------------------------------------