~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
--disable_warnings
2
DROP TABLE IF EXISTS t1, t2;
3
--enable_warnings
4
5
CREATE TABLE t1 (a INT, b INT, c INT, UNIQUE (A), UNIQUE(B));
6
INSERT t1 VALUES (1,2,10), (3,4,20);
7
INSERT t1 VALUES (5,6,30) ON DUPLICATE KEY UPDATE c=c+100;
1441 by Brian Aker
Fixing tests to work with PBXT.
8
--sorted_result
1 by brian
clean slate
9
SELECT * FROM t1;
10
INSERT t1 VALUES (5,7,40) ON DUPLICATE KEY UPDATE c=c+100;
1441 by Brian Aker
Fixing tests to work with PBXT.
11
--sorted_result
1 by brian
clean slate
12
SELECT * FROM t1;
13
INSERT t1 VALUES (8,4,50) ON DUPLICATE KEY UPDATE c=c+1000;
1441 by Brian Aker
Fixing tests to work with PBXT.
14
--sorted_result
1 by brian
clean slate
15
SELECT * FROM t1;
1441 by Brian Aker
Fixing tests to work with PBXT.
16
--sorted_result
1 by brian
clean slate
17
INSERT t1 VALUES (1,4,60) ON DUPLICATE KEY UPDATE c=c+10000;
1441 by Brian Aker
Fixing tests to work with PBXT.
18
--sorted_result
1 by brian
clean slate
19
SELECT * FROM t1;
20
-- error ER_DUP_ENTRY
21
INSERT t1 VALUES (1,9,70) ON DUPLICATE KEY UPDATE c=c+100000, b=4;
1441 by Brian Aker
Fixing tests to work with PBXT.
22
--sorted_result
1 by brian
clean slate
23
SELECT * FROM t1;
24
TRUNCATE TABLE t1;
25
INSERT t1 VALUES (1,2,10), (3,4,20);
26
INSERT t1 VALUES (5,6,30), (7,4,40), (8,9,60) ON DUPLICATE KEY UPDATE c=c+100;
1441 by Brian Aker
Fixing tests to work with PBXT.
27
--sorted_result
1 by brian
clean slate
28
SELECT * FROM t1;
29
INSERT t1 SET a=5 ON DUPLICATE KEY UPDATE b=0;
1441 by Brian Aker
Fixing tests to work with PBXT.
30
--sorted_result
1 by brian
clean slate
31
SELECT * FROM t1;
32
INSERT t1 VALUES (2,1,11), (7,4,40) ON DUPLICATE KEY UPDATE c=c+VALUES(a);
1441 by Brian Aker
Fixing tests to work with PBXT.
33
--sorted_result
1 by brian
clean slate
34
SELECT *, VALUES(a) FROM t1;
35
explain extended SELECT *, VALUES(a) FROM t1;
36
explain extended select * from t1 where values(a);
37
DROP TABLE t1;
38
39
#
40
# test for Bug #2709 "Affected Rows for ON DUPL.KEY undocumented, 
41
#                                                 perhaps illogical"
42
#
43
create table t1(a int primary key, b int);
44
insert into t1 values(1,1),(2,2),(3,3),(4,4),(5,5);
45
select * from t1;
46
47
--enable_info
48
insert into t1 values(4,14),(5,15),(6,16),(7,17),(8,18)
49
 on duplicate key update b=b+10;
50
--disable_info
51
52
select * from t1;
53
54
enable_info;
55
replace into t1 values(5,25),(6,26),(7,27),(8,28),(9,29);
56
disable_info;
57
1441 by Brian Aker
Fixing tests to work with PBXT.
58
--sorted_result
1 by brian
clean slate
59
select * from t1;
60
drop table t1;
61
62
# WorkLog #2274 - enable INSERT .. SELECT .. UPDATE syntax
63
# Same tests as beginning of this test except that insert source
64
# is a result from a select statement
65
#
66
CREATE TABLE t1 (a INT, b INT, c INT, UNIQUE (A), UNIQUE(B));
67
INSERT t1 VALUES (1,2,10), (3,4,20);
520.1.16 by Brian Aker
More test updates (one ulong fix)
68
INSERT t1 SELECT 5,6,30 ON DUPLICATE KEY UPDATE c=c+100;
1441 by Brian Aker
Fixing tests to work with PBXT.
69
--sorted_result
520.1.16 by Brian Aker
More test updates (one ulong fix)
70
SELECT * FROM t1;
71
INSERT t1 SELECT 5,7,40 ON DUPLICATE KEY UPDATE c=c+100;
1441 by Brian Aker
Fixing tests to work with PBXT.
72
--sorted_result
520.1.16 by Brian Aker
More test updates (one ulong fix)
73
SELECT * FROM t1;
74
INSERT t1 SELECT 8,4,50 ON DUPLICATE KEY UPDATE c=c+1000;
1441 by Brian Aker
Fixing tests to work with PBXT.
75
--sorted_result
520.1.16 by Brian Aker
More test updates (one ulong fix)
76
SELECT * FROM t1;
77
INSERT t1 SELECT 1,4,60 ON DUPLICATE KEY UPDATE c=c+10000;
1441 by Brian Aker
Fixing tests to work with PBXT.
78
--sorted_result
1 by brian
clean slate
79
SELECT * FROM t1;
80
-- error ER_DUP_ENTRY
520.1.16 by Brian Aker
More test updates (one ulong fix)
81
INSERT t1 SELECT 1,9,70 ON DUPLICATE KEY UPDATE c=c+100000, b=4;
1441 by Brian Aker
Fixing tests to work with PBXT.
82
--sorted_result
1 by brian
clean slate
83
SELECT * FROM t1;
84
TRUNCATE TABLE t1;
85
INSERT t1 VALUES (1,2,10), (3,4,20);
86
CREATE TABLE t2 (a INT, b INT, c INT, d INT);
87
# column names deliberately clash with columns in t1 (Bug#8147)
88
INSERT t2 VALUES (5,6,30,1), (7,4,40,1), (8,9,60,1);
89
INSERT t2 VALUES (2,1,11,2), (7,4,40,2);
90
INSERT t1 SELECT a,b,c FROM t2 WHERE d=1 ON DUPLICATE KEY UPDATE c=t1.c+100;
1441 by Brian Aker
Fixing tests to work with PBXT.
91
--sorted_result
1 by brian
clean slate
92
SELECT * FROM t1;
93
INSERT t1 SET a=5 ON DUPLICATE KEY UPDATE b=0;
1441 by Brian Aker
Fixing tests to work with PBXT.
94
--sorted_result
1 by brian
clean slate
95
SELECT * FROM t1;
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
96
--error ER_NON_UNIQ_ERROR
1 by brian
clean slate
97
INSERT t1 SELECT a,b,c FROM t2 WHERE d=2 ON DUPLICATE KEY UPDATE c=c+VALUES(a);
98
INSERT t1 SELECT a,b,c FROM t2 WHERE d=2 ON DUPLICATE KEY UPDATE c=t1.c+VALUES(t1.a);
1441 by Brian Aker
Fixing tests to work with PBXT.
99
--sorted_result
1 by brian
clean slate
100
SELECT *, VALUES(a) FROM t1;
101
DROP TABLE t1;
102
DROP TABLE t2;
103
104
#
105
# Bug#9725 - "disapearing query/hang" and "unknown error" with "on duplicate key update"
106
# INSERT INGORE...UPDATE gives bad error or breaks protocol.
107
#
1063.9.7 by Stewart Smith
insert_update test for MyISAM as temp table only: 1 open table twice, 1x can be myisam temp.
108
create table t1 (a int not null unique);
1 by brian
clean slate
109
insert into t1 values (1),(2);
110
insert ignore into t1 select 1 on duplicate key update a=2;
111
select * from t1;
112
insert ignore into t1 select a from t1 as t2 on duplicate key update a=t1.a+1 ;
113
select * from t1;
114
insert into t1 select 1 on duplicate key update a=2;
115
select * from t1;
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
116
--error ER_NON_UNIQ_ERROR
1 by brian
clean slate
117
insert into t1 select a from t1 on duplicate key update a=a+1 ;
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
118
--error ER_NON_UNIQ_ERROR
1 by brian
clean slate
119
insert ignore into t1 select a from t1 on duplicate key update a=t1.a+1 ;
120
drop table t1;
121
122
#
123
# Bug#10109 - INSERT .. SELECT ... ON DUPLICATE KEY UPDATE fails
124
# Bogus "Duplicate columns" error message
125
#
126
1063.9.7 by Stewart Smith
insert_update test for MyISAM as temp table only: 1 open table twice, 1x can be myisam temp.
127
CREATE TEMPORARY TABLE t1 (
520.1.16 by Brian Aker
More test updates (one ulong fix)
128
  a BIGINT NOT NULL DEFAULT 0,
1 by brian
clean slate
129
  PRIMARY KEY  (a)
130
) ENGINE=MyISAM;
131
132
INSERT INTO t1 ( a ) SELECT 0 ON DUPLICATE KEY UPDATE a = a + VALUES (a) ;
133
134
DROP TABLE t1;
135
136
#
137
# Bug#21555: incorrect behavior with INSERT ... ON DUPL KEY UPDATE and VALUES
138
#
139
140
141
# End of 4.1 tests
142
CREATE TABLE t1
143
(
520.1.16 by Brian Aker
More test updates (one ulong fix)
144
  a   BIGINT,
145
  b   BIGINT,
1 by brian
clean slate
146
  PRIMARY KEY (a)
147
);
148
149
INSERT INTO t1 VALUES (45, 1) ON DUPLICATE KEY UPDATE b =
150
  IF(VALUES(b) > t1.b, VALUES(b), t1.b);
