2
# Some simple test of load data
6
drop table if exists t1, t2;
9
create table t1 (a date, b date, c date not null, d date);
10
load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',';
11
load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES;
15
load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',' LINES STARTING BY ',' (b,c,d);
19
create table t1 (a text, b text);
20
load data infile '../std_data_ln/loaddata2.dat' into table t1 fields terminated by ',' enclosed by '''';
21
select concat('|',a,'|'), concat('|',b,'|') from t1;
24
create table t1 (a int, b char(10));
25
load data infile '../std_data_ln/loaddata3.dat' into table t1 fields terminated by '' enclosed by '' ignore 1 lines;
28
load data infile '../std_data_ln/loaddata4.dat' into table t1 fields terminated by '' enclosed by '' lines terminated by '' ignore 1 lines;
30
# The empty line last comes from the end line field in the file
35
# Bug #12053 LOAD DATA INFILE ignores NO_AUTO_VALUE_ON_ZERO setting
37
SET @OLD_SQL_MODE=@@SQL_MODE, @@SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
38
create table t1(id integer not null auto_increment primary key);
39
insert into t1 values(0);
41
eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t1' from t1;
43
eval load data infile '$MYSQLTEST_VARDIR/tmp/t1' into table t1;
46
remove_file $MYSQLTEST_VARDIR/tmp/t1;
49
eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t1'
50
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n'
53
eval load data infile '$MYSQLTEST_VARDIR/tmp/t1' into table t1
54
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n';
57
remove_file $MYSQLTEST_VARDIR/tmp/t1;
58
SET @@SQL_MODE=@OLD_SQL_MODE;
62
# Bug #11203: LOAD DATA does not accept same characters for ESCAPED and
65
create table t1 (a varchar(20), b varchar(20));
66
load data infile '../std_data_ln/loaddata_dq.dat' into table t1 fields terminated by ',' enclosed by '"' escaped by '"' (a,b);
71
# Bug #29294 SELECT INTO OUTFILE/LOAD DATA INFILE with special
72
# characters in the FIELDS ENCLOSED BY clause
76
id INT AUTO_INCREMENT PRIMARY KEY,
85
INSERT INTO t1 (c1) VALUES
86
('r'), ('rr'), ('rrr'), ('rrrr'),
87
('.r'), ('.rr'), ('.rrr'), ('.rrrr'),
88
('r.'), ('rr.'), ('rrr.'), ('rrrr.'),
89
('.r.'), ('.rr.'), ('.rrr.'), ('.rrrr.');
92
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
93
eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t1' FIELDS ENCLOSED BY 'r' FROM t1;
94
cat_file $MYSQLTEST_VARDIR/tmp/t1;
96
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
97
eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/t1' INTO TABLE t2 FIELDS ENCLOSED BY 'r';
98
SELECT t1.id, c1, c2 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE c1 != c2;
99
SELECT t1.id, c1, c2 FROM t1 RIGHT JOIN t2 ON t1.id=t2.id WHERE c1 != c2;
101
remove_file $MYSQLTEST_VARDIR/tmp/t1;
107
# Let us test extended LOAD DATA features
109
create table t1 (a int default 100, b int, c varchar(60));
110
# we can do something like this
111
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set b=@b+10, c=concat("b=",@b);
114
# we can use filled fields in expressions
115
# we also assigning NULL value to field with non-NULL default here
116
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set c= if(a is null,"oops",a);
119
# we even can use variables in set clause, and missed columns will be set
120
# with default values
122
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, b) set c= if(@a is null,@c,b);
124
# let us test side-effect of such load
125
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, @b);
129
# Reading of all columns with set
130
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 set c=b;
133
# now going to test fixed field-row file format
134
load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, b) set c="Wow";
137
# this also should work
138
load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, b) set c=concat(a,"+",b,"+",@c,"+",b,"+",if(c is null,"NIL",c));
140
# and this should bark
142
load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, @b);
144
# Now let us test LOAD DATA with subselect
145
create table t2 (num int primary key, str varchar(10));
146
insert into t2 values (10,'Ten'), (15,'Fifteen');
148
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@dummy,@n) set a= @n, c= (select str from t2 where num=@n);
152
# Bug#18628 mysql-test-run: security problem
154
# It should not be possible to load from a file outside of vardir
156
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
157
show variables like "secure_file_pri%";
158
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
159
select @@secure_file_priv;
161
set @@secure_file_priv= 0;
165
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
167
eval load data infile '$MYSQL_TEST_DIR/t/loaddata.test' into table t1;
170
# Test "load_file" returns NULL
171
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
172
eval select load_file("$MYSQL_TEST_DIR/t/loaddata.test");
178
# Bug#27586: Wrong autoinc value assigned by LOAD DATA in the
179
# NO_AUTO_VALUE_ON_ZERO mode
181
create table t1(f1 int);
182
insert into t1 values(1),(null);
183
create table t2(f2 int auto_increment primary key);
185
eval select * into outfile '$MYSQLTEST_VARDIR/tmp/t1' from t1;
186
SET @OLD_SQL_MODE=@@SQL_MODE, @@SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
187
eval load data infile '$MYSQLTEST_VARDIR/tmp/t1' into table t2;
190
remove_file $MYSQLTEST_VARDIR/tmp/t1;
191
SET @@SQL_MODE=@OLD_SQL_MODE;
195
# Bug#27670: LOAD DATA does not set CURRENT_TIMESTAMP default value for a
196
# TIMESTAMP field when no value has been provided.
198
create table t1(f1 int, f2 timestamp not null default current_timestamp);
199
create table t2(f1 int);
200
insert into t2 values(1),(2);
202
eval select * into outfile '$MYSQLTEST_VARDIR/tmp/t2' from t2;
203
eval load data infile '$MYSQLTEST_VARDIR/tmp/t2' into table t1;
205
select f1 from t1 where f2 <> '0000-00-00 00:00:00' order by f1;
206
remove_file $MYSQLTEST_VARDIR/tmp/t2;
209
eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t2'
210
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n'
212
eval load data infile '$MYSQLTEST_VARDIR/tmp/t2' into table t1
213
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n';
215
select f1 from t1 where f2 <> '0000-00-00 00:00:00' order by f1;
216
remove_file $MYSQLTEST_VARDIR/tmp/t2;
220
# Bug#29442: SELECT INTO OUTFILE FIELDS ENCLOSED BY digit, minus sign etc
221
# corrupts non-string fields containing this character.
224
CREATE TABLE t1 (c1 INT, c2 TIMESTAMP, c3 REAL, c4 DOUBLE);
226
INSERT INTO t1 (c1, c2, c3, c4) VALUES (10, '1970-02-01 01:02:03', 1.1E-100, 1.1E+100);
229
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
230
eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t1' FIELDS ENCLOSED BY '-' FROM t1;
231
cat_file $MYSQLTEST_VARDIR/tmp/t1;
236
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
237
eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/t1' INTO TABLE t1 FIELDS ENCLOSED BY '-';
240
remove_file $MYSQLTEST_VARDIR/tmp/t1;
243
###########################################################################
247
--echo # -- Bug#35469: server crash with LOAD DATA INFILE to a VIEW.
252
DROP TABLE IF EXISTS t1;
253
DROP VIEW IF EXISTS v1;
254
DROP VIEW IF EXISTS v2;
255
DROP VIEW IF EXISTS v3;
259
CREATE TABLE t1(c1 INT, c2 VARCHAR(255));
262
CREATE VIEW v1 AS SELECT * FROM t1;
263
CREATE VIEW v2 AS SELECT 1 + 2 AS c0, c1, c2 FROM t1;
264
CREATE VIEW v3 AS SELECT 1 AS d1, 2 AS d2;
267
LOAD DATA INFILE '../std_data_ln/bug35469.dat' INTO TABLE v1
268
FIELDS ESCAPED BY '\\'
271
LINES TERMINATED BY '\n' (c1, c2);
283
LOAD DATA INFILE '../std_data_ln/bug35469.dat' INTO TABLE v2
284
FIELDS ESCAPED BY '\\'
287
LINES TERMINATED BY '\n' (c1, c2);
299
--error ER_LOAD_DATA_INVALID_COLUMN
300
LOAD DATA INFILE '../std_data_ln/bug35469.dat' INTO TABLE v2
301
FIELDS ESCAPED BY '\\'
304
LINES TERMINATED BY '\n' (c0, c2);
307
--error ER_NON_UPDATABLE_TABLE
308
LOAD DATA INFILE '../std_data_ln/bug35469.dat' INTO TABLE v3
309
FIELDS ESCAPED BY '\\'
312
LINES TERMINATED BY '\n' (d1, d2);
321
--echo # -- End of Bug#35469.
323
###########################################################################
329
# Bug#12448 LOAD DATA / SELECT INTO OUTFILE
330
# doesn't work with multibyte path name
332
CREATE TABLE t1 (a int);
333
INSERT INTO t1 VALUES (1);
335
SET character_set_filesystem=filename;
336
select @@character_set_filesystem;
337
SELECT * INTO OUTFILE 't-1' FROM t1;
339
LOAD DATA INFILE 't-1' INTO TABLE t1;
342
SET character_set_filesystem=latin1;
343
select @@character_set_filesystem;
344
LOAD DATA INFILE 't@002d1' INTO TABLE t1;
347
remove_file $MYSQLTEST_VARDIR/master-data/test/t@002d1;
348
SET character_set_filesystem=default;
349
select @@character_set_filesystem;