~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/auto_increment.test

  • Committer: Monty Taylor
  • Date: 2009-06-08 13:39:05 UTC
  • mto: This revision was merged to the branch mainline in revision 1060.
  • Revision ID: mordred@inaugust.com-20090608133905-3hogrrafmfg6e5hs
Removed CHARSET_INFO stuff from protocol plugin interface - it makes no sense.

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