rename.test 2.23 KB
Newer Older
1 2 3 4
#
# Test of rename table
#

5 6
--source include/count_sessions.inc

7
--disable_warnings
8
drop table if exists t0,t1,t2,t3,t4;
9
# Clear up from other tests (to ensure that SHOW TABLES below is right)
unknown's avatar
unknown committed
10
drop table if exists t0,t5,t6,t7,t8,t9,t1_1,t1_2,t9_1,t9_2;
11 12
--enable_warnings

13 14 15 16 17 18 19 20 21
create table t0 SELECT 1,"table 1";
create table t2 SELECT 2,"table 2";
create table t3 SELECT 3,"table 3";
rename table t0 to t1;
rename table t3 to t4, t2 to t3, t1 to t2, t4 to t1;
select * from t1;
rename table t3 to t4, t2 to t3, t1 to t2, t4 to t1;
rename table t3 to t4, t2 to t3, t1 to t2, t4 to t1;
select * from t1;
unknown's avatar
unknown committed
22

23
# The following should give errors
24
--error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR
unknown's avatar
unknown committed
25
rename table t1 to t2;
26
--error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR
unknown's avatar
unknown committed
27
rename table t1 to t1;
28
--error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR
unknown's avatar
unknown committed
29
rename table t3 to t4, t2 to t3, t1 to t2, t4 to t2;
30
show tables like "t_";
31
--error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR
unknown's avatar
unknown committed
32
rename table t3 to t1, t2 to t3, t1 to t2, t4 to t1;
33
--error ER_FILE_NOT_FOUND,ER_FILE_NOT_FOUND
unknown's avatar
unknown committed
34
rename table t3 to t4, t5 to t3, t1 to t2, t4 to t1;
35 36 37 38

select * from t1;
select * from t2;
select * from t3;
39 40

# This should give a warning for t4
41
drop table if exists t1,t2,t3,t4;
unknown's avatar
unknown committed
42 43

#
44 45
# Bug #2397 RENAME TABLES is not blocked by
# FLUSH TABLES WITH READ LOCK
unknown's avatar
unknown committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#

connect (con1,localhost,root,,);
connect (con2,localhost,root,,);

connection con1;
CREATE TABLE t1 (a int);
CREATE TABLE t3 (a int);
connection con2;
FLUSH TABLES WITH READ LOCK;
connection con1;
send RENAME TABLE t1 TO t2, t3 to t4;
connection con2;
show tables;
UNLOCK TABLES;
61 62 63
connection con1;
reap;
connection con2;
64 65 66 67

# Wait for the the tables to be renamed
# i.e the query below succeds
let $query= select * from t2, t4;
68
source include/wait_for_query_to_succeed.inc;
69

unknown's avatar
unknown committed
70 71 72
show tables;

drop table t2, t4;
73

74 75 76 77
disconnect con2;
disconnect con1;
connection default;

78

unknown's avatar
unknown committed
79
--echo End of 4.1 tests
80 81


82 83 84 85 86 87
#
# Bug#14959: ALTER TABLE isn't able to rename a view
#
create table t1(f1 int);
create view v1 as select * from t1;
alter table v1 rename to v2;
88
--error ER_NO_SUCH_TABLE
89 90
alter table v1 rename to v2;
rename table v2 to v1;
91
--error ER_TABLE_EXISTS_ERROR
92 93 94
rename table v2 to v1;
drop view v1;
drop table t1;
95 96

--echo End of 5.0 tests
97 98 99

--source include/wait_until_count_sessions.inc