~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/include/ps_modify.inc

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
###################### ps_modify.inc #########################
 
2
#                                                            #
 
3
#  Tests for prepared statements: INSERT/DELETE/UPDATE...    #
 
4
#                                                            #
 
5
##############################################################
 
6
 
 
7
#    
 
8
# NOTE: PLEASE SEE ps_1general.test (bottom) 
 
9
#       BEFORE ADDING NEW TEST CASES HERE !!!
 
10
 
 
11
#
 
12
# Please be aware, that this file will be sourced by several test case files
 
13
# stored within the subdirectory 't'. So every change here will affect 
 
14
# several test cases.
 
15
#
 
16
# Please do not modify the structure (DROP/ALTER..) of the tables
 
17
#     't1' and 't9'. 
 
18
#
 
19
# But you are encouraged to use these two tables within your statements
 
20
# (DELETE/UPDATE/...) whenever possible. 
 
21
#     t1  - very simple table
 
22
#     t9  - table with nearly all available column types
 
23
#
 
24
# The structure and the content of these tables can be found in
 
25
#     include/ps_create.inc  CREATE TABLE ...
 
26
#     include/ps_renew.inc   DELETE all rows and INSERT some rows
 
27
#
 
28
# Both tables are managed by the same storage engine.
 
29
# The type of the storage engine is stored in the variable '$type' . 
 
30
 
 
31
 
 
32
 
 
33
#------------------- Please insert your test cases here -------------------#
 
34
 
 
35
 
 
36
 
 
37
#-------- Please be very carefull when editing behind this line  ----------#
 
38
 
 
39
--disable_query_log
 
40
select '------ delete tests ------' as test_sequence ;
 
41
--enable_query_log
 
42
--source include/ps_renew.inc
 
43
 
 
44
## delete without parameter
 
45
prepare stmt1 from 'delete from t1 where a=2' ;
 
46
execute stmt1;
 
47
select a,b from t1 where a=2;
 
48
# delete with row not found
 
49
execute stmt1;
 
50
 
 
51
## delete with one parameter in the where clause
 
52
insert into t1 values(0,NULL);
 
53
set @arg00=NULL;
 
54
prepare stmt1 from 'delete from t1 where b=?' ;
 
55
execute stmt1 using @arg00;
 
56
select a,b from t1 where b is NULL ;
 
57
set @arg00='one';
 
58
execute stmt1 using @arg00;
 
59
select a,b from t1 where b=@arg00;
 
60
 
 
61
## truncate a table
 
62
prepare stmt1 from 'truncate table t1' ;
 
63
 
 
64
 
 
65
--disable_query_log
 
66
select '------ update tests ------' as test_sequence ;
 
67
--enable_query_log
 
68
--source include/ps_renew.inc
 
69
 
 
70
## update without parameter
 
71
prepare stmt1 from 'update t1 set b=''a=two'' where a=2' ;
 
72
execute stmt1;
 
73
select a,b from t1 where a=2;
 
74
# dummy update
 
75
execute stmt1;
 
76
select a,b from t1 where a=2;
 
77
 
 
78
## update with one parameter in the set clause
 
79
set @arg00=NULL;
 
80
prepare stmt1 from 'update t1 set b=? where a=2' ;
 
81
execute stmt1 using @arg00;
 
82
select a,b from t1 where a=2;
 
83
set @arg00='two';
 
84
execute stmt1 using @arg00;
 
85
select a,b from t1 where a=2;
 
86
 
 
87
## update with one parameter in the where cause
 
88
set @arg00=2;
 
89
prepare stmt1 from 'update t1 set b=NULL where a=?' ;
 
90
execute stmt1 using @arg00;
 
91
select a,b from t1 where a=@arg00;
 
92
update t1 set b='two' where a=@arg00;
 
93
# row not found in update
 
94
set @arg00=2000;
 
95
execute stmt1 using @arg00;
 
96
select a,b from t1 where a=@arg00;
 
97
 
 
98
## update on primary key column (two parameters)
 
