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;
29
# The empty line last comes from the end line field in the file
34
# Bug #11203: LOAD DATA does not accept same characters for ESCAPED and
37
create table t1 (a varchar(20), b varchar(20));
38
load data infile '../std_data_ln/loaddata_dq.dat' into table t1 fields terminated by ',' enclosed by '"' escaped by '"' (a,b);
43
# Bug #29294 SELECT INTO OUTFILE/LOAD DATA INFILE with special
44
# characters in the FIELDS ENCLOSED BY clause
48
id INT AUTO_INCREMENT PRIMARY KEY,
57
INSERT INTO t1 (c1) VALUES
58
('r'), ('rr'), ('rrr'), ('rrrr'),
59
('.r'), ('.rr'), ('.rrr'), ('.rrrr'),
60
('r.'), ('rr.'), ('rrr.'), ('rrrr.'),
61
('.r.'), ('.rr.'), ('.rrr.'), ('.rrrr.');
64
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
65
eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t1' FIELDS ENCLOSED BY 'r' FROM t1;
66
cat_file $MYSQLTEST_VARDIR/tmp/t1;
68
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
69
eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/t1' INTO TABLE t2 FIELDS ENCLOSED BY 'r';
70
SELECT t1.id, c1, c2 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE c1 != c2;
71
SELECT t1.id, c1, c2 FROM t1 RIGHT JOIN t2 ON t1.id=t2.id WHERE c1 != c2;
73
remove_file $MYSQLTEST_VARDIR/tmp/t1;
79
# Let us test extended LOAD DATA features
81
create table t1 (a int default 100, b int, c varchar(60));
82
# we can do something like this
83
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set b=@b+10, c=concat("b=",@b);
86
# we can use filled fields in expressions
87
# we also assigning NULL value to field with non-NULL default here
88
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set c= if(a is null,"oops",a);
91
# we even can use variables in set clause, and missed columns will be set
94
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, b) set c= if(@a is null,@c,b);
96
# let us test side-effect of such load
97
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, @b);
101
# now going to test fixed field-row file format
102
load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, b) set c="Wow";
105
# this also should work
106
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));
108
# and this should bark
110
load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, @b);
112
# Now let us test LOAD DATA with subselect
113
create table t2 (num int primary key, str varchar(10));
114
insert into t2 values (10,'Ten'), (15,'Fifteen');
116
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);
120
# Bug#18628 mysql-test-run: security problem
122
# It should not be possible to load from a file outside of vardir
124
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
125
show variables like "secure_file_pri%";
126
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
127
select @@secure_file_priv;
129
set @@secure_file_priv= 0;
133
--replace_result $DRIZZLE_TEST_DIR DRIZZLE_TEST_DIR
135
eval load data infile '$DRIZZLE_TEST_DIR/t/loaddata.test' into table t1;
138
# Test "load_file" returns NULL
139
--replace_result $DRIZZLE_TEST_DIR DRIZZLE_TEST_DIR
140
eval select load_file("$DRIZZLE_TEST_DIR/t/loaddata.test");
146
# Bug#27670: LOAD DATA does not set CURRENT_TIMESTAMP default value for a
147
# TIMESTAMP field when no value has been provided.
149
create table t1(f1 int, f2 timestamp not null default current_timestamp);
150
create table t2(f1 int);
151
insert into t2 values(1),(2);
153
eval select * into outfile '$MYSQLTEST_VARDIR/tmp/t2' from t2;
155
eval load data infile '$MYSQLTEST_VARDIR/tmp/t2' into table t1;
157
select f1 from t1 where f2 <> '0000-00-00 00:00:00' order by f1;
158
remove_file $MYSQLTEST_VARDIR/tmp/t2;
161
eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t2'
162
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n'
165
eval load data infile '$MYSQLTEST_VARDIR/tmp/t2' into table t1
166
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n';
168
select f1 from t1 where f2 <> '0000-00-00 00:00:00' order by f1;
169
remove_file $MYSQLTEST_VARDIR/tmp/t2;
173
# Bug#29442: SELECT INTO OUTFILE FIELDS ENCLOSED BY digit, minus sign etc
174
# corrupts non-string fields containing this character.
177
CREATE TABLE t1 (c1 INT, c2 TIMESTAMP, c3 REAL, c4 DOUBLE);
179
INSERT INTO t1 (c1, c2, c3, c4) VALUES (10, '1970-02-01 01:02:03', 1.1E-100, 1.1E+100);
182
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
183
eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t1' FIELDS ENCLOSED BY '-' FROM t1;
184
#cat_file $MYSQLTEST_VARDIR/tmp/t1;
189
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
190
eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/t1' INTO TABLE t1 FIELDS ENCLOSED BY '-';
193
remove_file $MYSQLTEST_VARDIR/tmp/t1;