151
SELECT * FROM t1;
152
INSERT INTO t1 VALUES (45, 2) ON DUPLICATE KEY UPDATE b =
153
  IF(VALUES(b) > t1.b, VALUES(b), t1.b);
154
SELECT * FROM t1;
155
INSERT INTO t1 VALUES (45, 1) ON DUPLICATE KEY UPDATE b = 
156
  IF(VALUES(b) > t1.b, VALUES(b), t1.b);
157
SELECT * FROM t1;
158
159
DROP TABLE t1;
160
161
#
162
# Bug#25831: Deficiencies in INSERT ... SELECT ... field name resolving.
163
#
164
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
165
--error ER_BAD_FIELD_ERROR
166
INSERT INTO t1 SELECT 1, j;
167
DROP TABLE t1;
168
169
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
170
CREATE TABLE t2 (a INT, b INT);
171
CREATE TABLE t3 (a INT, c INT);
172
INSERT INTO t1 SELECT 1, a FROM t2 NATURAL JOIN t3 
173
  ON DUPLICATE KEY UPDATE j= a;
174
DROP TABLE t1,t2,t3;
175
176
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
177
CREATE TABLE t2 (a INT);
178
INSERT INTO t1 VALUES (1, 1);
179
INSERT INTO t2 VALUES (1), (3);
180
--error ER_BAD_FIELD_ERROR
181
INSERT INTO t1 SELECT 1, COUNT(*) FROM t2 ON DUPLICATE KEY UPDATE j= a;
182
DROP TABLE t1,t2;
183
184
#
185
# Bug #26261: Missing default value isn't noticed in 
186
#   insert ... on duplicate key update
187
#
188
CREATE TABLE t1 (a INT PRIMARY KEY, b INT NOT NULL);
189
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
190
--error ER_NO_DEFAULT_FOR_FIELD
1 by brian
clean slate
191
INSERT INTO t1 (a) VALUES (1);
192
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
193
--error ER_NO_DEFAULT_FOR_FIELD
1 by brian
clean slate
194
INSERT INTO t1 (a) VALUES (1) ON DUPLICATE KEY UPDATE a = b;
195
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
196
--error ER_NO_DEFAULT_FOR_FIELD
1 by brian
clean slate
197
INSERT INTO t1 (a) VALUES (1) ON DUPLICATE KEY UPDATE b = b;
198
199
SELECT * FROM t1;
200
201
DROP TABLE t1;
202
203
#
204
# Bug#27033: 0 as LAST_INSERT_ID() after INSERT .. ON DUPLICATE if rows were
205
#            touched but not actually changed.
206
#
207
CREATE TABLE t1 (f1 INT AUTO_INCREMENT PRIMARY KEY,
208
                 f2 VARCHAR(5) NOT NULL UNIQUE);
209
INSERT t1 (f2) VALUES ('test') ON DUPLICATE KEY UPDATE f1 = LAST_INSERT_ID(f1);
210
SELECT LAST_INSERT_ID();
211
INSERT t1 (f2) VALUES ('test') ON DUPLICATE KEY UPDATE f1 = LAST_INSERT_ID(f1);
212
SELECT LAST_INSERT_ID();
213
DROP TABLE t1;
214
215
#
216
# Bug#23233: 0 as LAST_INSERT_ID() after INSERT .. ON DUPLICATE in the
217
#            NO_AUTO_VALUE_ON_ZERO mode.
218
#
219
CREATE TABLE `t1` (
520.1.16 by Brian Aker
More test updates (one ulong fix)
220
  `id` int PRIMARY KEY auto_increment,
1 by brian
clean slate
221
  `f1` varchar(10) NOT NULL UNIQUE
222
);
223
INSERT IGNORE INTO t1 (f1) VALUES ("test1")
224
	ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
225
INSERT IGNORE INTO t1 (f1) VALUES ("test1")
226
	ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
227
SELECT LAST_INSERT_ID();
228
SELECT * FROM t1;
229
INSERT IGNORE INTO t1 (f1) VALUES ("test2")
230
	ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