99
set @arg00=2;
 
100
set @arg01=22;
 
101
prepare stmt1 from 'update t1 set a=? where a=?' ;
 
102
# dummy update
 
103
execute stmt1 using @arg00, @arg00;
 
104
select a,b from t1 where a=@arg00;
 
105
execute stmt1 using @arg01, @arg00;
 
106
select a,b from t1 where a=@arg01;
 
107
execute stmt1 using @arg00, @arg01;
 
108
select a,b from t1 where a=@arg00;
 
109
set @arg00=NULL;
 
110
set @arg01=2;
 
111
execute stmt1 using @arg00, @arg01;
 
112
select a,b from t1 order by a;
 
113
set @arg00=0;
 
114
execute stmt1 using @arg01, @arg00;
 
115
select a,b from t1 order by a;
 
116
 
 
117
## update with subquery and several parameters
 
118
set @arg00=23;
 
119
set @arg01='two';
 
120
set @arg02=2;
 
121
set @arg03='two';
 
122
set @arg04=2;
 
123
--disable_warnings
 
124
drop table if exists t2;
 
125
--enable_warnings
 
126
# t2 will be of table type 'MYISAM'
 
127
create table t2 as select a,b from t1 ;
 
128
prepare stmt1 from 'update t1 set a=? where b=?
 
129
                    and a in (select ? from t2
 
130
                              where b = ? or a = ?)';
 
131
--enable_info
 
132
execute stmt1 using @arg00, @arg01, @arg02, @arg03, @arg04 ;
 
133
--disable_info
 
134
select a,b from t1 where a = @arg00 ;
 
135
prepare stmt1 from 'update t1 set a=? where b=?
 
136
                    and a not in (select ? from t2
 
137
                              where b = ? or a = ?)';
 
138
--enable_info
 
139
execute stmt1 using @arg04, @arg01, @arg02, @arg03, @arg00 ;
 
140
--disable_info
 
141
select a,b from t1 order by a ;
 
142
drop table t2 ;
 
143
# t2 is now of table type '$type'
 
144
# The test battery for table type 'MERGE' gets here only a 'MYISAM' table
 
145
#
 
146
# Test UPDATE with SUBQUERY in prepared mode
 
147
#
 
148
eval create table t2
 
149
(
 
150
  a int, b varchar(30),
 
151
  primary key(a)
 
152
) engine = $type ;
 
153
insert into t2(a,b) select a, b from t1 ;
 
154
prepare stmt1 from 'update t1 set a=? where b=?
 
155
                    and a in (select ? from t2
 
156
                              where b = ? or a = ?)';
 
157
--enable_info
 
158
execute stmt1 using @arg00, @arg01, @arg02, @arg03, @arg04 ;
 
159
--disable_info
 
160
select a,b from t1 where a = @arg00 ;
 
161
prepare stmt1 from 'update t1 set a=? where b=?
 
162
                    and a not in (select ? from t2
 
163
                              where b = ? or a = ?)';
 
164
--enable_info
 
165
execute stmt1 using @arg04, @arg01, @arg02, @arg03, @arg00 ;
 
166
--disable_info
 
167
select a,b from t1 order by a ;
 
168
drop table t2 ;
 
169
 
 
170
## update with parameters in limit
 
171
set @arg00=1;
 
172
prepare stmt1 from 'update t1 set b=''bla''
 
173
where a=2
 
174
limit 1';
 
175
execute stmt1 ;
 
176
select a,b from t1 where b = 'bla' ;
 
177
prepare stmt1 from 'update t1 set b=''bla'' where a=2 limit ?';
 
178
execute stmt1 using @arg00;
 
179
 
 
180
--disable_query_log
 
181
select '------ insert tests ------' as test_sequence ;
 
182
--enable_query_log
 
183
--source include/ps_renew.inc
 
184
 
 
185
## insert without parameter
 
186
prepare stmt1 from 'insert into t1 values(5, ''five'' )';
 
