~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/read_only.test

  • Committer: Monty Taylor
  • Date: 2008-11-16 05:36:13 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116053613-bld4rqxhlkb49c02
Split out cache_row and type_holder.

Show diffs side-by-side

added added

removed removed

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