~drizzle-trunk/drizzle/development

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