Commit 346d10a9 authored by Monty's avatar Monty

Fixed error messages from DROP VIEW to align with DROP TABLE

- Produce a "Note" for all wrongly dropped objects
  (Like doing DROP VIEW on a table).
- IF EXISTS ends with a list of all not existing objects, instead of a
  separate note for every not existing object.

Other things:
 - Fixed bug where one could do CREATE TEMPORARY SEQUENCE multiple times
   and create multiple temporary sequences with the same name.
parent 5bcb1d65
...@@ -61,5 +61,6 @@ Warnings: ...@@ -61,5 +61,6 @@ Warnings:
Note 4092 Unknown VIEW: 'test.v1' Note 4092 Unknown VIEW: 'test.v1'
DROP VIEW IF EXISTS t1; DROP VIEW IF EXISTS t1;
Warnings: Warnings:
Warning 1347 'test.t1' is not of type 'VIEW'
Note 4092 Unknown VIEW: 'test.t1' Note 4092 Unknown VIEW: 'test.t1'
DROP TABLE t1; DROP TABLE t1;
...@@ -209,10 +209,7 @@ Note 1051 Unknown table 'test.table1' ...@@ -209,10 +209,7 @@ Note 1051 Unknown table 'test.table1'
Note 1051 Unknown table 'test.table2' Note 1051 Unknown table 'test.table2'
DROP VIEW IF EXISTS view1,view2,view3,view4; DROP VIEW IF EXISTS view1,view2,view3,view4;
Warnings: Warnings:
Note 4092 Unknown VIEW: 'test.view1' Note 4092 Unknown VIEW: 'test.view1,test.view2,test.view3,test.view4'
Note 4092 Unknown VIEW: 'test.view2'
Note 4092 Unknown VIEW: 'test.view3'
Note 4092 Unknown VIEW: 'test.view4'
# Test error message when trigger does not find table # Test error message when trigger does not find table
CREATE TABLE table1(a int); CREATE TABLE table1(a int);
......
#
# Create all tables, sequences and views needed for drop combinations;
#
if ($create_option != 'temporary')
{
show tables;
}
--echo # Generating test tables
--disable_query_log
--disable_warnings
eval create $create_option table if not exists t1 (a int);
eval create $create_option table if not exists t2 (a int);
eval create $create_option sequence if not exists s1;
eval create $create_option sequence if not exists s2;
if ($create_option != 'temporary')
{
eval create view if not exists v1 as SELECT * from t1;
eval create view if not exists v2 as SELECT * from t2;
}
--enable_warnings
--enable_query_log
This diff is collapsed.
#
# Test different combinations of doing DROP TABLE/SEQUENCE/VIEW
#
SET @save_default_engine= @@DEFAULT_STORAGE_ENGINE;
SET default_storage_engine=myisam;
let $DATADIR= `select @@datadir`;
# Create tables t1,t2, sequences s1,s2 and views v1,v2
let $create_option=;
--source drop_combinations.inc
--echo #
--echo # DROP TABLE
--echo #
--error ER_BAD_TABLE_ERROR
drop table t1,t2,t3;
--source drop_combinations.inc
--error ER_BAD_TABLE_ERROR
drop table t1,t3,t2;
--source drop_combinations.inc
--error ER_BAD_TABLE_ERROR
drop table t1,t4,t2,t3;
--source drop_combinations.inc
drop table t1,s1,s2,t2;
--source drop_combinations.inc
--error ER_BAD_TABLE_ERROR
drop table t1,v1,v2,t2;
--source drop_combinations.inc
--error ER_BAD_TABLE_ERROR
drop table v1,s1,s2,v2,t2;
--source drop_combinations.inc
--remove_file $DATADIR/test/t1.MYD
--error ER_BAD_TABLE_ERROR
drop table t1,s1,v1,t3,t4;
--error ER_BAD_TABLE_ERROR
drop table s2,v2,t2,t1;
--source drop_combinations.inc
--error ER_BAD_TABLE_ERROR
drop table s1,v1,s2,v2;
--source drop_combinations.inc
--echo #
--echo # DROP TABLE with if exists
--echo #
drop table if exists t1,t2,t3;
--source drop_combinations.inc
drop table if exists t1,t3,t2;
--source drop_combinations.inc
drop table if exists t1,t4,t2,t3;
--source drop_combinations.inc
drop table if exists t1,s1,s2,t2;
--source drop_combinations.inc
drop table if exists t1,v1,v2,t2;
--source drop_combinations.inc
drop table if exists v1,s1,s2,v2,t2;
--source drop_combinations.inc
--remove_file $DATADIR/test/t1.MYD
drop table if exists t1,s1,v1,t3,t4;
drop table if exists s2,v2,t2,t1;
--source drop_combinations.inc
drop table if exists s1,v1,s2,v2;
--source drop_combinations.inc
--echo #
--echo # DROP TEMPORARY TABLE
--echo #
--disable_warnings
drop table if exists t1,t2;
drop temporary table if exists tt1,tt2;
drop sequence if exists s1,s2;
drop temporary sequence if exists ss1,ss2;
drop view if exists v1,v2;
--enable_warnings
let $create_option=temporary;
--error ER_BAD_TABLE_ERROR
drop temporary table t1,t2,t3;
--source drop_combinations.inc
--error ER_BAD_TABLE_ERROR
drop temporary table t1,t3,t2;
--source drop_combinations.inc
--error ER_BAD_TABLE_ERROR
drop temporary table t1,t4,t2,t3;
--source drop_combinations.inc
drop temporary table t1,s1,s2,t2;
--source drop_combinations.inc
--error ER_BAD_TABLE_ERROR
drop temporary table t1,v1,v2,t2;
--source drop_combinations.inc
--error ER_BAD_TABLE_ERROR
drop temporary table v1,s1,s2,v2,t2;
--source drop_combinations.inc
--error ER_BAD_TABLE_ERROR
drop temporary table t1,s1,v1,t3,t4;
--source drop_combinations.inc
--error ER_BAD_TABLE_ERROR
drop temporary table s2,v2,t2,t1;
--source drop_combinations.inc
--error ER_BAD_TABLE_ERROR
drop temporary table s1,v1,s2,v2;
--source drop_combinations.inc
--echo #
--echo # DROP TEMPORARY TABLE with if exists
--echo #
drop temporary table if exists t1,t2,t3;
--source drop_combinations.inc
drop temporary table if exists t1,t3,t2;
--source drop_combinations.inc
drop temporary table if exists t1,t4,t2,t3;
--source drop_combinations.inc
drop temporary table if exists t1,s1,s2,t2;
--source drop_combinations.inc
drop temporary table if exists t1,v1,v2,t2;
--source drop_combinations.inc
drop temporary table if exists v1,s1,s2,v2,t2;
--source drop_combinations.inc
drop temporary table if exists t1,s1,v1,t3,t4;
drop temporary table if exists s2,v2,t2,t1;
--source drop_combinations.inc
drop temporary table if exists s1,v1,s2,v2;
--source drop_combinations.inc
let $create_option=;
drop temporary table t1,t2;
drop temporary sequence s1,s2;
--source drop_combinations.inc
--echo #
--echo # DROP SEQUENCE
--echo #
--error ER_UNKNOWN_SEQUENCES
drop sequence s1,s2,s3;
--source drop_combinations.inc
--error ER_UNKNOWN_SEQUENCES
drop sequence s1,s3,s2;
--source drop_combinations.inc
--error ER_UNKNOWN_SEQUENCES
drop sequence s1,s4,s2,s3;
--source drop_combinations.inc
--error ER_UNKNOWN_SEQUENCES
drop sequence s1,t1,t2,s2;
--source drop_combinations.inc
--error ER_UNKNOWN_SEQUENCES
drop sequence s1,v1,v2,s2;
--source drop_combinations.inc
--error ER_UNKNOWN_SEQUENCES
drop sequence v1,t1,t2,v2,s2;
--source drop_combinations.inc
--remove_file $DATADIR/test/s1.MYD
--error ER_UNKNOWN_SEQUENCES
drop sequence s1,t1,v1,t3,s4;
--error ER_UNKNOWN_SEQUENCES
drop sequence t2,v2,s2,s1;
--source drop_combinations.inc
--error ER_UNKNOWN_SEQUENCES
drop sequence t1,v1,t2,v2;
--source drop_combinations.inc
--echo #
--echo # DROP SEQUENCE with if exists
--echo #
drop sequence if exists s1,s2,s3;
--source drop_combinations.inc
drop sequence if exists s1,s3,s2;
--source drop_combinations.inc
drop sequence if exists s1,s4,s2,s3;
--source drop_combinations.inc
drop sequence if exists s1,t1,t2,s2;
--source drop_combinations.inc
drop sequence if exists s1,v1,v2,s2;
--source drop_combinations.inc
drop sequence if exists v1,t1,t2,v2,s2;
--source drop_combinations.inc
--remove_file $DATADIR/test/s1.MYD
drop sequence if exists s1,t1,v1,t3,s4;
drop sequence if exists t2,v2,s2,s1;
--source drop_combinations.inc
drop sequence if exists t1,v1,t2,v2;
--source drop_combinations.inc
--echo #
--echo # DROP TEMPORARY SEQUENCE
--echo #
--disable_warnings
drop table if exists t1,t2;
drop temporary table if exists tt1,tt2;
drop sequence if exists s1,s2;
drop temporary sequence if exists ss1,ss2;
drop view if exists v1,v2;
--enable_warnings
let $create_option=temporary;
--source drop_combinations.inc
--error ER_UNKNOWN_SEQUENCES
drop temporary sequence s1,s2,s3;
--source drop_combinations.inc
--error ER_UNKNOWN_SEQUENCES
drop temporary sequence s1,s3,s2;
--source drop_combinations.inc
--error ER_UNKNOWN_SEQUENCES
drop temporary sequence s1,s4,s2,s3;
--source drop_combinations.inc
--error ER_UNKNOWN_SEQUENCES
drop temporary sequence s1,t1,t2,s2;
--source drop_combinations.inc
--error ER_UNKNOWN_SEQUENCES
drop temporary sequence s1,v1,v2,s2;
--source drop_combinations.inc
--error ER_UNKNOWN_SEQUENCES
drop temporary sequence v1,t1,t2,v2,s2;
--source drop_combinations.inc
--error ER_UNKNOWN_SEQUENCES
drop temporary sequence s1,t1,v1,t3,s4;
--error ER_UNKNOWN_SEQUENCES
drop temporary sequence t2,v2,s2,s1;
--source drop_combinations.inc
--error ER_UNKNOWN_SEQUENCES
drop temporary sequence t1,v1,t2,v2;
--source drop_combinations.inc
--echo #
--echo # DROP TEMPORARY SEQUENCE with if exists
--echo #
drop temporary sequence if exists s1,s2,s3;
--source drop_combinations.inc
drop temporary sequence if exists s1,s3,s2;
--source drop_combinations.inc
drop temporary sequence if exists s1,s4,s2,s3;
--source drop_combinations.inc
drop temporary sequence if exists s1,t1,t2,s2;
--source drop_combinations.inc
drop temporary sequence if exists s1,v1,v2,s2;
--source drop_combinations.inc
drop temporary sequence if exists v1,t1,t2,v2,s2;
--source drop_combinations.inc
drop temporary sequence if exists s1,t1,v1,t3,s4;
drop temporary sequence if exists t2,v2,s2,s1;
--source drop_combinations.inc
drop temporary sequence if exists t1,v1,t2,v2;
--source drop_combinations.inc
let $create_option=;
drop temporary table t1,t2;
drop temporary sequence s1,s2;
--source drop_combinations.inc
--echo #
--echo # DROP VIEW
--echo #
--error ER_UNKNOWN_VIEW
drop view v1,v2,v3;
show warnings;
--source drop_combinations.inc
--error ER_UNKNOWN_VIEW
drop view v1,v3,v2;
show warnings;
--source drop_combinations.inc
--error ER_UNKNOWN_VIEW
drop view v1,v4,v2,v3;
show warnings;
--source drop_combinations.inc
--error ER_UNKNOWN_VIEW
drop view v1,t1,t2,v2;
show warnings;
--source drop_combinations.inc
--error ER_UNKNOWN_VIEW
drop view v1,s1,s2,v2;
show warnings;
--source drop_combinations.inc
--remove_file $DATADIR/test/t1.MYD
--error ER_UNKNOWN_VIEW
drop view s1,t1,t2,s2,v2;
show warnings;
drop table t1;
show warnings;
--error ER_UNKNOWN_VIEW
drop view v1,t1;
show warnings;
--source drop_combinations.inc
--error ER_UNKNOWN_VIEW
drop view v1,t1,s1,t3,v4;
show warnings;
--error ER_UNKNOWN_VIEW
drop view t2,s2,v2,v1;
show warnings;
--source drop_combinations.inc
--error ER_UNKNOWN_VIEW
drop view t1,s1,t2,s2;
show warnings;
--source drop_combinations.inc
--echo #
--echo # DROP VIEW with if exists
--echo #
drop view if exists v1,v2,v3;
--source drop_combinations.inc
drop view if exists v1,v3,v2;
--source drop_combinations.inc
drop view if exists v1,v4,v2,v3;
--source drop_combinations.inc
drop view if exists v1,t1,t2,v2;
--source drop_combinations.inc
drop view if exists v1,s1,s2,v2;
--source drop_combinations.inc
drop view if exists s1,t1,t2,s2,v2;
drop table t1;
drop view if exists v1,t1;
--source drop_combinations.inc
drop view if exists v1,t1,s1,t3,v4;
drop view if exists t2,s2,v2,v1;
--source drop_combinations.inc
drop view if exists t1,s1,t2,s2;
--source drop_combinations.inc
--echo # cleanup
drop table if exists t1,t2;
drop sequence if exists s1,s2;
drop view if exists v1,v2;
SET default_storage_engine=@save_default_engine;
...@@ -198,7 +198,7 @@ c d ...@@ -198,7 +198,7 @@ c d
drop view v100; drop view v100;
ERROR 42S02: Unknown VIEW: 'test.v100' ERROR 42S02: Unknown VIEW: 'test.v100'
drop view t1; drop view t1;
ERROR HY000: 'test.t1' is not of type 'VIEW' ERROR 42S02: Unknown VIEW: 'test.t1'
drop table v1; drop table v1;
ERROR 42S02: 'test.v1' is a view ERROR 42S02: 'test.v1' is a view
drop view v1,v2; drop view v1,v2;
...@@ -2848,7 +2848,11 @@ Tables_in_test ...@@ -2848,7 +2848,11 @@ Tables_in_test
t1 t1
CREATE VIEW v1 AS SELECT id FROM t1; CREATE VIEW v1 AS SELECT id FROM t1;
DROP VIEW t1,v1; DROP VIEW t1,v1;
ERROR HY000: 'test.t1' is not of type 'VIEW' ERROR 42S02: Unknown VIEW: 'test.t1'
show warnings;
Level Code Message
Warning 1347 'test.t1' is not of type 'VIEW'
Error 4092 Unknown VIEW: 'test.t1'
SHOW TABLES; SHOW TABLES;
Tables_in_test Tables_in_test
t1 t1
......
...@@ -130,7 +130,7 @@ select * from v2; ...@@ -130,7 +130,7 @@ select * from v2;
drop view v100; drop view v100;
# try to drop table with DROP VIEW # try to drop table with DROP VIEW
-- error ER_WRONG_OBJECT -- error ER_UNKNOWN_VIEW
drop view t1; drop view t1;
# try to drop VIEW with DROP TABLE # try to drop VIEW with DROP TABLE
...@@ -2730,8 +2730,9 @@ DROP VIEW v2,v1; ...@@ -2730,8 +2730,9 @@ DROP VIEW v2,v1;
SHOW TABLES; SHOW TABLES;
CREATE VIEW v1 AS SELECT id FROM t1; CREATE VIEW v1 AS SELECT id FROM t1;
--error ER_WRONG_OBJECT --error ER_UNKNOWN_VIEW
DROP VIEW t1,v1; DROP VIEW t1,v1;
show warnings;
SHOW TABLES; SHOW TABLES;
DROP TABLE t1; DROP TABLE t1;
......
...@@ -1810,10 +1810,10 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) ...@@ -1810,10 +1810,10 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
char path[FN_REFLEN + 1]; char path[FN_REFLEN + 1];
TABLE_LIST *view; TABLE_LIST *view;
String non_existant_views; String non_existant_views;
const char *wrong_object_db= NULL, *wrong_object_name= NULL; bool delete_error= FALSE, wrong_object_name= FALSE;
bool error= FALSE;
bool some_views_deleted= FALSE; bool some_views_deleted= FALSE;
bool something_wrong= FALSE; bool something_wrong= FALSE;
uint not_exists_count= 0;
DBUG_ENTER("mysql_drop_view"); DBUG_ENTER("mysql_drop_view");
/* /*
...@@ -1843,32 +1843,22 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) ...@@ -1843,32 +1843,22 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
char name[FN_REFLEN]; char name[FN_REFLEN];
my_snprintf(name, sizeof(name), "%s.%s", view->db.str, my_snprintf(name, sizeof(name), "%s.%s", view->db.str,
view->table_name.str); view->table_name.str);
if (thd->lex->if_exists())
{
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
ER_UNKNOWN_VIEW,
ER_THD(thd, ER_UNKNOWN_VIEW),
name);
continue;
}
if (not_exist)
{
if (non_existant_views.length()) if (non_existant_views.length())
non_existant_views.append(','); non_existant_views.append(',');
non_existant_views.append(name); non_existant_views.append(name);
}
else if (!not_exist)
{
if (!wrong_object_name)
{ {
wrong_object_db= view->db.str; wrong_object_name= 1;
wrong_object_name= view->table_name.str; my_error(ER_WRONG_OBJECT, MYF(ME_WARNING), view->db.str,
} view->table_name.str, "VIEW");
} }
else
not_exists_count++;
continue; continue;
} }
if (unlikely(mysql_file_delete(key_file_frm, path, MYF(MY_WME)))) if (unlikely(mysql_file_delete(key_file_frm, path, MYF(MY_WME))))
error= TRUE; delete_error= TRUE;
some_views_deleted= TRUE; some_views_deleted= TRUE;
...@@ -1881,17 +1871,16 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) ...@@ -1881,17 +1871,16 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
sp_cache_invalidate(); sp_cache_invalidate();
} }
if (unlikely(wrong_object_name)) something_wrong= (delete_error ||
{ (!thd->lex->if_exists() && (not_exists_count ||
my_error(ER_WRONG_OBJECT, MYF(0), wrong_object_db, wrong_object_name, wrong_object_name)));
"VIEW");
}
if (unlikely(non_existant_views.length())) if (unlikely(non_existant_views.length()))
{ {
my_error(ER_UNKNOWN_VIEW, MYF(0), non_existant_views.c_ptr_safe()); my_error(ER_UNKNOWN_VIEW, MYF(something_wrong ? 0 : ME_NOTE),
non_existant_views.c_ptr_safe());
} }
something_wrong= error || wrong_object_name || non_existant_views.length();
if (some_views_deleted || !something_wrong) if (some_views_deleted || !something_wrong)
{ {
/* if something goes wrong, bin-log with possible error code, /* if something goes wrong, bin-log with possible error code,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment