~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/insert.test

  • Committer: Brian Aker
  • Date: 2008-07-15 06:45:16 UTC
  • Revision ID: brian@tangent.org-20080715064516-fnbq7kowh7w57bxj
Merge Monty's code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Test of refering to old values
3
 
#
4
 
 
5
 
--disable_warnings
6
 
drop table if exists t1,t2,t3;
7
 
--enable_warnings
8
 
 
9
 
create table t1 (a int not null);
10
 
insert into t1 values (1);
11
 
insert into t1 values (a+2);
12
 
insert into t1 values (a+3),(a+4);
13
 
insert into t1 values (5),(a+6);
14
 
select * from t1;
15
 
drop table t1;
16
 
 
17
 
#
18
 
# Test of duplicate key values with packed keys
19
 
#
20
 
 
21
 
create table t1 (id int not null auto_increment primary key, username varchar(32) not null, unique (username));
22
 
insert into t1 values (0,"mysql");
23
 
insert into t1 values (0,"mysql ab");
24
 
insert into t1 values (0,"mysql a");
25
 
insert into t1 values (0,"r1manic");
26
 
insert into t1 values (0,"r1man");
27
 
drop table t1;
28
 
 
29
 
#
30
 
# Test insert syntax
31
 
#
32
 
 
33
 
create table t1 (a int not null auto_increment, primary key (a), t timestamp, c char(10) default "hello", i int);
34
 
insert into t1 values (default,default,default,default), (default,default,default,default), (4,0,"a",5),(default,default,default,default);
35
 
select a,t>0,c,i from t1;
36
 
truncate table t1;
37
 
insert into t1 set a=default,t=default,c=default;
38
 
insert into t1 set a=default,t=default,c=default,i=default;
39
 
insert into t1 set a=4,t=0,c="a",i=5;
40
 
insert into t1 set a=5,t=0,c="a",i=null;
41
 
insert into t1 set a=default,t=default,c=default,i=default;
42
 
select a,t>0,c,i from t1;
43
 
drop table t1;
44
 
 
45
 
#
46
 
#Test of behaviour with INSERT VALUES (NULL)
47
 
#
48
 
 
49
 
create table t1 (id int NOT NULL DEFAULT 8);
50
 
insert into t1 values(NULL);
51
 
insert into t1 values (1), (NULL), (2);
52
 
select * from t1;
53
 
drop table t1;
54
 
 
55
 
#
56
 
# Test if insert ... select distinct
57
 
#
58
 
 
59
 
create table t1 (email varchar(50));
60
 
insert into t1 values ('sasha@mysql.com'),('monty@mysql.com'),('foo@hotmail.com'),('foo@aol.com'),('bar@aol.com');
61
 
create table t2(id int not null auto_increment primary key, t2 varchar(50), unique(t2));
62
 
insert delayed into t2 (t2) select distinct substring(email, locate('@', email)+1) from t1;
63
 
select * from t2;
64
 
drop table t1,t2;
65
 
 
66
 
#
67
 
# Test of mysqld crash with fully qualified column names
68
 
#
69
 
 
70
 
--disable_warnings
71
 
drop database if exists mysqltest;
72
 
--enable_warnings
73
 
create database mysqltest;
74
 
use mysqltest;
75
 
create table t1 (c int);
76
 
insert into mysqltest.t1 set mysqltest.t1.c = '1';
77
 
drop database mysqltest;
78
 
use test;
79
 
 
80
 
 
81
 
# End of 4.1 tests
82
 
 
83
 
#
84
 
# Test automatic result buffering with INSERT INTO t1 ... SELECT ... FROM t1
85
 
#
86
 
 
87
 
create table t1(id1 int not null auto_increment primary key, t char(12));
88
 
create table t2(id2 int not null, t char(12));
89
 
create table t3(id3 int not null, t char(12), index(id3));
90
 
disable_query_log;
91
 
set autocommit=0;
92
 
begin;
93
 
let $1 = 100;
94
 
while ($1)
95
 
 {
96
 
  let $2 = 5;
97
 
  eval insert into t1(t) values ('$1'); 
98
 
  while ($2)
99
 
   {
100
 
     eval insert into t2(id2,t) values ($1,'$2'); 
101
 
     let $3 = 10;
102
 
     while ($3)
103
 
     {
104
 
       eval insert into t3(id3,t) values ($1,'$2'); 
105
 
       dec $3;
106
 
     }
107
 
     dec $2; 
108
 
   }
109
 
  dec $1;
110
 
 }
111
 
enable_query_log;
112
 
select count(*) from t2;
113
 
