From 2ff98e05867ba02dad0b3bd8d27b814afbb54a59 Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Thu, 1 Dec 2005 12:15:48 +0200 Subject: [PATCH] View creation code fixed to expect empty TABLE_LIST::table pointer (BUG#15096). --- mysql-test/r/view.result | 15 +++++++++++++++ mysql-test/t/view.test | 21 +++++++++++++++++++++ sql/sql_view.cc | 35 ++++++++++++++++++++++------------- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index ebb2c190eb1..16ed023fdac 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2424,3 +2424,18 @@ f1 sum(f2) NULL 12 drop view v1; drop table t1; +CREATE VIEW v1 AS SELECT 42 AS Meaning; +DROP FUNCTION IF EXISTS f1; +CREATE FUNCTION f1() RETURNS INTEGER +BEGIN +DECLARE retn INTEGER; +SELECT Meaning FROM v1 INTO retn; +RETURN retn; +END +// +CREATE VIEW v2 AS SELECT f1(); +select * from v2; +f1() +42 +drop view v2,v1; +drop function f1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index ac103278f08..8a19b9fce08 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2280,3 +2280,24 @@ create view v1 as select * from t1; select f1, sum(f2) from v1 group by f1; drop view v1; drop table t1; + +# +# BUG#15096: using function with view for view creation +# +CREATE VIEW v1 AS SELECT 42 AS Meaning; +--disable_warnings +DROP FUNCTION IF EXISTS f1; +--enable_warnings +DELIMITER //; +CREATE FUNCTION f1() RETURNS INTEGER +BEGIN + DECLARE retn INTEGER; + SELECT Meaning FROM v1 INTO retn; + RETURN retn; +END +// +DELIMITER ;// +CREATE VIEW v2 AS SELECT f1(); +select * from v2; +drop view v2,v1; +drop function f1; diff --git a/sql/sql_view.cc b/sql/sql_view.cc index e03d3b22b89..31c5e5fed0a 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -350,15 +350,6 @@ bool mysql_create_view(THD *thd, */ for (tbl= lex->query_tables; tbl; tbl= tbl->next_global) { - /* is this table temporary and is not view? */ - if (tbl->table->s->tmp_table != NO_TMP_TABLE && !tbl->view && - !tbl->schema_table) - { - my_error(ER_VIEW_SELECT_TMPTABLE, MYF(0), tbl->alias); - res= TRUE; - goto err; - } - /* is this table view and the same view which we creates now? */ if (tbl->view && strcmp(tbl->view_db.str, view->db) == 0 && @@ -370,11 +361,29 @@ bool mysql_create_view(THD *thd, } /* - Copy the privileges of the underlying VIEWs which were filled by - fill_effective_table_privileges - (they were not copied at derived tables processing) + tbl->table can be NULL when tbl is a placeholder for a view + that is indirectly referenced via a stored function from the + view being created. We don't check these indirectly + referenced views in CREATE VIEW so they don't have table + object. */ - tbl->table->grant.privilege= tbl->grant.privilege; + if (tbl->table) + { + /* is this table temporary and is not view? */ + if (tbl->table->s->tmp_table != NO_TMP_TABLE && !tbl->view && + !tbl->schema_table) + { + my_error(ER_VIEW_SELECT_TMPTABLE, MYF(0), tbl->alias); + res= TRUE; + goto err; + } + /* + Copy the privileges of the underlying VIEWs which were filled by + fill_effective_table_privileges + (they were not copied at derived tables processing) + */ + tbl->table->grant.privilege= tbl->grant.privilege; + } } /* prepare select to resolve all fields */