~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# Test of auto_increment;  The test for BDB tables is in bdb.test
3
#
4
--disable_warnings
5
drop table if exists t1;
6
drop table if exists t2;
7
--enable_warnings
8
SET SQL_WARNINGS=1;
9
10
create table t1 (a int not null auto_increment,b int, primary key (a)) engine=myisam auto_increment=3;
11
insert into t1 values (1,1),(NULL,3),(NULL,4);
12
delete from t1 where a=4;
13
insert into t1 values (NULL,5),(NULL,6);
14
select * from t1;
15
delete from t1 where a=6;
16
#show table status like "t1";
17
replace t1 values (3,1);
18
ALTER TABLE t1 add c int;
19
replace t1 values (3,3,3);
20
insert into t1 values (NULL,7,7);
21
update t1 set a=8,b=b+1,c=c+1 where a=7;
22
insert into t1 values (NULL,9,9);
23
select * from t1;
24
drop table t1;
25
26
create table t1 (
27
  skey tinyint unsigned NOT NULL auto_increment PRIMARY KEY,
28
  sval char(20)
29
);
30
insert into t1 values (NULL, "hello");
31
insert into t1 values (NULL, "hey");
32
select * from t1;
33
select _rowid,t1._rowid,skey,sval from t1;
34
drop table t1;
35
36
#
37
# Test auto_increment on sub key
38
#
39
create table t1 (a char(10) not null, b int not null auto_increment, primary key(a,b));
40
insert into t1 values ("a",1),("b",2),("a",2),("c",1);
41
insert into t1 values ("a",NULL),("b",NULL),("c",NULL),("e",NULL);
42
insert into t1 (a) values ("a"),("b"),("c"),("d");
43
insert into t1 (a) values ('k'),('d');
44
insert into t1 (a) values ("a");
45
insert into t1 values ("d",last_insert_id());
46
select * from t1;
47
drop table t1;
48
49
create table t1 (ordid int(8) not null auto_increment, ord  varchar(50) not null, primary key (ordid), index(ord,ordid)); 
50
insert into t1 (ordid,ord) values (NULL,'sdj'),(NULL,'sdj');
51
select * from t1;
52
drop table t1;
53
54
create table t1 (ordid int(8) not null auto_increment, ord  varchar(50) not null, primary key (ord,ordid));
55
insert into t1 values (NULL,'sdj'),(NULL,'sdj'),(NULL,"abc"),(NULL,'abc'),(NULL,'zzz'),(NULL,'sdj'),(NULL,'abc');
56
select * from t1;
57
drop table t1;
58
59
create table t1 (sid char(5), id int(2) NOT NULL auto_increment, key(sid,  id));
60
create table t2 (sid char(20), id int(2));
61
insert into t2 values ('skr',NULL),('skr',NULL),('test',NULL);
62
insert into t1 select * from t2;
63
select * from t1;
64
drop table t1,t2;
65
66
#
67
# Test of auto_increment columns when they are set to 0
68
#
69
70
create table t1 (a int not null primary key auto_increment);
71
insert into t1 values (0);
72
update t1 set a=0;
73
select * from t1;
74
check table t1;
75
drop table t1;
76
77
#
78
# Test negative values (Bug #1366)
79
#
80
81
create table t1 (a int not null auto_increment primary key);
82
insert into t1 values (NULL);
83
insert into t1 values (-1);
84
select last_insert_id();
85
insert into t1 values (NULL);
86
select * from t1;
87
drop table t1;
88
89
create table t1 (a int not null auto_increment primary key) /*!40102 engine=heap */;
90
insert into t1 values (NULL);
91
insert into t1 values (-1);
92
select last_insert_id();
93
insert into t1 values (NULL);
94
select * from t1;
95
drop table t1;
96
#
97
# last_insert_id() madness
98
#
99
create table t1 (i tinyint unsigned not null auto_increment primary key);
100
insert into t1 set i = 254;
101
insert into t1 set i = null;
102
select last_insert_id();
103
explain extended select last_insert_id();
104
--error ER_DUP_ENTRY
105
insert into t1 set i = 254;
106
select last_insert_id();
107
--error ER_DUP_ENTRY
108
insert into t1 set i = null;
109
select last_insert_id();
110
drop table t1;
111
112
create table t1 (i tinyint unsigned not null auto_increment, key (i));
113
insert into t1 set i = 254;
114
insert into t1 set i = null;
115
select last_insert_id();
116
insert into t1 set i = null;
117
select last_insert_id();
118
drop table t1;
119
120
create table t1 (i tinyint unsigned not null auto_increment primary key, b int, unique (b));
121
insert into t1 values (NULL, 10);
122
select last_insert_id();
123
insert into t1 values (NULL, 15);
124
select last_insert_id();
125
--error ER_DUP_ENTRY
126
insert into t1 values (NULL, 10);
127
select last_insert_id();
128
129
drop table t1;
130
131
create table t1(a int auto_increment,b int null,primary key(a));
132
SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
133
insert into t1(a,b)values(NULL,1);
134
insert into t1(a,b)values(200,2);
135
insert into t1(a,b)values(0,3);
136
insert into t1(b)values(4);
137
insert into t1(b)values(5);
138
insert into t1(b)values(6);
139
insert into t1(b)values(7);
140
select * from t1 order by b;
141
alter table t1 modify b mediumint;
142
select * from t1 order by b;
143
create table t2 (a int);
144
insert t2 values (1),(2);
145
alter table t2 add b int auto_increment primary key;
146
select * from t2;
147
drop table t2;
148
delete from t1 where a=0;
149
update t1 set a=0 where b=5;
150
select * from t1 order by b;
151
delete from t1 where a=0;
152
--error 1048
153
update t1 set a=NULL where b=6;
154
update t1 set a=300 where b=7;
155
SET SQL_MODE='';
156
insert into t1(a,b)values(NULL,8);
157
insert into t1(a,b)values(400,9);
158
insert into t1(a,b)values(0,10);
159
insert into t1(b)values(11);
160
insert into t1(b)values(12);
161
insert into t1(b)values(13);
162
insert into t1(b)values(14);
163
select * from t1 order by b;
164
delete from t1 where a=0;
165
update t1 set a=0 where b=12;
166
select * from t1 order by b;
167
delete from t1 where a=0;
168
--error 1048
169
update t1 set a=NULL where b=13;
170
update t1 set a=500 where b=14;
171
select * from t1 order by b;
172
drop table t1;
173
174
#
175
# Test of behavior of ALTER TABLE when coulmn containing NULL or zeroes is
176
# converted to AUTO_INCREMENT column
177
#
178
create table t1 (a bigint);
179
insert into t1 values (1), (2), (3), (NULL), (NULL);
180
alter table t1 modify a bigint not null auto_increment primary key; 
181
select * from t1;
182
drop table t1;
183
184
create table t1 (a bigint);
185
insert into t1 values (1), (2), (3), (0), (0);
186
alter table t1 modify a bigint not null auto_increment primary key; 
187
select * from t1;
188
drop table t1;
189
190
# We still should be able to preserve zero in NO_AUTO_VALUE_ON_ZERO mode
191
create table t1 (a bigint);
192
insert into t1 values (0), (1), (2), (3);
193
set sql_mode=NO_AUTO_VALUE_ON_ZERO;
194
alter table t1 modify a bigint not null auto_increment primary key; 
195
set sql_mode= '';
196
select * from t1;
197
drop table t1;
198
199
# It also sensible to preserve zeroes if we are converting auto_increment
200
# column to auto_increment column (or not touching it at all, which is more
201
# common case probably)
202
create table t1 (a int auto_increment primary key , b int null);
203
set sql_mode=NO_AUTO_VALUE_ON_ZERO;
204
insert into t1 values (0,1),(1,2),(2,3);
205
select * from t1;
206
set sql_mode= '';
207
alter table t1 modify b varchar(255);
208
insert into t1 values (0,4);
209
select * from t1;
210
drop table t1;
211
212
#
213
# BUG #10045: Problem with composite AUTO_INCREMENT + BLOB key
214
215
CREATE TABLE t1 ( a INT AUTO_INCREMENT, b BLOB, PRIMARY KEY (a,b(10)));
216
INSERT INTO t1 (b) VALUES ('aaaa');
217
CHECK TABLE t1;
218
INSERT INTO t1 (b) VALUES ('');
219
CHECK TABLE t1;
220
INSERT INTO t1 (b) VALUES ('bbbb');
221
CHECK TABLE t1;
222
DROP TABLE IF EXISTS t1;
223
224
# BUG #19025:
225
226
CREATE TABLE `t1` (
227
    t1_name VARCHAR(255) DEFAULT NULL,
228
    t1_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
229
    KEY (t1_name),
230
    PRIMARY KEY (t1_id)
231
) AUTO_INCREMENT = 1000;
232
233
INSERT INTO t1 (t1_name) VALUES('MySQL');
234
INSERT INTO t1 (t1_name) VALUES('MySQL');
235
INSERT INTO t1 (t1_name) VALUES('MySQL');
236
237
SELECT * from t1;
238
239
SHOW CREATE TABLE `t1`;
240
241
DROP TABLE `t1`;
242
243
#
244
# Bug #6880: LAST_INSERT_ID() within a statement
245
#
246
247
create table t1(a int not null auto_increment primary key);              
248
create table t2(a int not null auto_increment primary key, t1a int);     
249
insert into t1 values(NULL);
250
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
251
insert into t1 values (NULL);
252
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
253
(NULL, LAST_INSERT_ID());
254
insert into t1 values (NULL);                                            
255
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
256
(NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
257
select * from t2;
258
drop table t1, t2;
259
260
--echo End of 4.1 tests
261
262
#
263
# Bug #11080 & #11005  Multi-row REPLACE fails on a duplicate key error
264
# 
265
266
CREATE TABLE t1 ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL,PRIMARY KEY  (`a`),UNIQUE KEY `b` (`b`));
267
insert into t1 (b) values (1);
268
replace into t1 (b) values (2), (1), (3);
269
select * from t1;
270
truncate table t1;
271
insert into t1 (b) values (1);
272
replace into t1 (b) values (2);
273
replace into t1 (b) values (1);
274
replace into t1 (b) values (3);
275
select * from t1;
276
drop table t1;
277
278
create table t1 (rowid int not null auto_increment, val int not null,primary
279
key (rowid), unique(val));
280
replace into t1 (val) values ('1'),('2');
281
replace into t1 (val) values ('1'),('2');
282
--error ER_DUP_ENTRY
283
insert into t1 (val) values ('1'),('2');
284
select * from t1;
285
drop table t1;
286
287
#
288
# Test that update changes internal auto-increment value
289
#
290
291
create table t1 (a int not null auto_increment primary key, val int);
292
insert into t1 (val) values (1);
293
update t1 set a=2 where a=1;
294
insert into t1 (val) values (1);
295
select * from t1;
296
drop table t1;
297
298
#
299
# Test key duplications with auto-increment in ALTER TABLE
300
# bug #14573
301
#
302
CREATE TABLE t1 (t1 INT(10) PRIMARY KEY, t2 INT(10));
303
INSERT INTO t1 VALUES(0, 0);
304
INSERT INTO t1 VALUES(1, 1);
305
--error ER_DUP_ENTRY
306
ALTER TABLE t1 CHANGE t1 t1 INT(10) auto_increment;
307
DROP TABLE t1;
308
309
# Test of REPLACE when it does INSERT+DELETE and not UPDATE:
310
# see if it sets LAST_INSERT_ID() ok
311
create table t1 (a int primary key auto_increment, b int, c int, d timestamp default current_timestamp, unique(b),unique(c));
312
insert into t1 values(null,1,1,now());
313
insert into t1 values(null,0,0,null);
314
# this will delete two rows
315
replace into t1 values(null,1,0,null);
316
select last_insert_id();
317
318
drop table t1;