~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/auto_increment.test

  • Committer: Jim Winstead
  • Date: 2008-07-19 02:56:45 UTC
  • mto: (202.1.8 codestyle)
  • mto: This revision was merged to the branch mainline in revision 207.
  • Revision ID: jimw@mysql.com-20080719025645-w2pwytebgzusjzjb
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
Temporarily disables tab-completion in the drizzle client until an appropriate
autoconf check can be added/enabled.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Test of auto_increment;  The test for BDB tables is in bdb.test
3
 
#
4
 
--disable_warnings
5
 
drop table if exists t1;
6
 
drop table if exists t2;
7
 
--enable_warnings
8
 
SET SQL_WARNINGS=1;
9
 
 
10
 
create TEMPORARY table t1 (a int not null auto_increment,b int, primary key (a)) engine=myisam auto_increment=3;
11
 
insert into t1 values (1,1),(NULL,3),(NULL,4);
12
 
delete from t1 where a=4;
13
 
insert into t1 values (NULL,5),(NULL,6);
14
 
select * from t1;
15
 
delete from t1 where a=6;
16
 
--replace_column 1 #  6 # 7 # 8 # 9 # 10 #
17
 
show table status like "t1";
18
 
replace t1 values (3,1);
19
 
ALTER TABLE t1 add c int;
20
 
replace t1 values (3,3,3);
21
 
insert into t1 values (NULL,7,7);
22
 
update t1 set a=8,b=b+1,c=c+1 where a=7;
23
 
insert into t1 values (NULL,9,9);
24
 
select * from t1;
25
 
drop table t1;
26
 
 
27
 
create table t1 (
28
 
  skey int NOT NULL auto_increment PRIMARY KEY,
29
 
  sval char(20)
30
 
);
31
 
insert into t1 values (NULL, "hello");
32
 
insert into t1 values (NULL, "hey");
33
 
select * from t1;
34
 
select _rowid,t1._rowid,skey,sval from t1;
35
 
drop table t1;
36
 
 
37
 
#
38
 
# Test auto_increment on sub key
39
 
#
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;
67
 
 
68
 
#
69
 
# Test of auto_increment columns when they are set to 0
70
 
#
71
 
 
72
 
create table t1 (a int not null primary key auto_increment);
73
 
insert into t1 values (0);
74
 
update t1 set a=0;
75
 
select * from t1;
76
 
check table t1;
77
 
drop table t1;
78
 
 
79
 
#
80
 
# Test negative values (Bug #1366)
81
 
#
82
 
 
83
 
create table t1 (a int not null auto_increment primary key);
84
 
insert into t1 values (NULL);
85
 
insert into t1 values (-1);
86
 
select last_insert_id();
87
 
insert into t1 values (NULL);
88
 
select * from t1;
89
 
drop table t1;
90
 
 
91
 
create temporary table t1 (a int not null auto_increment primary key) /*!40102 engine=MEMORY */;
92
 
insert into t1 values (NULL);
93
 
insert into t1 values (-1);
94
 
select last_insert_id();
95
 
insert into t1 values (NULL);
96
 
select * from t1;
97
 
drop table t1;
98
 
 
99
 
create table t1 (i int not null auto_increment, key (i));
100
 
insert into t1 set i = 254;
101
 
insert into t1 set i = null;
102
 
select last_insert_id();
103
 
insert into t1 set i = null;
104
 
select last_insert_id();
105
 
drop table t1;
106
 
 
107
 
create table t1 (i int not null auto_increment primary key, b int, unique (b));
108
 
insert into t1 values (NULL, 10);
109
 
select last_insert_id();
110
 
insert into t1 values (NULL, 15);
111
 
select last_insert_id();
112
 
--error ER_DUP_ENTRY
113
 
insert into t1 values (NULL, 10);
114
 
select last_insert_id();
115
 
 
116
 
drop table t1;
117
 
 
118
 
create table t1(a int auto_increment,b int null,primary key(a));
119
 
