~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/auto_increment.test

  • Committer: Stewart Smith
  • Date: 2009-05-15 06:57:12 UTC
  • mto: (991.1.5 for-brian)
  • mto: This revision was merged to the branch mainline in revision 1022.
  • Revision ID: stewart@flamingspork.com-20090515065712-bmionylacjmexmmm
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.

Also fix DEFAULT keyword handling for auto-increment so that it defaults to
NULL and not 0 so that the following is valid and generates two auto-inc
values:

create table t1 (a int auto_increment primary key)
insert into t1 (a) values (default);
insert into t1 (a) values (default);

Important to note that 0 is no longer magic. So this gives you duplicate
primary key error:

insert into t1 (a) values(0);
insert into t1 (a) values(0);

as you've inserted the explicit value of 0 twice.

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
 
115
115
drop table t1;
116
116
 
117
 
#SQL_MODE was removed from Drizzle.
118
117
create table t1(a int auto_increment,b int null,primary key(a));
119
 
#SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
120
118
insert into t1(a,b)values(NULL,1);
121
119
insert into t1(a,b)values(200,2);
122
120
insert into t1(a,b)values(0,3);
140
138
--error 1048
141
139
update t1 set a=NULL where b=6;
142
140
update t1 set a=300 where b=7;
143
 
#SQL_MODE var is not supported.
144
 
#SET SQL_MODE='';
145
141
insert into t1(a,b)values(NULL,8);
146
142
insert into t1(a,b)values(400,9);
147
143
insert into t1(a,b)values(0,10);
172
168
 
173
169
create table t1 (a bigint);
174
170
insert into t1 values (1), (2), (3), (0), (0);
 
171
--error 1062
175
172
alter table t1 modify a bigint not null auto_increment primary key; 
176
173
select * from t1;
177
174
drop table t1;
178
175
 
179
176
# 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;
 
177
create table t1 (a bigint);
 
178
insert into t1 values (0), (1), (2), (3);
185
179
 
186
180
# Bug314567 -  ALTER TABLE causes auto_increment resequencing,
187
181
# resulting in duplicate entry since sql_mode=NO_AUTO_VALUE_ON_ZERO
188
182
#is not supported.
 
183
# NO_AUTO_VALUE_ON_ZERO is now default for Drizzle
189
184
 
190
 
#alter table t1 modify a bigint not null auto_increment primary key; 
 
185
alter table t1 modify a bigint not null auto_increment primary key; 
191
186
#set sql_mode= '';
192
 
#select * from t1;
193
 
#drop table t1;
 
187
select * from t1;
 
188
drop table t1;
194
189
 
195
190
# It also sensible to preserve zeroes if we are converting auto_increment
196
191
# column to auto_increment column (or not touching it at all, which is more
198
193
create table t1 (a int auto_increment primary key , b int null);
199
194
#sql_mode is not supported.
200
195
#set sql_mode=NO_AUTO_VALUE_ON_ZERO;
201
 
#insert into t1 values (0,1),(1,2),(2,3);
202
 
#select * from t1;
 
196
insert into t1 values (0,1),(1,2),(2,3);
 
197
select * from t1;
203
198
#set sql_mode= '';
204
199
alter table t1 modify b varchar(255);
 
200
--error 1062
205
201
insert into t1 values (0,4);
206
202
select * from t1;
207
203
drop table t1;
300
296
CREATE TABLE t1 (t1 INT PRIMARY KEY, t2 INT);
301
297
INSERT INTO t1 VALUES(0, 0);
302
298
INSERT INTO t1 VALUES(1, 1);
303
 
--error ER_DUP_ENTRY
304
299
ALTER TABLE t1 CHANGE t1 t1 INT auto_increment;
 
300
--error ER_DUP_ENTRY
 
301
INSERT INTO t1 VALUES(0,0);
305
302
DROP TABLE t1;
306
303
 
307
304
# Test of REPLACE when it does INSERT+DELETE and not UPDATE: