~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/insert.test

  • Committer: Brian Aker
  • Date: 2008-07-20 05:41:52 UTC
  • Revision ID: brian@tangent.org-20080720054152-5laf6plsb0o7h6ss
Documentation cleanup

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