insert into t1(a,b)values(NULL,1);
120
 
insert into t1(a,b)values(200,2);
121
 
insert into t1(a,b)values(0,3);
122
 
insert into t1(b)values(4);
123
 
insert into t1(b)values(5);
124
 
insert into t1(b)values(6);
125
 
insert into t1(b)values(7);
126
 
select * from t1 order by b;
127
 
#mediumint is not supported. changed to b int.
128
 
alter table t1 modify b int;
129
 
select * from t1 order by b;
130
 
create table t2 (a int);
131
 
insert t2 values (1),(2);
132
 
alter table t2 add b int auto_increment primary key;
133
 
select * from t2;
134
 
drop table t2;
135
 
delete from t1 where a=0;
136
 
update t1 set a=0 where b=5;
137
 
select * from t1 order by b;
138
 
delete from t1 where a=0;
139
 
--error ER_BAD_NULL_ERROR
140
 
update t1 set a=NULL where b=6;
141
 
update t1 set a=300 where b=7;
142
 
insert into t1(a,b)values(NULL,8);
143
 
insert into t1(a,b)values(400,9);
144
 
insert into t1(a,b)values(0,10);
145
 
insert into t1(b)values(11);
146
 
insert into t1(b)values(12);
147
 
insert into t1(b)values(13);
148
 
insert into t1(b)values(14);
149
 
select * from t1 order by b;
150
 
delete from t1 where a=0;
151
 
update t1 set a=0 where b=12;
152
 
select * from t1 order by b;
153
 
delete from t1 where a=0;
154
 
--error ER_BAD_NULL_ERROR
155
 
update t1 set a=NULL where b=13;
156
 
update t1 set a=500 where b=14;
157
 
select * from t1 order by b;
158
 
drop table t1;
159
 
 
160
 
#
161
 
# Test of behavior of ALTER TABLE when coulmn containing NULL or zeroes is
162
 
# converted to AUTO_INCREMENT column
163
 
#
164
 
create table t1 (a bigint);
165
 
insert into t1 values (1), (2), (3), (NULL), (NULL);
166
 
alter table t1 modify a bigint not null auto_increment primary key; 
167
 
select * from t1;
168
 
drop table t1;
169
 
 
170
 
create table t1 (a bigint);
171
 
insert into t1 values (1), (2), (3), (0), (0);
172
 
--error ER_DUP_ENTRY
173
 
alter table t1 modify a bigint not null auto_increment primary key; 
174
 
select * from t1;
175
 
drop table t1;
176
 
 
177
 
# We still should be able to preserve zero in NO_AUTO_VALUE_ON_ZERO mode
178
 
create table t1 (a bigint);
179
 
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
 
 
186
 
alter table t1 modify a bigint not null auto_increment primary key; 
187
 
#set sql_mode= '';
188
 
select * from t1;
189
 
drop table t1;
190
 
 
191
 
# It also sensible to preserve zeroes if we are converting auto_increment
192
 
# column to auto_increment column (or not touching it at all, which is more
193
 
# common case probably)
194
 
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;
197
 
insert into t1 values (0,1),(1,2),(2,3);
198
 
select * from t1;
199
 
#set sql_mode= '';
200
 
alter table t1 modify b varchar(255);
201
 
--error ER_DUP_ENTRY
202
 
insert into t1 values (0,4);
203
 
select * from t1;
204
 
drop table t1;
205
 
 
206
 
#
207
 
# BUG #10045: Problem with composite AUTO_INCREMENT + BLOB key
208
 
 
209
 
CREATE TABLE t1 ( a INT AUTO_INCREMENT, b BLOB, PRIMARY KEY (a,b(10)));
210
 
INSERT INTO t1 (b) VALUES ('aaaa');
211
 
CHECK TABLE t1;
212
 
INSERT INTO t1 (b) VALUES ('');
213
 
CHECK TABLE t1;
214
 