187
execute stmt1;
 
188
select a,b from t1 where a = 5;
 
189
 
 
190
## insert with one parameter in values part
 
191
set @arg00='six' ;
 
192
prepare stmt1 from 'insert into t1 values(6, ? )';
 
193
execute stmt1 using @arg00;
 
194
select a,b from t1 where b = @arg00;
 
195
# the second insert fails, because the first column is primary key
 
196
--error ER_DUP_ENTRY
 
197
execute stmt1 using @arg00;
 
198
set @arg00=NULL ;
 
199
prepare stmt1 from 'insert into t1 values(0, ? )';
 
200
execute stmt1 using @arg00;
 
201
select a,b from t1 where b is NULL;
 
202
 
 
203
## insert with two parameter in values part
 
204
set @arg00=8 ;
 
205
set @arg01='eight' ;
 
206
prepare stmt1 from 'insert into t1 values(?, ? )';
 
207
execute stmt1 using @arg00, @arg01 ;
 
208
select a,b from t1 where b = @arg01;
 
209
# cases derived from client_test.c: test_null()
 
210
set @NULL= null ;
 
211
set @arg00= 'abc' ;
 
212
# execute must fail, because first column is primary key (-> not null)
 
213
--error 1048
 
214
execute stmt1 using @NULL, @NULL ;
 
215
--error 1048
 
216
execute stmt1 using @NULL, @NULL ;
 
217
--error 1048
 
218
execute stmt1 using @NULL, @arg00 ;
 
219
--error 1048
 
220
execute stmt1 using @NULL, @arg00 ;
 
221
let $1 = 2;
 
222
while ($1)
 
223
{
 
224
  eval set @arg01= 10000 + $1 ;
 
225
  execute stmt1 using @arg01, @arg00 ;
 
226
  dec $1;
 
227
}
 
228
select * from t1 where a > 10000 order by a ;
 
229
delete from t1 where a > 10000 ;
 
230
let $1 = 2;
 
231
while ($1)
 
232
{
 
233
  eval set @arg01= 10000 + $1 ;
 
234
  execute stmt1 using @arg01, @NULL ;
 
235
  dec $1;
 
236
}
 
237
select * from t1 where a > 10000 order by a ;
 
238
delete from t1 where a > 10000 ;
 
239
let $1 = 10;
 
240
while ($1)
 
241
{
 
242
  eval set @arg01= 10000 + $1 ;
 
243
  execute stmt1 using @arg01, @arg01 ;
 
244
  dec $1;
 
245
}
 
246
select * from t1 where a > 10000 order by a ;
 
247
delete from t1 where a > 10000 ;
 
248
 
 
249
 
 
250
## insert with two rows in values part
 
251
set @arg00=81 ;
 
252
set @arg01='8-1' ;
 
253
set @arg02=82 ;
 
254
set @arg03='8-2' ;
 
255
prepare stmt1 from 'insert into t1 values(?,?),(?,?)';
 
256
execute stmt1 using @arg00, @arg01, @arg02, @arg03 ;
 
257
select a,b from t1 where a in (@arg00,@arg02) ;
 
258
 
 
259
## insert with two parameter in the set part
 
260
set @arg00=9 ;
 
261
set @arg01='nine' ;
 
262
prepare stmt1 from 'insert into t1 set a=?, b=? ';
 
263
execute stmt1 using @arg00, @arg01 ;
 
264
select a,b from t1 where a = @arg00 ;
 
265
 
 
266
## insert with parameters in the ON DUPLICATE KEY part 
 
267
set @arg00=6 ;
 
268
set @arg01=1 ;
 
269
prepare stmt1 from 'insert into t1 set a=?, b=''sechs''
 
270
                    on duplicate key update a=a + ?, b=concat(b,''modified'') ';
 
271
execute stmt1 using @arg00, @arg01;
 
272
select * from t1 order by a;
 
273
set @arg00=81 ;
 
274
set @arg01=1 ;
 
275
--error ER_DUP_ENTRY
 
276
execute stmt1 using @arg00, @arg01;
 
277
 
 
278
## insert, autoincrement column and ' SELECT LAST_INSERT_ID() '
 
279
# cases derived from client_test.c: test_bug3117()
 
280
--disable_warnings
 
281
drop table if exists t2 ;
 
282
--enable_warnings
 
283
# The test battery for table type 'MERGE' gets here only a 'MYISAM' table
 
284
eval create table t2 (id int auto_increment primary key) 
 
285
ENGINE= $type ;
 
286
prepare stmt1 from ' select last_insert_id() ' ;
 
287
insert into t2 values (NULL) ;
 
288
execute stmt1 ;
 
289
insert into t2 values (NULL) ;
 
290
# bug#3117
 
291
execute stmt1 ;
 
292
drop table t2 ;
 
293
 
 
294
## many parameters
 
295
set @1000=1000 ;
 
296
set @x1000_2="x1000_2" ;
 
297
set @x1000_3="x1000_3" ;
 
298
 
 
299
set @x1000="x1000" ;
 
300
set @1100=1100 ;
 
301
set @x1100="x1100" ;
 
302
set @100=100 ;
 
303
set @updated="updated" ;
 
304
insert into t1 values(1000,'x1000_1') ;
 
305
insert into t1 values(@1000,@x1000_2),(@1000,@x1000_3)
 
306
               on duplicate key update a = a + @100, b = concat(b,@updated) ;
 
307
select a,b from t1 where a >= 1000 order by a ;
 
308
delete from t1 where a >= 1000 ;
 
309
insert into t1 values(1000,'x1000_1') ;
 
310
prepare stmt1 from ' insert into t1 values(?,?),(?,?)
 
311
               on duplicate key update a = a + ?, b = concat(b,?) ';
 
312
execute stmt1 using @1000, @x1000_2, @1000, @x1000_3, @100, @updated ;
 
313
select a,b from t1 where a >= 1000 order by a ;
 
314
delete from t1 where a >= 1000 ;
 
315
insert into t1 values(1000,'x1000_1') ;
 
316
execute stmt1 using @1000, @x1000_2, @1100, @x1000_3, @100, @updated ;
 
317
select a,b from t1 where a >= 1000 order by a ;
 
318
delete from t1 where a >= 1000 ;
 
319
 
 
320
## replace
 
321
prepare stmt1 from ' replace into t1 (a,b) select 100, ''hundred'' ';
 
322
execute stmt1;
 
323
execute stmt1;
 
324
execute stmt1;
 
325
 
 
326
 
 
327
 
 
328
## multi table statements
 
329
--disable_query_log
 
330
select '------ multi table tests ------' as test_sequence ;
 
331
--enable_query_log
 
332
# cases derived from client_test.c: test_multi
 
333
delete from t1 ;
 
334
delete from t9 ;
 
335
insert into t1(a,b) values (1, 'one'), (2, 'two'), (3, 'three') ;
 
336
insert into t9 (c1,c21)
 
337
  values (1, 'one'), (2, 'two'), (3, 'three') ;
 
338
prepare stmt_delete from " delete t1, t9 
 
339
  from t1, t9 where t1.a=t9.c1 and t1.b='updated' ";
 
340
prepare stmt_update from " update t1, t9 
 
341
  set t1.b='updated', t9.c21='updated'
 
342
  where t1.a=t9.c1 and t1.a=? ";
 
343
prepare stmt_select1 from " select a, b from t1 order by a" ;
 
344
prepare stmt_select2 from " select c1, c21 from t9 order by c1" ;
 
345
set @arg00= 1 ;
 
346
let $1= 3 ;
 
347
while ($1)
 
348
{
 
349
  execute stmt_update using @arg00 ;
 
350
  execute stmt_delete ;
 
351
  execute stmt_select1 ;
 
352
  execute stmt_select2 ;
 
353
  set @arg00= @arg00 + 1 ;
 
354
  dec $1 ;
 
355
}
 
356