231
SELECT * FROM t1;
232
INSERT IGNORE INTO t1 (f1) VALUES ("test2")
233
	ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
234
SELECT LAST_INSERT_ID();
235
SELECT * FROM t1;
236
INSERT IGNORE INTO t1 (f1) VALUES ("test3")
237
	ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
238
SELECT LAST_INSERT_ID();
239
SELECT * FROM t1;
240
DROP TABLE t1;
241
CREATE TABLE `t1` (
520.1.16 by Brian Aker
More test updates (one ulong fix)
242
  `id` int PRIMARY KEY auto_increment,
1 by brian
clean slate
243
  `f1` varchar(10) NOT NULL UNIQUE
244
);
245
INSERT IGNORE INTO t1 (f1) VALUES ("test1")
246
	ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
247
SELECT LAST_INSERT_ID();
248
SELECT * FROM t1;
249
INSERT IGNORE INTO t1 (f1) VALUES ("test1"),("test4")
250
	ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
251
SELECT LAST_INSERT_ID();
252
SELECT * FROM t1;
253
DROP TABLE t1;
254
CREATE TABLE `t1` (
520.1.16 by Brian Aker
More test updates (one ulong fix)
255
  `id` int PRIMARY KEY auto_increment,
1 by brian
clean slate
256
  `f1` varchar(10) NOT NULL UNIQUE,
257
  tim1 timestamp default '2003-01-01 00:00:00' on update current_timestamp
258
);
259
INSERT INTO t1 (f1) VALUES ("test1");
260
SELECT id, f1 FROM t1;
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
261
REPLACE INTO t1 VALUES (null,"test1",null);
1 by brian
clean slate
262
SELECT id, f1 FROM t1;
263
DROP TABLE t1;
264
265
#
266
# Bug#27954: multi-row INSERT ... ON DUPLICATE with duplicated
267
# row at the first place into table with AUTO_INCREMENT and
268
# additional UNIQUE key.
269
#
270
CREATE TABLE t1 (
271
  id INT AUTO_INCREMENT PRIMARY KEY,
272
  c1 CHAR(1) UNIQUE KEY,
273
  cnt INT DEFAULT 1
274
);
275
INSERT INTO t1 (c1) VALUES ('A'), ('B'), ('C');
276
SELECT * FROM t1;
277
INSERT  INTO t1 (c1) VALUES ('A'), ('X'), ('Y'), ('Z')
278
  ON DUPLICATE KEY UPDATE cnt=cnt+1;
279
SELECT * FROM t1;
280
DROP TABLE t1;
281
282
#
283
# Bug#28000: INSERT IGNORE ... SELECT ... ON DUPLICATE
284
# with erroneous UPDATE: NOT NULL field with NULL value.
285
#
286
CREATE TABLE t1 (
287
  id INT AUTO_INCREMENT PRIMARY KEY,
288
  c1 INT NOT NULL,
289
  cnt INT DEFAULT 1
290
);
291
INSERT INTO t1 (id,c1) VALUES (1,10);
292
SELECT * FROM t1;
293
CREATE TABLE t2 (id INT, c1 INT);
294
INSERT INTO t2 VALUES (1,NULL), (2,2);
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
295
--error ER_BAD_NULL_ERROR
1 by brian
clean slate
296
INSERT INTO t1 (id,c1) SELECT 1,NULL
297
  ON DUPLICATE KEY UPDATE c1=NULL;
298
SELECT * FROM t1;
299
INSERT IGNORE INTO t1 (id,c1) SELECT 1,NULL
300
  ON DUPLICATE KEY UPDATE c1=NULL, cnt=cnt+1;
301
SELECT * FROM t1;
302
INSERT IGNORE INTO t1 (id,c1) SELECT * FROM t2
303
  ON DUPLICATE KEY UPDATE c1=NULL, cnt=cnt+1;
304
SELECT * FROM t1;
305
1119.4.13 by Stewart Smith
make insert_update test not leave tables behind
306
DROP TABLE t1,t2;
1 by brian
clean slate
307
308
#
309
# Bug#28904: INSERT .. ON DUPLICATE was silently updating rows when it
310
#            shouldn't.
311
#
312
create table t1(f1 int primary key,
313
 f2 timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP);
314
insert into t1(f1) values(1);
315
--replace_column 1 #
316
select @stamp1:=f2 from t1;
317
insert into t1(f1) values(1) on duplicate key update f1=1;
318
--replace_column 1 #
319
select @stamp2:=f2 from t1;
320
select if( @stamp1 = @stamp2, "correct", "wrong");
321
drop table t1;