mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / t / read_only.test
blobabc016bafce99217e28270f88dc114c5aed806ae
1 # Test of the READ_ONLY global variable:
2 # check that it blocks updates unless they are only on temporary tables.
4 # should work with embedded server after mysqltest is fixed
5 --source include/not_embedded.inc
7 set @start_read_only= @@global.read_only;
9 # Save the initial number of concurrent sessions
10 --source include/count_sessions.inc
12 --disable_warnings
13 DROP TABLE IF EXISTS t1,t2,t3;
14 --enable_warnings
16 # READ_ONLY does nothing to SUPER users
17 # so we use a non-SUPER one:
19 grant CREATE, SELECT, DROP on *.* to test@localhost;
21 --echo connect (con1,localhost,test,,test);
22 connect (con1,localhost,test,,test);
24 --echo connection default;
25 connection default;
27 set global read_only=0;
29 --echo connection con1;
30 connection con1;
32 create table t1 (a int);
34 insert into t1 values(1);
36 create table t2 select * from t1;
38 --echo connection default;
39 connection default;
41 set global read_only=1;
43 # We check that SUPER can:
45 create table t3 (a int);
46 drop table t3;
48 --echo connection con1;
49 connection con1;
51 select @@global.read_only;
53 --error ER_OPTION_PREVENTS_STATEMENT
54 create table t3 (a int);
56 --error ER_OPTION_PREVENTS_STATEMENT
57 insert into t1 values(1);
59 # if a statement, after parse stage, looks like it will update a
60 # non-temp table, it will be rejected, even if at execution it would
61 # have turned out that 0 rows would be updated
62 --error ER_OPTION_PREVENTS_STATEMENT
63 update t1 set a=1 where 1=0;
65 # multi-update is special (see sql_parse.cc) so we test it
66 --error ER_OPTION_PREVENTS_STATEMENT
67 update t1,t2 set t1.a=t2.a+1 where t1.a=t2.a;
69 # check multi-delete to be sure
70 --error ER_OPTION_PREVENTS_STATEMENT
71 delete t1,t2 from t1,t2 where t1.a=t2.a;
73 # With temp tables updates should be accepted:
75 create temporary table t3 (a int);
77 create temporary table t4 (a int) select * from t3;
79 insert into t3 values(1);
81 insert into t4 select * from t3;
83 # a non-temp table updated:
84 --error ER_OPTION_PREVENTS_STATEMENT
85 update t1,t3 set t1.a=t3.a+1 where t1.a=t3.a;
87 # no non-temp table updated (just swapped):
88 update t1,t3 set t3.a=t1.a+1 where t1.a=t3.a;
90 update t4,t3 set t4.a=t3.a+1 where t4.a=t3.a;
92 --error ER_OPTION_PREVENTS_STATEMENT
93 delete t1 from t1,t3 where t1.a=t3.a;
95 delete t3 from t1,t3 where t1.a=t3.a;
97 delete t4 from t3,t4 where t4.a=t3.a;
99 # and even homonymous ones
101 create temporary table t1 (a int);
103 insert into t1 values(1);
105 update t1,t3 set t1.a=t3.a+1 where t1.a=t3.a;
107 delete t1 from t1,t3 where t1.a=t3.a;
109 drop table t1;
111 --error ER_OPTION_PREVENTS_STATEMENT
112 insert into t1 values(1);
115 # Bug#11733 COMMITs should not happen if read-only is set
118 # LOCK TABLE ... WRITE / READ_ONLY
119 # - is an error in the same connection
120 # - is ok in a different connection
122 --echo connection default;
123 connection default;
124 set global read_only=0;
125 lock table t1 write;
127 --echo connection con1;
128 connection con1;
129 lock table t2 write;
131 --echo connection default;
132 connection default;
133 --error ER_LOCK_OR_ACTIVE_TRANSACTION
134 set global read_only=1;
135 unlock tables ;
136 # The following call blocks until con1 releases the write lock.
137 # Blocking is expected.
138 --echo send set global read_only=1;
139 send set global read_only=1;
141 --echo connection con1;
142 connection con1;
143 select @@global.read_only;
144 unlock tables ;
145 let $wait_condition= SELECT @@global.read_only= 1;
146 --source include/wait_condition.inc
147 select @@global.read_only;
149 --echo connection default;
150 connection default;
151 --echo reap;
152 reap;
154 # LOCK TABLE ... READ / READ_ONLY
155 # - is an error in the same connection
156 # - is ok in a different connection
158 --echo connection default;
159 connection default;
160 set global read_only=0;
161 lock table t1 read;
163 --echo connection con1;
164 connection con1;
165 lock table t2 read;
167 --echo connection default;
168 connection default;
169 --error ER_LOCK_OR_ACTIVE_TRANSACTION
170 set global read_only=1;
171 unlock tables ;
172 # The following call blocks until con1 releases the read lock.
173 # Blocking is a limitation, and could be improved.
174 --echo send set global read_only=1;
175 send set global read_only=1;
177 --echo connection con1;
178 connection con1;
179 select @@global.read_only;
180 unlock tables ;
181 let $wait_condition= SELECT @@global.read_only= 1;
182 --source include/wait_condition.inc
183 select @@global.read_only;
185 --echo connection default;
186 connection default;
187 --echo reap;
188 reap;
190 # pending transaction / READ_ONLY
191 # - is an error in the same connection
192 # - is ok in a different connection
194 --echo connection default;
195 connection default;
196 set global read_only=0;
197 BEGIN;
199 --echo connection con1;
200 connection con1;
201 BEGIN;
203 --echo connection default;
204 connection default;
205 --error ER_LOCK_OR_ACTIVE_TRANSACTION
206 set global read_only=1;
207 ROLLBACK;
209 set global read_only=1;
211 --echo connection con1;
212 connection con1;
213 select @@global.read_only;
214 ROLLBACK;
216 # Verify that FLUSH TABLES WITH READ LOCK do not block READ_ONLY
217 # - in the same SUPER connection
218 # - in another SUPER connection
220 --echo connection default;
221 connection default;
222 set global read_only=0;
223 flush tables with read lock;
224 set global read_only=1;
225 unlock tables;
227 --echo connect (root2,localhost,root,,test);
228 connect (root2,localhost,root,,test);
230 --echo connection default;
231 connection default;
232 set global read_only=0;
233 flush tables with read lock;
235 --echo connection root2;
236 connection root2;
237 set global read_only=1;
239 --echo connection default;
240 connection default;
241 select @@global.read_only;
242 unlock tables;
243 disconnect root2;
245 # Bug#22077 DROP TEMPORARY TABLE fails with wrong error if read_only is set
247 # check if DROP TEMPORARY on a non-existing temporary table returns the right
248 # error
250 --error ER_BAD_TABLE_ERROR
251 drop temporary table ttt;
253 # check if DROP TEMPORARY TABLE IF EXISTS produces a warning with read_only set
254 drop temporary table if exists ttt;
257 # Cleanup
259 --echo connection default;
260 connection default;
261 set global read_only=0;
262 disconnect con1;
263 drop table t1,t2;
264 drop user test@localhost;
266 --echo #
267 --echo # Bug#27440 read_only allows create and drop database
268 --echo #
269 set global read_only= 1;
270 --disable_warnings
271 drop database if exists mysqltest_db1;
272 drop database if exists mysqltest_db2;
273 --enable_warnings
275 delete from mysql.user where User like 'mysqltest_%';
276 delete from mysql.db where User like 'mysqltest_%';
277 delete from mysql.tables_priv where User like 'mysqltest_%';
278 delete from mysql.columns_priv where User like 'mysqltest_%';
279 flush privileges;
281 grant all on mysqltest_db2.* to `mysqltest_u1`@`%`;
282 create database mysqltest_db1;
283 grant all on mysqltest_db1.* to `mysqltest_u1`@`%`;
284 flush privileges;
285 --echo connect (con_bug27440,127.0.0.1,mysqltest_u1,,test,MASTER_MYPORT,);
286 connect (con_bug27440,127.0.0.1,mysqltest_u1,,test,$MASTER_MYPORT,);
287 --echo connection con_bug27440;
288 connection con_bug27440;
289 --error ER_OPTION_PREVENTS_STATEMENT
290 create database mysqltest_db2;
291 show databases like '%mysqltest_db2%';
292 --error ER_OPTION_PREVENTS_STATEMENT
293 drop database mysqltest_db1;
294 --echo disconnect con_bug27440;
295 disconnect con_bug27440;
296 --echo connection default;
297 connection default;
298 delete from mysql.user where User like 'mysqltest_%';
299 delete from mysql.db where User like 'mysqltest_%';
300 delete from mysql.tables_priv where User like 'mysqltest_%';
301 delete from mysql.columns_priv where User like 'mysqltest_%';
302 flush privileges;
303 drop database mysqltest_db1;
304 set global read_only= @start_read_only;
306 # Wait till all disconnects are completed
307 --source include/wait_until_count_sessions.inc