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

5 6 7 8
# Test requires concurrent connections, which can't be tested on embedded
# server
-- source include/not_embedded.inc

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

15 16 17 18 19 20 21 22 23
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;
24

25
# The following should give errors
26 27 28 29 30 31
--error 1050,1050
rename table t1 to t2;
--error 1050,1050
rename table t1 to t1;
--error 1050,1050
rename table t3 to t4, t2 to t3, t1 to t2, t4 to t2;
32
show tables like "t_";
33 34 35 36
--error 1050,1050
rename table t3 to t1, t2 to t3, t1 to t2, t4 to t1;
--error 1017,1017
rename table t3 to t4, t5 to t3, t1 to t2, t4 to t1;
37 38 39 40

select * from t1;
select * from t2;
select * from t3;
41 42

# This should give a warning for t4
43
drop table if exists t1,t2,t3,t4;
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
44 45

#
46 47
# Bug #2397 RENAME TABLES is not blocked by
# FLUSH TABLES WITH READ LOCK
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#

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;
63 64 65
connection con1;
reap;
connection con2;
66 67 68 69 70 71

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

vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
72 73 74
show tables;

drop table t2, t4;
75

76 77 78 79
disconnect con2;
disconnect con1;
connection default;

80 81 82 83 84 85 86 87 88 89 90 91 92
#
# 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;
--error 1146
alter table v1 rename to v2;
rename table v2 to v1;
--error 1050
rename table v2 to v1;
drop view v1;
drop table t1;
93
# End of 4.1 tests