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