INSERT INTO t1 (b) VALUES ('bbbb');
215
 
CHECK TABLE t1;
216
 
DROP TABLE IF EXISTS t1;
217
 
 
218
 
# BUG #19025:
219
 
#changed syntax of int(10) to int
220
 
CREATE TABLE t1 (
221
 
    t1_name VARCHAR(255) DEFAULT NULL,
222
 
    t1_id INT not null AUTO_INCREMENT,
223
 
    KEY (t1_name),
224
 
    PRIMARY KEY (t1_id)
225
 
) AUTO_INCREMENT = 1000;
226
 
 
227
 
INSERT INTO t1 (t1_name) VALUES('MySQL');
228
 
INSERT INTO t1 (t1_name) VALUES('MySQL');
229
 
INSERT INTO t1 (t1_name) VALUES('MySQL');
230
 
 
231
 
SELECT * from t1;
232
 
 
233
 
SHOW CREATE TABLE `t1`;
234
 
 
235
 
DROP TABLE `t1`;
236
 
 
237
 
#
238
 
# Bug #6880: LAST_INSERT_ID() within a statement
239
 
#
240
 
 
241
 
create table t1(a int not null auto_increment primary key);              
242
 
create table t2(a int not null auto_increment primary key, t1a int);     
243
 
insert into t1 values(NULL);
244
 
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
245
 
insert into t1 values (NULL);
246
 
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
247
 
(NULL, LAST_INSERT_ID());
248
 
insert into t1 values (NULL);                                            
249
 
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
250
 
(NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
251
 
select * from t2;
252
 
drop table t1, t2;
253
 
 
254
 
--echo End of 4.1 tests
255
 
 
256
 
#
257
 
# Bug #11080 & #11005  Multi-row REPLACE fails on a duplicate key error
258
 
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`));
261
 
insert into t1 (b) values (1);
262
 
replace into t1 (b) values (2), (1), (3);
263
 
select * from t1;
264
 
truncate table t1;
265
 
insert into t1 (b) values (1);
266
 
replace into t1 (b) values (2);
267
 
replace into t1 (b) values (1);
268
 
replace into t1 (b) values (3);
269
 
select * from t1;
270
 
drop table t1;
271
 
 
272
 
create table t1 (rowid int not null auto_increment, val int not null,primary
273
 
key (rowid), unique(val));
274
 
replace into t1 (val) values ('1'),('2');
275
 
replace into t1 (val) values ('1'),('2');
276
 
--error ER_DUP_ENTRY
277
 
insert into t1 (val) values ('1'),('2');
278
 
select * from t1;
279
 
drop table t1;
280
 
 
281
 
#
282
 
# Test that update changes internal auto-increment value
283
 
# Bug 314570 
284
 
 
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
 
 
292
 
#
293
 
# Test key duplications with auto-increment in ALTER TABLE
294
 
# bug #14573
295
 
#
296
 
#changed syntax of int(11) to int.
297
 
CREATE TABLE t1 (t1 INT PRIMARY KEY, t2 INT);
298
 
INSERT INTO t1 VALUES(0, 0);
299
 
INSERT INTO t1 VALUES(1, 1);
300
 
ALTER TABLE t1 CHANGE t1 t1 INT auto_increment;
301
 
--error ER_DUP_ENTRY
302
 
INSERT INTO t1 VALUES(0,0);
303
 
DROP TABLE t1;
304
 
 
305
 
# Test of REPLACE when it does INSERT+DELETE and not UPDATE:
306
 
# see if it sets LAST_INSERT_ID() ok
307
 
create table t1 (a int primary key auto_increment, b int, c int, d timestamp default current_timestamp, unique(b),unique(c));
308
 
insert into t1 values(null,1,1,now());
309
 
insert into t1 values(null,0,0,null);
310
 
# this will delete two rows
311
 
replace into t1 values(null,1,0,null);
312
 
select last_insert_id();
313
 
 
314
 
drop table t1;