~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
# Test of the READ_ONLY global variable:
2
# check that it blocks updates unless they are only on temporary tables.
3
4
--disable_warnings
5
DROP TABLE IF EXISTS t1,t2,t3;
6
--enable_warnings
7
8
# READ_ONLY does nothing to SUPER users
9
# so we use a non-SUPER one:
10
11
grant CREATE, SELECT, DROP on *.* to test@localhost;
12
13
connect (con1,localhost,test,,test);
14
15
connection default;
16
17
set global read_only=0;
18
19
connection con1;
20
21
create table t1 (a int);
22
23
insert into t1 values(1);
24
25
create table t2 select * from t1;
26
27
connection default;
28
29
set global read_only=1;
30
31
# We check that SUPER can:
32
33
create table t3 (a int);
34
drop table t3;
35
36
connection con1;
37
38
select @@global.read_only;
39
40
--error 1290
41
create table t3 (a int);
42
43
--error 1290
44
insert into t1 values(1);
45
46
# if a statement, after parse stage, looks like it will update a
47
# non-temp table, it will be rejected, even if at execution it would
48
# have turned out that 0 rows would be updated
49
--error 1290
50
update t1 set a=1 where 1=0;
51
52
# multi-update is special (see sql_parse.cc) so we test it
53
--error 1290
54
update t1,t2 set t1.a=t2.a+1 where t1.a=t2.a;
55
56
# check multi-delete to be sure
57
--error 1290
58
delete t1,t2 from t1,t2 where t1.a=t2.a;
59
60
# With temp tables updates should be accepted:
61
62
create temporary table t3 (a int);
63
64
create temporary table t4 (a int) select * from t3;
65
66
insert into t3 values(1);
67
68
insert into t4 select * from t3;
69
70
# a non-temp table updated:
71
--error 1290
72
update t1,t3 set t1.a=t3.a+1 where t1.a=t3.a;
73
74
# no non-temp table updated (just swapped):
75
update t1,t3 set t3.a=t1.a+1 where t1.a=t3.a;
76
77
update t4,t3 set t4.a=t3.a+1 where t4.a=t3.a;
78
79
--error 1290
80
delete t1 from t1,t3 where t1.a=t3.a;
81
82
delete t3 from t1,t3 where t1.a=t3.a;
83
84
delete t4 from t3,t4 where t4.a=t3.a;
85
86
# and even homonymous ones
87
88
create temporary table t1 (a int);
89
90
insert into t1 values(1);
91
92
update t1,t3 set t1.a=t3.a+1 where t1.a=t3.a;
93
94
delete t1 from t1,t3 where t1.a=t3.a;
95
96
drop table t1;
97
98
--error 1290
99
insert into t1 values(1);
100
101
#
102
# BUG#11733: COMMITs should not happen if read-only is set
103
#
104
105
# LOCK TABLE ... WRITE / READ_ONLY
106
# - is an error in the same connection
107
# - is ok in a different connection
108
109
connection default;
110
set global read_only=0;
111
lock table t1 write;
112
113
connection con1;
114
lock table t2 write;
115
116
connection default;
117
--error ER_LOCK_OR_ACTIVE_TRANSACTION
118
set global read_only=1;
119
unlock tables ;
120
# The following call blocks until con1 releases the write lock.
121
# Blocking is expected.
122
send set global read_only=1;
123
124
connection con1;
125
--sleep 1
126
select @@global.read_only;
127
unlock tables ;
128
--sleep 1
129
select @@global.read_only;
130
131
connection default;
132
reap;
133
134
# LOCK TABLE ... READ / READ_ONLY
135
# - is an error in the same connection
136
# - is ok in a different connection
137
138
connection default;
139
set global read_only=0;
140
lock table t1 read;
141
142
connection con1;
143
lock table t2 read;
144
145
connection default;
146
--error ER_LOCK_OR_ACTIVE_TRANSACTION
147
set global read_only=1;
148
unlock tables ;
149
# The following call blocks until con1 releases the read lock.
150
# Blocking is a limitation, and could be improved.
151
send set global read_only=1;
152
153
connection con1;
154
--sleep 1
155
select @@global.read_only;
156
unlock tables ;
157
--sleep 1
158
select @@global.read_only;
159
160
connection default;
161
reap;
162
163
# pending transaction / READ_ONLY
164
# - is an error in the same connection
165
# - is ok in a different connection
166
167
connection default;
168
set global read_only=0;
169
BEGIN;
170
171
connection con1;
172
BEGIN;
173
174
connection default;
175
--error ER_LOCK_OR_ACTIVE_TRANSACTION
176
set global read_only=1;
177
ROLLBACK;
178
set global read_only=1;
179
180
connection con1;
181
select @@global.read_only;
182
ROLLBACK;
183
184
# Verify that FLUSH TABLES WITH READ LOCK do not block READ_ONLY
185
# - in the same SUPER connection
186
# - in another SUPER connection
187
188
connection default;
189
set global read_only=0;
190
flush tables with read lock;
191
set global read_only=1;
192
unlock tables;
193
194
connect (root2,localhost,root,,test);
195
196
connection default;
197
set global read_only=0;
198
flush tables with read lock;
199
200
connection root2;
201
set global read_only=1;
202
203
connection default;
204
select @@global.read_only;
205
unlock tables;
206
207
# BUG #22077 "DROP TEMPORARY TABLE fails with wrong error if read_only is set"
208
#
209
# check if DROP TEMPORARY on a non-existing temporary table returns the right
210
# error
211
212
--error ER_BAD_TABLE_ERROR
213
drop temporary table ttt;
214
215
# check if DROP TEMPORARY TABLE IF EXISTS produces a warning with read_only set
216
drop temporary table if exists ttt;
217
218
#
219
# Cleanup
220
#
221
connection default;
222
set global read_only=0;
223
drop table t1,t2;
224
drop user test@localhost;
225
--echo #
226
--echo # Bug #27440 read_only allows create and drop database
227
--echo #
228
set global read_only= 1;
229
--disable_warnings
230
drop database if exists mysqltest_db1;
231
drop database if exists mysqltest_db2;
232
--enable_warnings
233
234
delete from mysql.user where User like 'mysqltest_%';
235
delete from mysql.db where User like 'mysqltest_%';
236
delete from mysql.tables_priv where User like 'mysqltest_%';
237
delete from mysql.columns_priv where User like 'mysqltest_%';
238
flush privileges;
239
240
grant all on mysqltest_db2.* to `mysqltest_u1`@`%`;
241
create database mysqltest_db1;
242
grant all on mysqltest_db1.* to `mysqltest_u1`@`%`;
243
flush privileges;
244
connect (con_bug27440,127.0.0.1,mysqltest_u1,,test,$MASTER_MYPORT,);
245
connection con_bug27440;
246
--error ER_OPTION_PREVENTS_STATEMENT
247
create database mysqltest_db2;
248
show databases like '%mysqltest_db2%';
249
--error ER_OPTION_PREVENTS_STATEMENT
250
drop database mysqltest_db1;
251
disconnect con_bug27440;
252
connection default;
253
delete from mysql.user where User like 'mysqltest_%';
254
delete from mysql.db where User like 'mysqltest_%';
255
delete from mysql.tables_priv where User like 'mysqltest_%';
256
delete from mysql.columns_priv where User like 'mysqltest_%';
257
flush privileges;
258
drop database mysqltest_db1;
259
set global read_only=0;