From 0b54001b21e56ceb04d80eeeadbb62a04b04d34f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Apr 2007 23:21:37 +0500 Subject: Bug#5507: TRUNCATE does not work with views. Support of views wasn't implemented for the TRUNCATE statement. Now TRUNCATE on views has the same semantics as DELETE FROM view: mysql_truncate() checks whether the table is a view and falls back to delete if so. In order to initialize properly the LEX::updatable for a view st_lex::can_use_merged() now allows usage of merged views for the TRUNCATE statement. mysql-test/r/truncate.result: Added a test case for the Bug#5507: TRUNCATE does not work with views. mysql-test/t/truncate.test: Added a test case for the Bug#5507: TRUNCATE does not work with views. sql/sql_lex.cc: Bug#5507: TRUNCATE does not work with views. can_use_merged() was denying of usage of merged views for a TRUNCATE statement. This results in improper initialization of view LEX::updatable. Fixed. sql/sql_delete.cc: Bug#5507: TRUNCATE does not work with views. 1.mysql_truncate() was lacking of check whether the table is view. Added. 2.mysql_truncate() calls mysql_delete(), but mysql_delete() always reports errors as "DELETE" errors. Fixed. mysql-test/t/view.test: Updated test case for Bug#14540: OPTIMIZE, ANALYZE, REPAIR applied to not a view. mysql-test/r/view.result: Updated test case for Bug#14540: OPTIMIZE, ANALYZE, REPAIR applied to not a view. --- sql/sql_delete.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'sql/sql_delete.cc') diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 19f3135c594..6956e5cfe91 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -369,6 +369,8 @@ bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds) { Item *fake_conds= 0; SELECT_LEX *select_lex= &thd->lex->select_lex; + const char *operation = thd->lex->sql_command == SQLCOM_TRUNCATE ? + "TRUNCATE" : "DELETE"; DBUG_ENTER("mysql_prepare_delete"); List all_fields; @@ -383,14 +385,14 @@ bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds) DBUG_RETURN(TRUE); if (!table_list->updatable || check_key_in_view(thd, table_list)) { - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "DELETE"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, operation); DBUG_RETURN(TRUE); } { TABLE_LIST *duplicate; if ((duplicate= unique_table(thd, table_list, table_list->next_global, 0))) { - update_non_unique_table_error(table_list, "DELETE", duplicate); + update_non_unique_table_error(table_list, operation, duplicate); DBUG_RETURN(TRUE); } } @@ -895,7 +897,8 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) if (!dont_send_ok) { db_type table_type; - mysql_frm_type(thd, path, &table_type); + if (mysql_frm_type(thd, path, &table_type) == FRMTYPE_VIEW) + goto trunc_by_del; if (table_type == DB_TYPE_UNKNOWN) { my_error(ER_NO_SUCH_TABLE, MYF(0), -- cgit v1.2.1