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
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
11
eval load data infile '$DRIZZLETEST_VARDIR/std_data_ln/loaddata1.dat' into table t1 fields terminated by ',';
12
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
13
eval load data infile '$DRIZZLETEST_VARDIR/std_data_ln/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES;
17
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
18
eval load data infile '$DRIZZLETEST_VARDIR/std_data_ln/loaddata1.dat' into table t1 fields terminated by ',' LINES STARTING BY ',' (b,c,d);
22
create table t1 (a text, b text);
23
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
24
eval load data infile '$DRIZZLETEST_VARDIR/std_data_ln/loaddata2.dat' into table t1 fields terminated by ',' enclosed by '''';
25
select concat('|',a,'|'), concat('|',b,'|') from t1;
28
create table t1 (a int, b char(10));
29
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
30
eval load data infile '$DRIZZLETEST_VARDIR/std_data_ln/loaddata3.dat' into table t1 fields terminated by '' enclosed by '' ignore 1 lines;
34
# The empty line last comes from the end line field in the file
39
# Bug #11203: LOAD DATA does not accept same characters for ESCAPED and
42
create table t1 (a varchar(20), b varchar(20));
43
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
44
eval load data infile '$DRIZZLETEST_VARDIR/std_data_ln/loaddata_dq.dat' into table t1 fields terminated by ',' enclosed by '"' escaped by '"' (a,b);
49
# Bug #29294 SELECT INTO OUTFILE/LOAD DATA INFILE with special
50
# characters in the FIELDS ENCLOSED BY clause
54
id INT AUTO_INCREMENT PRIMARY KEY,
63
INSERT INTO t1 (c1) VALUES
64
('r'), ('rr'), ('rrr'), ('rrrr'),
65
('.r'), ('.rr'), ('.rrr'), ('.rrrr'),
66
('r.'), ('rr.'), ('rrr.'), ('rrrr.'),
67
('.r.'), ('.rr.'), ('.rrr.'), ('.rrrr.');
70
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
71
eval SELECT * INTO OUTFILE '$DRIZZLETEST_VARDIR/tmp/t1' FIELDS ENCLOSED BY 'r' FROM t1;
72
cat_file $DRIZZLETEST_VARDIR/tmp/t1;
74
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
75
eval LOAD DATA INFILE '$DRIZZLETEST_VARDIR/tmp/t1' INTO TABLE t2 FIELDS ENCLOSED BY 'r';
76
SELECT t1.id, c1, c2 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE c1 != c2;
77
SELECT t1.id, c1, c2 FROM t1 RIGHT JOIN t2 ON t1.id=t2.id WHERE c1 != c2;
79
remove_file $DRIZZLETEST_VARDIR/tmp/t1;
85
# Let us test extended LOAD DATA features
87
create table t1 (a int default 100, b int, c varchar(60));
88
# we can do something like this
89
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
90
eval load data infile '$DRIZZLETEST_VARDIR/std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set b=@b+10, c=concat("b=",@b);
93
# we can use filled fields in expressions
94
# we also assigning NULL value to field with non-NULL default here
95
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
96
eval load data infile '$DRIZZLETEST_VARDIR/std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set c= if(a is null,"oops",a);
99
# we even can use variables in set clause, and missed columns will be set
100
# with default values
102
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
103
eval load data infile '$DRIZZLETEST_VARDIR/std_data_ln/rpl_loaddata.dat' into table t1 (@a, b) set c= if(@a is null,@c,b);
105
# let us test side-effect of such load
106
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
107
eval load data infile '$DRIZZLETEST_VARDIR/std_data_ln/rpl_loaddata.dat' into table t1 (@a, @b);
111
# now going to test fixed field-row file format
112
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
113
eval load data infile '$DRIZZLETEST_VARDIR/std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, b) set c="Wow";
116
# this also should work
117
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
118
eval load data infile '$DRIZZLETEST_VARDIR/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));
120
# and this should bark
121
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
122
--error ER_LOAD_FROM_FIXED_SIZE_ROWS_TO_VAR
123
eval load data infile '$DRIZZLETEST_VARDIR/std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, @b);
125
# Now let us test LOAD DATA with subselect
126
create table t2 (num int primary key, str varchar(10));
127
insert into t2 values (10,'Ten'), (15,'Fifteen');
129
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
130
eval load data infile '$DRIZZLETEST_VARDIR/std_data_ln/rpl_loaddata.dat' into table t1 (@dummy,@n) set a= @n, c= (select str from t2 where num=@n);
134
# Bug#18628 mysql-test-run: security problem
136
# It should not be possible to load from a file outside of vardir
138
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
139
show variables like "secure_file_pri%";
140
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
141
select @@secure_file_priv;
142
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
143
set @@secure_file_priv= 0;
147
--replace_result $DRIZZLE_TEST_DIR DRIZZLE_TEST_DIR
148
--error ER_OPTION_PREVENTS_STATEMENT
149
eval load data infile '$DRIZZLE_TEST_DIR/t/loaddata.test' into table t1;
152
--replace_result $DRIZZLE_TEST_DIR DRIZZLE_TEST_DIR
153
--error ER_OPTION_PREVENTS_STATEMENT
154
eval select load_file("$DRIZZLE_TEST_DIR/t/loaddata.test");
160
# Bug#27670: LOAD DATA does not set CURRENT_TIMESTAMP default value for a
161
# TIMESTAMP field when no value has been provided.
163
create table t1(f1 int, f2 timestamp not null default current_timestamp);
164
create table t2(f1 int);
165
insert into t2 values(1),(2);
167
eval select * into outfile '$DRIZZLETEST_VARDIR/tmp/t2' from t2;
168
--error ER_WARN_TOO_FEW_RECORDS
169
eval load data infile '$DRIZZLETEST_VARDIR/tmp/t2' into table t1;
171
select f1 from t1 where f2 IS NOT NULL order by f1;
172
remove_file $DRIZZLETEST_VARDIR/tmp/t2;
175
eval SELECT * INTO OUTFILE '$DRIZZLETEST_VARDIR/tmp/t2'
176
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n'
178
--error ER_WARN_TOO_FEW_RECORDS
179
eval load data infile '$DRIZZLETEST_VARDIR/tmp/t2' into table t1
180
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n';
182
select f1 from t1 where f2 IS NOT NULL order by f1;
183
remove_file $DRIZZLETEST_VARDIR/tmp/t2;
187
# Bug#29442: SELECT INTO OUTFILE FIELDS ENCLOSED BY digit, minus sign etc
188
# corrupts non-string fields containing this character.
191
CREATE TABLE t1 (c1 INT, c2 TIMESTAMP, c3 REAL, c4 DOUBLE);
193
INSERT INTO t1 (c1, c2, c3, c4) VALUES (10, '1970-02-01 01:02:03', 1.1E-100, 1.1E+100);
196
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
197
eval SELECT * INTO OUTFILE '$DRIZZLETEST_VARDIR/tmp/t1' FIELDS ENCLOSED BY '-' FROM t1;
198
#cat_file $DRIZZLETEST_VARDIR/tmp/t1;
203
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
204
eval LOAD DATA INFILE '$DRIZZLETEST_VARDIR/tmp/t1' INTO TABLE t1 FIELDS ENCLOSED BY '-';
207
remove_file $DRIZZLETEST_VARDIR/tmp/t1;