insert into  t2 select t1.* from t1, t2 t, t3 where  t1.id1 = t.id2 and t.id2 = t3.id3;
114
 
select count(*) from t2;
115
 
drop table t1,t2,t3;
116
 
 
117
 
#
118
 
# Test different cases of duplicate fields
119
 
#
120
 
 
121
 
create table t1 (a int, b int);
122
 
insert into t1 (a,b) values (a,b);
123
 
insert into t1 SET a=1, b=a+1;
124
 
insert into t1 (a,b) select 1,2;
125
 
INSERT INTO t1 ( a ) SELECT 0 ON DUPLICATE KEY UPDATE a = a + VALUES (a);
126
 
--error 1110
127
 
replace into t1 (a,a) select 100, 'hundred';
128
 
--error 1110
129
 
insert into t1 (a,b,b) values (1,1,1);
130
 
--error 1136
131
 
insert into t1 (a,a) values (1,1,1);
132
 
--error 1110
133
 
insert into t1 (a,a) values (1,1);
134
 
--error 1110
135
 
insert into t1 SET a=1,b=2,a=1;
136
 
--error 1110
137
 
insert into t1 (b,b) select 1,2;
138
 
--error 1110
139
 
INSERT INTO t1 (b,b) SELECT 0,0 ON DUPLICATE KEY UPDATE a = a + VALUES (a);
140
 
drop table t1;
141
 
 
142
 
#
143
 
# Test for values returned by ROW_COUNT() function
144
 
# (and thus for values returned by mysql_affected_rows())
145
 
# for various forms of INSERT
146
 
#
147
 
create table t1 (id int primary key, data int);
148
 
insert into t1 values (1, 1), (2, 2), (3, 3);
149
 
select row_count();
150
 
insert ignore into t1 values (1, 1);
151
 
select row_count();
152
 
# Reports that 2 rows are affected (1 deleted + 1 inserted)
153
 
replace into t1 values (1, 11);
154
 
select row_count();
155
 
replace into t1 values (4, 4);
156
 
select row_count();
157
 
# Reports that 2 rows are affected. This conforms to documentation.
158
 
# (Useful for differentiating inserts from updates).
159
 
insert into t1 values (2, 2) on duplicate key update data= data + 10;
160
 
select row_count();
161
 
insert into t1 values (5, 5) on duplicate key update data= data + 10;
162
 
select row_count();
163
 
drop table t1;
164
 
 
165
 
# Test of INSERT IGNORE and re-using auto_increment values
166
 
create table t1 (id int primary key auto_increment, data int, unique(data));
167
 
insert ignore into t1 values(NULL,100),(NULL,110),(NULL,120);
168
 
insert ignore into t1 values(NULL,10),(NULL,20),(NULL,110),(NULL,120),(NULL,100),(NULL,90);
169
 
insert ignore into t1 values(NULL,130),(NULL,140),(500,110),(550,120),(450,100),(NULL,150);
170
 
# PBXT differs from InnoDB here. Main reason is that inserting
171
 
# 500 causes auto inc value to be set to 501, this is never
172
 
# undone because of possible concurrent inserts.
173
 
select * from t1 order by id;
174
 
 
175
 
drop table t1;
176
 
 
177
 
#
178
 
# Bug #26788: mysqld (debug) aborts when inserting specific numbers into char
179
 
#             fields
180
 
#
181
 
 
182
 
CREATE TABLE t1 (
183
 
  a char(20) NOT NULL,
184
 
  b char(7) DEFAULT NULL,
185
 
  c char(4) DEFAULT NULL
186
 
);
187
 
 
188
 
INSERT INTO t1(a,b,c) VALUES (9.999999e+0, 9.999999e+0, 9.999e+0);
189
 
INSERT INTO t1(a,b) VALUES (1.225e-04, 1.225e-04);
190
 
INSERT INTO t1(a,b) VALUES (1.225e-01, 1.225e-01);
191
 
INSERT INTO t1(a,b) VALUES (1.225877e-01, 1.225877e-01);
192
 
INSERT INTO t1(a,b) VALUES (1.225e+01, 1.225e+01);
193
 
INSERT INTO t1(a,b,c) VALUES (1.225e+01, 1.225e+01, 1.225e+01);
194
 
INSERT INTO t1(a,b) VALUES (1.225e+05, 1.225e+05);
195
 
INSERT INTO t1(a,b) VALUES (1.225e+10, 1.225e+10);
196
 
INSERT INTO t1(a,b) VALUES (1.225e+15, 1.225e+15);
197
 
INSERT INTO t1(a,b) VALUES (5000000e+0, 5000000e+0);
198
 
INSERT INTO t1(a,b) VALUES (1.25e+78, 1.25e+78);
199
 
INSERT INTO t1(a,b) VALUES (1.25e-94, 1.25e-94);
200
 
INSERT INTO t1(a,b) VALUES (1.25e+203, 1.25e+203);
201
 
INSERT INTO t1(a,b) VALUES (1.25e-175, 1.25e-175);
202
 
INSERT INTO t1(a,c) VALUES (1.225e+0, 1.225e+0);
203
 
INSERT INTO t1(a,c) VALUES (1.37e+0, 1.37e+0);
204
 
INSERT INTO t1(a,c) VALUES (-1.37e+0, -1.37e+0);
205
 
INSERT INTO t1(a,c) VALUES (-1.87e-2, -1.87e-2);
206
 
INSERT INTO t1(a,c) VALUES (5000e+0, 5000e+0);
207
 
INSERT INTO t1(a,c) VALUES (-5000e+0, -5000e+0);
208
 
SELECT * FROM t1;
209
 
 
210
 
DROP TABLE t1;
211
 
 
212
 
CREATE TABLE t1 (
213
 
  a char(20) NOT NULL,
214
 
  b char(7) DEFAULT NULL,
215
 
  c char(5)
216
 
);
217
 
 
218
 
 
219
 
INSERT INTO t1(a,b,c) VALUES (9.999999e+0, 9.999999e+0, 9.999e+0);
220
 
INSERT INTO t1(a,b,c) VALUES (1.225e-05, 1.225e-05, 1.225e-05);
221
 
INSERT INTO t1(a,b) VALUES (1.225e-04, 1.225e-04);
222
 
INSERT INTO t1(a,b) VALUES (1.225e-01, 1.225e-01);
223
 
INSERT INTO t1(a,b) VALUES (1.225877e-01, 1.225877e-01);
224
 
INSERT INTO t1(a,b) VALUES (1.225e+01, 1.225e+01);
225
 
INSERT INTO t1(a,b,c) VALUES (1.225e+01, 1.225e+01, 1.225e+01);
226
 
INSERT INTO t1(a,b) VALUES (1.225e+05, 1.225e+05);
227
 
INSERT INTO t1(a,b) VALUES (1.225e+10, 1.225e+10);
228
 
INSERT INTO t1(a,b) VALUES (1.225e+15, 1.225e+15);
229
 
INSERT INTO t1(a,b) VALUES (5000000e+0, 5000000e+0);
230
 
INSERT INTO t1(a,b) VALUES (1.25e+78, 1.25e+78);
231
 
INSERT INTO t1(a,b) VALUES (1.25e-94, 1.25e-94);
232
 
INSERT INTO t1(a,b) VALUES (1.25e+203, 1.25e+203);
233
 
INSERT INTO t1(a,b) VALUES (1.25e-175, 1.25e-175);
234
 
INSERT INTO t1(a,c) VALUES (1.225e+0, 1.225e+0);
235
 
INSERT INTO t1(a,c) VALUES (1.37e+0, 1.37e+0);
236
 
INSERT INTO t1(a,c) VALUES (-1.37e+0, -1.37e+0);
237
 
INSERT INTO t1(a,c) VALUES (1.87e-3, 1.87e-3);
238
 
INSERT INTO t1(a,c) VALUES (-1.87e-2, -1.87e-2);
239
 
INSERT INTO t1(a,c) VALUES (5000e+0, 5000e+0);
240
 
INSERT INTO t1(a,c) VALUES (-5000e+0, -5000e+0);
241
 
 
242
 
SELECT * FROM t1;
243
 
 
244
 
DROP TABLE t1;
245
 
 
246
 
#
247
 
# Bug #31152: assertion in Field_str::store(double)
248
 
#
249
 
 
250
 
CREATE TABLE t (a CHAR(10),b INT);
251
 
INSERT INTO t VALUES (),(),();
252
 
INSERT INTO t(a) SELECT rand() FROM t;
253
 
DROP TABLE t;
254
 
 
255
 
#
256
 
# Bug #30453: String not cast to int correctly
257
 
#
258
 
 
259
 
CREATE TABLE t1 (c1 INT NOT NULL);
260
 
INSERT INTO t1 VALUES(4188.32999999999992724042385816574096679687500),
261
 
('4188.32999999999992724042385816574096679687500'), (4188);
262
 
SELECT * FROM t1;
263
 
 
264
 
CREATE TABLE t2 (c1 BIGINT);
265
 
INSERT INTO t2 VALUES('15449237462.0000000000');
266
 
SELECT * FROM t2;
267
 
 
268
 
DROP TABLE t1, t2;
269
 
 
270
 
--echo End of 5.0 tests.
271