~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/auto_increment.test

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

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
 
#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;
 
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;
66
65
 
67
66
#
68
67
# Test of auto_increment columns when they are set to 0
94
93
insert into t1 values (NULL);
95
94
select * from t1;
96
95
drop table t1;
 
96
#
 
97
# 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;
97
111
 
98
112
create table t1 (i int not null auto_increment, key (i));
99
113
insert into t1 set i = 254;
114
128
 
115
129
drop table t1;
116
130
 
117
 
#SQL_MODE was removed from Drizzle.
118
131
create table t1(a int auto_increment,b int null,primary key(a));
119
 
#SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
 
132
SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
120
133
insert into t1(a,b)values(NULL,1);
121
134
insert into t1(a,b)values(200,2);
122
135
insert into t1(a,b)values(0,3);
125
138
insert into t1(b)values(6);
126
139
insert into t1(b)values(7);
127
140
select * from t1 order by b;
128
 
#mediumint is not supported. changed to b int.
129
 
alter table t1 modify b int;
 
141
alter table t1 modify b mediumint;
130
142
select * from t1 order by b;
131
143
create table t2 (a int);
132
144
insert t2 values (1),(2);
140
152
--error 1048
141
153
update t1 set a=NULL where b=6;
142
154
update t1 set a=300 where b=7;
143
 
#SQL_MODE var is not supported.
144
 
#SET SQL_MODE='';
 
155
SET SQL_MODE='';
145
156
insert into t1(a,b)values(NULL,8);
146
157
insert into t1(a,b)values(400,9);
147
158
insert into t1(a,b)values(0,10);
177
188
drop table t1;
178
189
 
179
190
# We still should be able to preserve zero in NO_AUTO_VALUE_ON_ZERO mode
180
 
#create table t1 (a bigint);
181
 
#insert into t1 values (0), (1), (2), (3);
182
 
 
183
 
#sql_mode not supported
184
 
#set sql_mode=NO_AUTO_VALUE_ON_ZERO;
185
 
 
186
 
# Bug314567 -  ALTER TABLE causes auto_increment resequencing,
187
 
# resulting in duplicate entry since sql_mode=NO_AUTO_VALUE_ON_ZERO
188
 
#is not supported.
189
 
 
190
 
#alter table t1 modify a bigint not null auto_increment primary key; 
191
 
#set sql_mode= '';
192
 
#select * from t1;
193
 
#drop table t1;
 
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;
194
198
 
195
199
# It also sensible to preserve zeroes if we are converting auto_increment
196
200
# column to auto_increment column (or not touching it at all, which is more
197
201
# common case probably)
198
202
create table t1 (a int auto_increment primary key , b int null);
199
 
#sql_mode is not supported.
200
 
#set sql_mode=NO_AUTO_VALUE_ON_ZERO;
201
 
#insert into t1 values (0,1),(1,2),(2,3);
202
 
#select * from t1;
203
 
#set sql_mode= '';
 
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= '';
204
207
alter table t1 modify b varchar(255);
205
208
insert into t1 values (0,4);
206
209
select * from t1;
219
222
DROP TABLE IF EXISTS t1;
220
223
 
221
224
# BUG #19025:
222
 
#changed syntax of int(10) to int
223
 
CREATE TABLE t1 (
 
225
 
 
226
CREATE TABLE `t1` (
224
227
    t1_name VARCHAR(255) DEFAULT NULL,
225
 
    t1_id INT not null AUTO_INCREMENT,
 
228
    t1_id INT(10) NOT NULL AUTO_INCREMENT,
226
229
    KEY (t1_name),
227
230
    PRIMARY KEY (t1_id)
228
231
) AUTO_INCREMENT = 1000;
259
262
#
260
263
# Bug #11080 & #11005  Multi-row REPLACE fails on a duplicate key error
261
264
262
 
#changed syntax of int (11) to int
263
 
CREATE TABLE t1 ( `a` int NOT NULL auto_increment, `b` int default NULL,PRIMARY KEY  (`a`),UNIQUE KEY `b` (`b`));
 
265
 
 
266
CREATE TABLE t1 ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL,PRIMARY KEY  (`a`),UNIQUE KEY `b` (`b`));
264
267
insert into t1 (b) values (1);
265
268
replace into t1 (b) values (2), (1), (3);
266
269
select * from t1;
283
286
 
284
287
#
285
288
# Test that update changes internal auto-increment value
286
 
# Bug 314570 
 
289
#
287
290
 
288
 
#create table t1 (a int not null auto_increment primary key, val int);
289
 
#insert into t1 (val) values (1);
290
 
#update t1 set a=2 where a=1;
291
 
#insert into t1 (val) values (1);
292
 
#select * from t1;
293
 
#drop table t1;
 
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;
294
297
 
295
298
#
296
299
# Test key duplications with auto-increment in ALTER TABLE
297
300
# bug #14573
298
301
#
299
 
#changed syntax of int(11) to int.
300
 
CREATE TABLE t1 (t1 INT PRIMARY KEY, t2 INT);
 
302
CREATE TABLE t1 (t1 INT(10) PRIMARY KEY, t2 INT(10));
301
303
INSERT INTO t1 VALUES(0, 0);
302
304
INSERT INTO t1 VALUES(1, 1);
303
305
--error ER_DUP_ENTRY
304
 
ALTER TABLE t1 CHANGE t1 t1 INT auto_increment;
 
306
ALTER TABLE t1 CHANGE t1 t1 INT(10) auto_increment;
305
307
DROP TABLE t1;
306
308
 
307
309
# Test of REPLACE when it does INSERT+DELETE and not UPDATE: