~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/auto_increment.test

  • Committer: Monty Taylor
  • Date: 2008-10-16 09:12:23 UTC
  • mto: (511.1.6 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016091223-17ngih0qu9vssjs3
We pass -Wunused-macros now!

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
--enable_warnings
8
8
SET SQL_WARNINGS=1;
9
9
 
10
 
create TEMPORARY table t1 (a int not null auto_increment,b int, primary key (a)) engine=myisam auto_increment=3;
 
10
create table t1 (a int not null auto_increment,b int, primary key (a)) engine=myisam auto_increment=3;
11
11
insert into t1 values (1,1),(NULL,3),(NULL,4);
12
12
delete from t1 where a=4;
13
13
insert into t1 values (NULL,5),(NULL,6);
14
14
select * from t1;
15
15
delete from t1 where a=6;
16
 
--replace_column 1 #  6 # 7 # 8 # 9 # 10 #
17
 
show table status like "t1";
 
16
#show table status like "t1";
18
17
replace t1 values (3,1);
19
18
ALTER TABLE t1 add c int;
20
19
replace t1 values (3,3,3);
37
36
#
38
37
# Test auto_increment on sub key
39
38
#
40
 
#Drizzle does not support auto_increment on sub key.
41
 
#create table t1 (a char(10) not null, b int not null auto_increment, primary key(b));
42
 
#insert into t1 values ("a",1),("b",2),("a",2),("c",1);
43
 
#insert into t1 values ("a",NULL),("b",NULL),("c",NULL),("e",NULL);
44
 
#insert into t1 (a) values ("a"),("b"),("c"),("d");
45
 
#insert into t1 (a) values ('k'),('d');
46
 
#insert into t1 (a) values ("a");
47
 
#insert into t1 values ("d",last_insert_id());
48
 
#select * from t1;
49
 
#drop table t1;
50
 
 
51
 
#create table t1 (ordid int(8) not null auto_increment, ord  varchar(50) not null, primary key (ordid), index(ord,ordid)); 
52
 
#insert into t1 (ordid,ord) values (NULL,'sdj'),(NULL,'sdj');
53
 
#select * from t1;
54
 
#drop table t1;
55
 
 
56
 
#create table t1 (ordid int(8) not null auto_increment, ord  varchar(50) not null, primary key (ord,ordid));
57
 
#insert into t1 values (NULL,'sdj'),(NULL,'sdj'),(NULL,"abc"),(NULL,'abc'),(NULL,'zzz'),(NULL,'sdj'),(NULL,'abc');
58
 
#select * from t1;
59
 
#drop table t1;
60
 
 
61
 
#create table t1 (sid char(5), id int(2) NOT NULL auto_increment, key(sid,  id));
62
 
#create table t2 (sid char(20), id int(2));
63
 
#insert into t2 values ('skr',NULL),('skr',NULL),('test',NULL);
64
 
#insert into t1 select * from t2;
65
 
#select * from t1;
66
 
#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;
67
65
 
68
66
#
69
67
# Test of auto_increment columns when they are set to 0
88
86
select * from t1;
89
87
drop table t1;
90
88
 
91
 
create temporary table t1 (a int not null auto_increment primary key) /*!40102 engine=MEMORY */;
 
89
create table t1 (a int not null auto_increment primary key) /*!40102 engine=heap */;
92
90
insert into t1 values (NULL);
93
91
insert into t1 values (-1);
94
92
select last_insert_id();
95
93
insert into t1 values (NULL);
96
94
select * from t1;
97
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;
98
111
 
99
112
create table t1 (i int not null auto_increment, key (i));
100
113
insert into t1 set i = 254;
116
129
drop table t1;
117
130
 
118
131
create table t1(a int auto_increment,b int null,primary key(a));
 
132
SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
119
133
insert into t1(a,b)values(NULL,1);
120
134
insert into t1(a,b)values(200,2);
121
135
insert into t1(a,b)values(0,3);
124
138
insert into t1(b)values(6);
125
139
insert into t1(b)values(7);
126
140
select * from t1 order by b;
127
 
#mediumint is not supported. changed to b int.
128
 
alter table t1 modify b int;
 
141
alter table t1 modify b mediumint;
129
142
select * from t1 order by b;
130
143
create table t2 (a int);
131
144
insert t2 values (1),(2);
136
149
update t1 set a=0 where b=5;
137
150
select * from t1 order by b;
138
151
delete from t1 where a=0;
139
 
--error ER_BAD_NULL_ERROR
 
152
--error 1048
140
153
update t1 set a=NULL where b=6;
141
154
update t1 set a=300 where b=7;
 
155
SET SQL_MODE='';
142
156
insert into t1(a,b)values(NULL,8);
143
157
insert into t1(a,b)values(400,9);
144
158
insert into t1(a,b)values(0,10);
151
165
update t1 set a=0 where b=12;
152
166
select * from t1 order by b;
153
167
delete from t1 where a=0;
154
 
--error ER_BAD_NULL_ERROR
 
168
--error 1048
155
169
update t1 set a=NULL where b=13;
156
170
update t1 set a=500 where b=14;
157
171
select * from t1 order by b;
169
183
 
170
184
create table t1 (a bigint);
171
185
insert into t1 values (1), (2), (3), (0), (0);
172
 
--error ER_DUP_ENTRY
173
186
alter table t1 modify a bigint not null auto_increment primary key; 
174
187
select * from t1;
175
188
drop table t1;
177
190
# We still should be able to preserve zero in NO_AUTO_VALUE_ON_ZERO mode
178
191
create table t1 (a bigint);
179
192
insert into t1 values (0), (1), (2), (3);
180
 
 
181
 
# Bug314567 -  ALTER TABLE causes auto_increment resequencing,
182
 
# resulting in duplicate entry since sql_mode=NO_AUTO_VALUE_ON_ZERO
183
 
#is not supported.
184
 
# NO_AUTO_VALUE_ON_ZERO is now default for Drizzle
185
 
 
 
193
set sql_mode=NO_AUTO_VALUE_ON_ZERO;
186
194
alter table t1 modify a bigint not null auto_increment primary key; 
187
 
#set sql_mode= '';
 
195
set sql_mode= '';
188
196
select * from t1;
189
197
drop table t1;
190
198
 
192
200
# column to auto_increment column (or not touching it at all, which is more
193
201
# common case probably)
194
202
create table t1 (a int auto_increment primary key , b int null);
195
 
#sql_mode is not supported.
196
 
#set sql_mode=NO_AUTO_VALUE_ON_ZERO;
 
203
set sql_mode=NO_AUTO_VALUE_ON_ZERO;
197
204
insert into t1 values (0,1),(1,2),(2,3);
198
205
select * from t1;
199
 
#set sql_mode= '';
 
206
set sql_mode= '';
200
207
alter table t1 modify b varchar(255);
201
 
--error ER_DUP_ENTRY
202
208
insert into t1 values (0,4);
203
209
select * from t1;
204
210
drop table t1;
216
222
DROP TABLE IF EXISTS t1;
217
223
 
218
224
# BUG #19025:
219
 
#changed syntax of int(10) to int
220
 
CREATE TABLE t1 (
 
225
 
 
226
CREATE TABLE `t1` (
221
227
    t1_name VARCHAR(255) DEFAULT NULL,
222
 
    t1_id INT not null AUTO_INCREMENT,
 
228
    t1_id INT(10) NOT NULL AUTO_INCREMENT,
223
229
    KEY (t1_name),
224
230
    PRIMARY KEY (t1_id)
225
231
) AUTO_INCREMENT = 1000;
256
262
#
257
263
# Bug #11080 & #11005  Multi-row REPLACE fails on a duplicate key error
258
264
259
 
#changed syntax of int (11) to int
260
 
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`));
261
267
insert into t1 (b) values (1);
262
268
replace into t1 (b) values (2), (1), (3);
263
269
select * from t1;
280
286
 
281
287
#
282
288
# Test that update changes internal auto-increment value
283
 
# Bug 314570 
 
289
#
284
290
 
285
 
#create table t1 (a int not null auto_increment primary key, val int);
286
 
#insert into t1 (val) values (1);
287
 
#update t1 set a=2 where a=1;
288
 
#insert into t1 (val) values (1);
289
 
#select * from t1;
290
 
#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;
291
297
 
292
298
#
293
299
# Test key duplications with auto-increment in ALTER TABLE
294
300
# bug #14573
295
301
#
296
 
#changed syntax of int(11) to int.
297
 
CREATE TABLE t1 (t1 INT PRIMARY KEY, t2 INT);
 
302
CREATE TABLE t1 (t1 INT(10) PRIMARY KEY, t2 INT(10));
298
303
INSERT INTO t1 VALUES(0, 0);
299
304
INSERT INTO t1 VALUES(1, 1);
300
 
ALTER TABLE t1 CHANGE t1 t1 INT auto_increment;
301
305
--error ER_DUP_ENTRY
302
 
INSERT INTO t1 VALUES(0,0);
 
306
ALTER TABLE t1 CHANGE t1 t1 INT(10) auto_increment;
303
307
DROP TABLE t1;
304
308
 
305
309
# Test of REPLACE when it does INSERT+DELETE and not UPDATE: