~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
drop table if exists t1;
2
drop table if exists t2;
3
SET SQL_WARNINGS=1;
4
create table t1 (a int not null auto_increment,b int, primary key (a)) engine=myisam auto_increment=3;
5
insert into t1 values (1,1),(NULL,3),(NULL,4);
6
delete from t1 where a=4;
7
insert into t1 values (NULL,5),(NULL,6);
8
select * from t1;
9
a	b
10
1	1
11
3	3
12
5	5
13
6	6
14
delete from t1 where a=6;
15
replace t1 values (3,1);
16
ALTER TABLE t1 add c int;
17
replace t1 values (3,3,3);
18
insert into t1 values (NULL,7,7);
19
update t1 set a=8,b=b+1,c=c+1 where a=7;
20
insert into t1 values (NULL,9,9);
21
select * from t1;
22
a	b	c
23
1	1	NULL
24
3	3	3
25
5	5	NULL
26
8	8	8
27
9	9	9
28
drop table t1;
29
create table t1 (
642.1.71 by Lee
merge with latest from the trunk
30
skey int NOT NULL auto_increment PRIMARY KEY,
1 by brian
clean slate
31
sval char(20)
32
);
33
insert into t1 values (NULL, "hello");
34
insert into t1 values (NULL, "hey");
35
select * from t1;
36
skey	sval
37
1	hello
38
2	hey
39
select _rowid,t1._rowid,skey,sval from t1;
40
_rowid	_rowid	skey	sval
41
1	1	1	hello
42
2	2	2	hey
43
drop table t1;
44
create table t1 (a int not null primary key auto_increment);
45
insert into t1 values (0);
46
update t1 set a=0;
47
select * from t1;
48
a
49
0
50
check table t1;
51
Table	Op	Msg_type	Msg_text
52
test.t1	check	status	OK
53
drop table t1;
54
create table t1 (a int not null auto_increment primary key);
55
insert into t1 values (NULL);
56
insert into t1 values (-1);
57
select last_insert_id();
58
last_insert_id()
59
1
60
insert into t1 values (NULL);
61
select * from t1;
62
a
63
-1
64
1
65
2
66
drop table t1;
67
create table t1 (a int not null auto_increment primary key) /*!40102 engine=heap */;
68
insert into t1 values (NULL);
69
insert into t1 values (-1);
70
select last_insert_id();
71
last_insert_id()
72
1
73
insert into t1 values (NULL);
74
select * from t1;
75
a
76
1
77
-1
78
2
79
drop table t1;
642.1.71 by Lee
merge with latest from the trunk
80
create table t1 (i int not null auto_increment, key (i));
81
insert into t1 set i = 254;
82
insert into t1 set i = null;
83
select last_insert_id();
84
last_insert_id()
85
255
86
insert into t1 set i = null;
87
select last_insert_id();
88
last_insert_id()
89
256
90
drop table t1;
91
create table t1 (i int not null auto_increment primary key, b int, unique (b));
1 by brian
clean slate
92
insert into t1 values (NULL, 10);
93
select last_insert_id();
94
last_insert_id()
95
1
96
insert into t1 values (NULL, 15);
97
select last_insert_id();
98
last_insert_id()
99
2
100
insert into t1 values (NULL, 10);
101
ERROR 23000: Duplicate entry '10' for key 'b'
102
select last_insert_id();
103
last_insert_id()
104
2
105
drop table t1;
106
create table t1(a int auto_increment,b int null,primary key(a));
107
insert into t1(a,b)values(NULL,1);
108
insert into t1(a,b)values(200,2);
109
insert into t1(a,b)values(0,3);
110
insert into t1(b)values(4);
111
insert into t1(b)values(5);
112
insert into t1(b)values(6);
113
insert into t1(b)values(7);
114
select * from t1 order by b;
115
a	b
116
1	1
117
200	2
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
118
0	3
119
201	4
120
202	5
121
203	6
122
204	7
642.1.71 by Lee
merge with latest from the trunk
123
alter table t1 modify b int;
1 by brian
clean slate
124
select * from t1 order by b;
125
a	b
126
1	1
127
200	2
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
128
0	3
129
201	4
130
202	5
131
203	6
132
204	7
1 by brian
clean slate
133
create table t2 (a int);
134
insert t2 values (1),(2);
135
alter table t2 add b int auto_increment primary key;
136
select * from t2;
137
a	b
138
1	1
139
2	2
140
drop table t2;
141
delete from t1 where a=0;
142
update t1 set a=0 where b=5;
143
select * from t1 order by b;
144
a	b
145
1	1
146
200	2
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
147
201	4
1 by brian
clean slate
148
0	5
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
149
203	6
150
204	7
1 by brian
clean slate
151
delete from t1 where a=0;
152
update t1 set a=NULL where b=6;
153
ERROR 23000: Column 'a' cannot be null
154
update t1 set a=300 where b=7;
155
insert into t1(a,b)values(NULL,8);
156
insert into t1(a,b)values(400,9);
157
insert into t1(a,b)values(0,10);
158
insert into t1(b)values(11);
159
insert into t1(b)values(12);
160
insert into t1(b)values(13);
161
insert into t1(b)values(14);
162
select * from t1 order by b;
163
a	b
164
1	1
165
200	2
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
166
201	4
167
203	6
1 by brian
clean slate
168
300	7
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
169
205	8
1 by brian
clean slate
170
400	9
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
171
0	10
172
401	11
173
402	12
174
403	13
175
404	14
1 by brian
clean slate
176
delete from t1 where a=0;
177
update t1 set a=0 where b=12;
178
select * from t1 order by b;
179
a	b
180
1	1
181
200	2
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
182
201	4
183
203	6
1 by brian
clean slate
184
300	7
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
185
205	8
1 by brian
clean slate
186
400	9
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
187
401	11
1 by brian
clean slate
188
0	12
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
189
403	13
190
404	14
1 by brian
clean slate
191
delete from t1 where a=0;
192
update t1 set a=NULL where b=13;
193
ERROR 23000: Column 'a' cannot be null
194
update t1 set a=500 where b=14;
195
select * from t1 order by b;
196
a	b
197
1	1
198
200	2
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
199
201	4
200
203	6
1 by brian
clean slate
201
300	7
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
202
205	8
1 by brian
clean slate
203
400	9
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
204
401	11
205
403	13
1 by brian
clean slate
206
500	14
207
drop table t1;
208
create table t1 (a bigint);
209
insert into t1 values (1), (2), (3), (NULL), (NULL);
210
alter table t1 modify a bigint not null auto_increment primary key;
211
select * from t1;
212
a
213
1
214
2
215
3
216
4
217
5
218
drop table t1;
219
create table t1 (a bigint);
220
insert into t1 values (1), (2), (3), (0), (0);
221
alter table t1 modify a bigint not null auto_increment primary key;
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
222
ERROR 23000: ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry '0' for key 'PRIMARY'
223
select * from t1;
224
a
225
1
226
2
227
3
228
0
229
0
230
drop table t1;
231
create table t1 (a bigint);
232
insert into t1 values (0), (1), (2), (3);
233
alter table t1 modify a bigint not null auto_increment primary key;
234
select * from t1;
235
a
236
0
237
1
238
2
239
3
1 by brian
clean slate
240
drop table t1;
241
create table t1 (a int auto_increment primary key , b int null);
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
242
insert into t1 values (0,1),(1,2),(2,3);
243
select * from t1;
244
a	b
245
0	1
246
1	2
247
2	3
1 by brian
clean slate
248
alter table t1 modify b varchar(255);
249
insert into t1 values (0,4);
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
250
ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
1 by brian
clean slate
251
select * from t1;
252
a	b
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
253
0	1
254
1	2
255
2	3
1 by brian
clean slate
256
drop table t1;
257
CREATE TABLE t1 ( a INT AUTO_INCREMENT, b BLOB, PRIMARY KEY (a,b(10)));
258
INSERT INTO t1 (b) VALUES ('aaaa');
259
CHECK TABLE t1;
260
Table	Op	Msg_type	Msg_text
261
test.t1	check	status	OK
262
INSERT INTO t1 (b) VALUES ('');
263
CHECK TABLE t1;
264
Table	Op	Msg_type	Msg_text
265
test.t1	check	status	OK
266
INSERT INTO t1 (b) VALUES ('bbbb');
267
CHECK TABLE t1;
268
Table	Op	Msg_type	Msg_text
269
test.t1	check	status	OK
270
DROP TABLE IF EXISTS t1;
642.1.71 by Lee
merge with latest from the trunk
271
CREATE TABLE t1 (
1 by brian
clean slate
272
t1_name VARCHAR(255) DEFAULT NULL,
642.1.71 by Lee
merge with latest from the trunk
273
t1_id INT not null AUTO_INCREMENT,
1 by brian
clean slate
274
KEY (t1_name),
275
PRIMARY KEY (t1_id)
276
) AUTO_INCREMENT = 1000;
642.1.71 by Lee
merge with latest from the trunk
277
Warnings:
278
Warning	1071	Specified key was too long; max key length is 767 bytes
1 by brian
clean slate
279
INSERT INTO t1 (t1_name) VALUES('MySQL');
280
INSERT INTO t1 (t1_name) VALUES('MySQL');
281
INSERT INTO t1 (t1_name) VALUES('MySQL');
282
SELECT * from t1;
283
t1_name	t1_id
284
MySQL	1000
285
MySQL	1001
286
MySQL	1002
287
SHOW CREATE TABLE `t1`;
288
Table	Create Table
289
t1	CREATE TABLE `t1` (
873.2.35 by Monty Taylor
Update tests based on how Toru's latest patch changes create table statements.
290
  `t1_name` varchar(255) DEFAULT NULL,
642.1.71 by Lee
merge with latest from the trunk
291
  `t1_id` int NOT NULL AUTO_INCREMENT,
1 by brian
clean slate
292
  PRIMARY KEY (`t1_id`),
1008.3.10 by Stewart Smith
fix test result now that I fixed SHOW CREATE TABLE
293
  KEY `t1_name` (`t1_name`(191))
642.1.71 by Lee
merge with latest from the trunk
294
) ENGINE=InnoDB AUTO_INCREMENT=1003
1 by brian
clean slate
295
DROP TABLE `t1`;
296
create table t1(a int not null auto_increment primary key);
297
create table t2(a int not null auto_increment primary key, t1a int);
298
insert into t1 values(NULL);
299
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
300
insert into t1 values (NULL);
301
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
302
(NULL, LAST_INSERT_ID());
303
insert into t1 values (NULL);
304
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
305
(NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
306
select * from t2;
307
a	t1a
308
1	1
309
2	1
310
3	2
311
4	2
312
5	2
313
6	3
314
7	3
315
8	3
316
9	3
317
drop table t1, t2;
318
End of 4.1 tests
642.1.71 by Lee
merge with latest from the trunk
319
CREATE TABLE t1 ( `a` int NOT NULL auto_increment, `b` int default NULL,PRIMARY KEY  (`a`),UNIQUE KEY `b` (`b`));
1 by brian
clean slate
320
insert into t1 (b) values (1);
321
replace into t1 (b) values (2), (1), (3);
322
select * from t1;
323
a	b
642.1.71 by Lee
merge with latest from the trunk
324
2	2
1 by brian
clean slate
325
3	1
326
4	3
327
truncate table t1;
328
insert into t1 (b) values (1);
329
replace into t1 (b) values (2);
330
replace into t1 (b) values (1);
331
replace into t1 (b) values (3);
332
select * from t1;
333
a	b
642.1.71 by Lee
merge with latest from the trunk
334
2	2
1 by brian
clean slate
335
3	1
336
4	3
337
drop table t1;
338
create table t1 (rowid int not null auto_increment, val int not null,primary
339
key (rowid), unique(val));
340
replace into t1 (val) values ('1'),('2');
341
replace into t1 (val) values ('1'),('2');
342
insert into t1 (val) values ('1'),('2');
343
ERROR 23000: Duplicate entry '1' for key 'val'
344
select * from t1;
345
rowid	val
346
3	1
347
4	2
348
drop table t1;
642.1.71 by Lee
merge with latest from the trunk
349
CREATE TABLE t1 (t1 INT PRIMARY KEY, t2 INT);
1 by brian
clean slate
350
INSERT INTO t1 VALUES(0, 0);
351
INSERT INTO t1 VALUES(1, 1);
642.1.71 by Lee
merge with latest from the trunk
352
ALTER TABLE t1 CHANGE t1 t1 INT auto_increment;
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
353
INSERT INTO t1 VALUES(0,0);
354
ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
1 by brian
clean slate
355
DROP TABLE t1;
356
create table t1 (a int primary key auto_increment, b int, c int, d timestamp default current_timestamp, unique(b),unique(c));
357
insert into t1 values(null,1,1,now());
358
insert into t1 values(null,0,0,null);
359
replace into t1 values(null,1,0,null);
360
select last_insert_id();
361
last_insert_id()
362
3
363
drop table t1;