~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
1063.9.3 by Brian Aker
Partial fix for tests for tmp
10
create TEMPORARY table t1 (a int not null auto_increment,b int, primary key (a)) engine=myisam auto_increment=3;
1 by brian
clean slate
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
1233.2.1 by Monty Taylor
Renamed instances of HEAP engine to MEMORY. Removed the alias.
90
create temporary table t1 (a int not null auto_increment primary key) /*!40102 engine=MEMORY */;
1 by brian
clean slate
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
117
create table t1(a int auto_increment,b int null,primary key(a));
118
insert into t1(a,b)values(NULL,1);
119
insert into t1(a,b)values(200,2);
120
insert into t1(a,b)values(0,3);
121
insert into t1(b)values(4);
122
insert into t1(b)values(5);
123
insert into t1(b)values(6);
124
insert into t1(b)values(7);
125
select * from t1 order by b;
642.1.71 by Lee
merge with latest from the trunk
126
#mediumint is not supported. changed to b int.
127
alter table t1 modify b int;
1 by brian
clean slate
128
select * from t1 order by b;
129
create table t2 (a int);
130
insert t2 values (1),(2);
131
alter table t2 add b int auto_increment primary key;
132
select * from t2;
133
drop table t2;
134
delete from t1 where a=0;
135
update t1 set a=0 where b=5;
136
select * from t1 order by b;
137
delete from t1 where a=0;
138
--error 1048
139
update t1 set a=NULL where b=6;
140
update t1 set a=300 where b=7;
141
insert into t1(a,b)values(NULL,8);
142
insert into t1(a,b)values(400,9);
143
insert into t1(a,b)values(0,10);
144
insert into t1(b)values(11);
145
insert into t1(b)values(12);
146
insert into t1(b)values(13);
147
insert into t1(b)values(14);
148
select * from t1 order by b;
149
delete from t1 where a=0;
150
update t1 set a=0 where b=12;
151
select * from t1 order by b;
152
delete from t1 where a=0;
153
--error 1048
154
update t1 set a=NULL where b=13;
155
update t1 set a=500 where b=14;
156
select * from t1 order by b;
157
drop table t1;
158
159
#
160
# Test of behavior of ALTER TABLE when coulmn containing NULL or zeroes is
161
# converted to AUTO_INCREMENT column
162
#
163
create table t1 (a bigint);
164
insert into t1 values (1), (2), (3), (NULL), (NULL);
165
alter table t1 modify a bigint not null auto_increment primary key; 
166
select * from t1;
167
drop table t1;
168
169
create table t1 (a bigint);
170
insert into t1 values (1), (2), (3), (0), (0);
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
171
--error 1062
1 by brian
clean slate
172
alter table t1 modify a bigint not null auto_increment primary key; 
173
select * from t1;
174
drop table t1;
175
176
# We still should be able to preserve zero in NO_AUTO_VALUE_ON_ZERO mode
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
177
create table t1 (a bigint);
178
insert into t1 values (0), (1), (2), (3);
642.1.71 by Lee
merge with latest from the trunk
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.
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
183
# NO_AUTO_VALUE_ON_ZERO is now default for Drizzle
642.1.71 by Lee
merge with latest from the trunk
184
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
185
alter table t1 modify a bigint not null auto_increment primary key; 
642.1.71 by Lee
merge with latest from the trunk
186
#set sql_mode= '';
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
187
select * from t1;
188
drop table t1;
1 by brian
clean slate
189
190
# It also sensible to preserve zeroes if we are converting auto_increment
191
# column to auto_increment column (or not touching it at all, which is more
192
# common case probably)
193
create table t1 (a int auto_increment primary key , b int null);
642.1.71 by Lee
merge with latest from the trunk
194
#sql_mode is not supported.
195
#set sql_mode=NO_AUTO_VALUE_ON_ZERO;
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
196
insert into t1 values (0,1),(1,2),(2,3);
197
select * from t1;
642.1.71 by Lee
merge with latest from the trunk
198
#set sql_mode= '';
1 by brian
clean slate
199
alter table t1 modify b varchar(255);
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
200
--error 1062
1 by brian
clean slate
201
insert into t1 values (0,4);
202
select * from t1;
203
drop table t1;
204
205
#
206
# BUG #10045: Problem with composite AUTO_INCREMENT + BLOB key
207
208
CREATE TABLE t1 ( a INT AUTO_INCREMENT, b BLOB, PRIMARY KEY (a,b(10)));
209
INSERT INTO t1 (b) VALUES ('aaaa');
210
CHECK TABLE t1;
211
INSERT INTO t1 (b) VALUES ('');
212
CHECK TABLE t1;
213
INSERT INTO t1 (b) VALUES ('bbbb');
214
CHECK TABLE t1;
215
DROP TABLE IF EXISTS t1;
216
217
# BUG #19025:
642.1.71 by Lee
merge with latest from the trunk
218
#changed syntax of int(10) to int
219
CREATE TABLE t1 (
1 by brian
clean slate
220
    t1_name VARCHAR(255) DEFAULT NULL,
642.1.71 by Lee
merge with latest from the trunk
221
    t1_id INT not null AUTO_INCREMENT,
1 by brian
clean slate
222
    KEY (t1_name),
223
    PRIMARY KEY (t1_id)
224
) AUTO_INCREMENT = 1000;
225
226
INSERT INTO t1 (t1_name) VALUES('MySQL');
227
INSERT INTO t1 (t1_name) VALUES('MySQL');
228
INSERT INTO t1 (t1_name) VALUES('MySQL');
229
230
SELECT * from t1;
231
232
SHOW CREATE TABLE `t1`;
233
234
DROP TABLE `t1`;
235
236
#
237
# Bug #6880: LAST_INSERT_ID() within a statement
238
#
239
240
create table t1(a int not null auto_increment primary key);              
241
create table t2(a int not null auto_increment primary key, t1a int);     
242
insert into t1 values(NULL);
243
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
244
insert into t1 values (NULL);
245
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
246
(NULL, LAST_INSERT_ID());
247
insert into t1 values (NULL);                                            
248
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
249
(NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
250
select * from t2;
251
drop table t1, t2;
252
253
--echo End of 4.1 tests
254
255
#
256
# Bug #11080 & #11005  Multi-row REPLACE fails on a duplicate key error
257
# 
642.1.71 by Lee
merge with latest from the trunk
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`));
1 by brian
clean slate
260
insert into t1 (b) values (1);
261
replace into t1 (b) values (2), (1), (3);
262
select * from t1;
263
truncate table t1;
264
insert into t1 (b) values (1);
265
replace into t1 (b) values (2);
266
replace into t1 (b) values (1);
267
replace into t1 (b) values (3);
268
select * from t1;
269
drop table t1;
270
271
create table t1 (rowid int not null auto_increment, val int not null,primary
272
key (rowid), unique(val));
273
replace into t1 (val) values ('1'),('2');
274
replace into t1 (val) values ('1'),('2');
275
--error ER_DUP_ENTRY
276
insert into t1 (val) values ('1'),('2');
277
select * from t1;
278
drop table t1;
279
280
#
281
# Test that update changes internal auto-increment value
642.1.71 by Lee
merge with latest from the trunk
282
# Bug 314570 
1 by brian
clean slate
283
642.1.71 by Lee
merge with latest from the trunk
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;
1 by brian
clean slate
290
291
#
292
# Test key duplications with auto-increment in ALTER TABLE
293
# bug #14573
294
#
642.1.71 by Lee
merge with latest from the trunk
295
#changed syntax of int(11) to int.
296
CREATE TABLE t1 (t1 INT PRIMARY KEY, t2 INT);
1 by brian
clean slate
297
INSERT INTO t1 VALUES(0, 0);
298
INSERT INTO t1 VALUES(1, 1);
642.1.71 by Lee
merge with latest from the trunk
299
ALTER TABLE t1 CHANGE t1 t1 INT auto_increment;
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
300
--error ER_DUP_ENTRY
301
INSERT INTO t1 VALUES(0,0);
1 by brian
clean slate
302
DROP TABLE t1;
303
304
# Test of REPLACE when it does INSERT+DELETE and not UPDATE:
305
# see if it sets LAST_INSERT_ID() ok
306
create table t1 (a int primary key auto_increment, b int, c int, d timestamp default current_timestamp, unique(b),unique(c));
307
insert into t1 values(null,1,1,now());
308
insert into t1 values(null,0,0,null);
309
# this will delete two rows
310
replace into t1 values(null,1,0,null);
311
select last_insert_id();
312
313
drop table t1;