~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/auto_increment.test

  • Committer: Brian Aker
  • Date: 2009-01-08 22:47:46 UTC
  • mfrom: (642.1.77 drizzle-clean-code)
  • Revision ID: brian@tangent.org-20090108224746-b6l8m91ougralsh9
MergeĀ fromĀ Lee.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#
37
37
# Test auto_increment on sub key
38
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;
 
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;
65
66
 
66
67
#
67
68
# Test of auto_increment columns when they are set to 0
95
96
drop table t1;
96
97
#
97
98
# last_insert_id() madness
98
 
#
99
 
create table t1 (i int 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;
 
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;
111
113
 
112
114
create table t1 (i int not null auto_increment, key (i));
113
115
insert into t1 set i = 254;
128
130
 
129
131
drop table t1;
130
132
 
 
133
#SQL_MODE was removed from Drizzle.
131
134
create table t1(a int auto_increment,b int null,primary key(a));
132
 
SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
 
135
#SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
133
136
insert into t1(a,b)values(NULL,1);
134
137
insert into t1(a,b)values(200,2);
135
138
insert into t1(a,b)values(0,3);
138
141
insert into t1(b)values(6);
139
142
insert into t1(b)values(7);
140
143
select * from t1 order by b;
141
 
alter table t1 modify b mediumint;
 
144
#mediumint is not supported. changed to b int.
 
145
alter table t1 modify b int;
142
146
select * from t1 order by b;
143
147
create table t2 (a int);
144
148
insert t2 values (1),(2);
152
156
--error 1048
153
157
update t1 set a=NULL where b=6;
154
158
update t1 set a=300 where b=7;
155
 
SET SQL_MODE='';
 
159
#SQL_MODE var is not supported.
 
160
#SET SQL_MODE='';
156
161
insert into t1(a,b)values(NULL,8);
157
162
insert into t1(a,b)values(400,9);
158
163
insert into t1(a,b)values(0,10);
188
193
drop table t1;
189
194
 
190
195
# 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;
 
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;
198
210
 
199
211
# It also sensible to preserve zeroes if we are converting auto_increment
200
212
# column to auto_increment column (or not touching it at all, which is more
201
213
# common case probably)
202
214
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= '';
 
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= '';
207
220
alter table t1 modify b varchar(255);
208
221
insert into t1 values (0,4);
209
222
select * from t1;
222
235
DROP TABLE IF EXISTS t1;
223
236
 
224
237
# BUG #19025:
225
 
 
226
 
CREATE TABLE `t1` (
 
238
#changed syntax of int(10) to int
 
239
CREATE TABLE t1 (
227
240
    t1_name VARCHAR(255) DEFAULT NULL,
228
 
    t1_id INT(10) NOT NULL AUTO_INCREMENT,
 
241
    t1_id INT not null AUTO_INCREMENT,
229
242
    KEY (t1_name),
230
243
    PRIMARY KEY (t1_id)
231
244
) AUTO_INCREMENT = 1000;
262
275
#
263
276
# Bug #11080 & #11005  Multi-row REPLACE fails on a duplicate key error
264
277
265
 
 
266
 
CREATE TABLE t1 ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL,PRIMARY KEY  (`a`),UNIQUE KEY `b` (`b`));
 
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`));
267
280
insert into t1 (b) values (1);
268
281
replace into t1 (b) values (2), (1), (3);
269
282
select * from t1;
286
299
 
287
300
#
288
301
# Test that update changes internal auto-increment value
289
 
#
 
302
# Bug 314570 
290
303
 
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;
 
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;
297
310
 
298
311
#
299
312
# Test key duplications with auto-increment in ALTER TABLE
300
313
# bug #14573
301
314
#
302
 
CREATE TABLE t1 (t1 INT(10) PRIMARY KEY, t2 INT(10));
 
315
#changed syntax of int(11) to int.
 
316
CREATE TABLE t1 (t1 INT PRIMARY KEY, t2 INT);
303
317
INSERT INTO t1 VALUES(0, 0);
304
318
INSERT INTO t1 VALUES(1, 1);
305
319
--error ER_DUP_ENTRY
306
 
ALTER TABLE t1 CHANGE t1 t1 INT(10) auto_increment;
 
320
ALTER TABLE t1 CHANGE t1 t1 INT auto_increment;
307
321
DROP TABLE t1;
308
322
 
309
323
# Test of REPLACE when it does INSERT+DELETE and not UPDATE: