2003-05-05 13:52:39 +02:00
#
# Some simple test of load data
#
2003-05-21 20:39:58 +02:00
--disable_warnings
2005-03-16 10:13:35 +01:00
drop table if exists t1, t2;
2003-05-21 20:39:58 +02:00
--enable_warnings
2003-05-05 13:52:39 +02:00
create table t1 (a date, b date, c date not null, d date);
2006-01-24 08:30:54 +01:00
load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',';
load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES;
2003-05-05 13:52:39 +02:00
SELECT * from t1;
2003-05-26 10:47:03 +02:00
truncate table t1;
2006-01-24 08:30:54 +01:00
load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',' LINES STARTING BY ',' (b,c,d);
2003-05-26 10:47:03 +02:00
SELECT * from t1;
2003-05-05 13:52:39 +02:00
drop table t1;
2003-05-26 10:47:03 +02:00
2003-08-22 03:07:40 +02:00
create table t1 (a text, b text);
2006-01-24 08:30:54 +01:00
load data infile '../std_data_ln/loaddata2.dat' into table t1 fields terminated by ',' enclosed by '''';
2003-08-22 03:07:40 +02:00
select concat('|',a,'|'), concat('|',b,'|') from t1;
drop table t1;
2003-12-14 05:39:52 +01:00
create table t1 (a int, b char(10));
2006-01-24 08:30:54 +01:00
load data infile '../std_data_ln/loaddata3.dat' into table t1 fields terminated by '' enclosed by '' ignore 1 lines;
2003-12-14 05:39:52 +01:00
select * from t1;
truncate table t1;
2006-01-24 08:30:54 +01:00
load data infile '../std_data_ln/loaddata4.dat' into table t1 fields terminated by '' enclosed by '' lines terminated by '' ignore 1 lines;
2003-12-14 05:39:52 +01:00
# The empty line last comes from the end line field in the file
select * from t1;
drop table t1;
2005-09-22 09:46:01 +02:00
#
# Bug #12053 LOAD DATA INFILE ignores NO_AUTO_VALUE_ON_ZERO setting
#
SET @OLD_SQL_MODE=@@SQL_MODE, @@SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
create table t1(id integer not null auto_increment primary key);
insert into t1 values(0);
disable_query_log;
2006-01-24 08:30:54 +01:00
eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t1' from t1;
2005-09-22 09:46:01 +02:00
delete from t1;
2006-01-24 08:30:54 +01:00
eval load data infile '$MYSQLTEST_VARDIR/tmp/t1' into table t1;
2005-09-22 09:46:01 +02:00
enable_query_log;
select * from t1;
2006-01-24 08:30:54 +01:00
--exec rm $MYSQLTEST_VARDIR/tmp/t1
2005-09-22 09:46:01 +02:00
disable_query_log;
2006-01-24 08:30:54 +01:00
eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t1'
2005-09-22 09:46:01 +02:00
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n'
FROM t1;
delete from t1;
2006-01-24 08:30:54 +01:00
eval load data infile '$MYSQLTEST_VARDIR/tmp/t1' into table t1
2005-09-22 09:46:01 +02:00
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n';
enable_query_log;
select * from t1;
2006-01-24 08:30:54 +01:00
--exec rm $MYSQLTEST_VARDIR/tmp/t1
2005-09-22 09:46:01 +02:00
SET @@SQL_MODE=@OLD_SQL_MODE;
2005-09-23 14:37:22 +02:00
drop table t1;
2005-09-22 09:46:01 +02:00
2005-06-23 01:14:14 +02:00
#
# Bug #11203: LOAD DATA does not accept same characters for ESCAPED and
# ENCLOSED
#
create table t1 (a varchar(20), b varchar(20));
2006-01-24 08:30:54 +01:00
load data infile '../std_data_ln/loaddata_dq.dat' into table t1 fields terminated by ',' enclosed by '"' escaped by '"' (a,b);
2005-06-23 01:14:14 +02:00
select * from t1;
drop table t1;
2005-10-22 02:57:51 +02:00
2005-07-28 02:22:47 +02:00
# End of 4.1 tests
2005-07-28 16:09:54 +02:00
2005-03-16 02:32:47 +01:00
#
# Let us test extended LOAD DATA features
#
create table t1 (a int default 100, b int, c varchar(60));
# we can do something like this
2006-01-24 08:30:54 +01:00
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set b=@b+10, c=concat("b=",@b);
2005-03-16 02:32:47 +01:00
select * from t1;
truncate table t1;
# we can use filled fields in expressions
# we also assigning NULL value to field with non-NULL default here
2006-01-24 08:30:54 +01:00
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set c= if(a is null,"oops",a);
2005-03-16 02:32:47 +01:00
select * from t1;
truncate table t1;
# we even can use variables in set clause, and missed columns will be set
# with default values
set @c:=123;
2006-01-24 08:30:54 +01:00
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, b) set c= if(@a is null,@c,b);
2005-03-16 02:32:47 +01:00
select * from t1;
# let us test side-effect of such load
2006-01-24 08:30:54 +01:00
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, @b);
2005-03-16 02:32:47 +01:00
select * from t1;
select @a, @b;
truncate table t1;
# now going to test fixed field-row file format
2006-01-24 08:30:54 +01:00
load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, b) set c="Wow";
2005-03-16 02:32:47 +01:00
select * from t1;
truncate table t1;
# this also should work
2006-01-24 08:30:54 +01:00
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));
2005-03-16 02:32:47 +01:00
select * from t1;
# and this should bark
--error 1409
2006-01-24 08:30:54 +01:00
load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, @b);
2005-03-16 10:13:35 +01:00
# Now let us test LOAD DATA with subselect
create table t2 (num int primary key, str varchar(10));
insert into t2 values (10,'Ten'), (15,'Fifteen');
truncate table t1;
2006-01-24 08:30:54 +01:00
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);
2005-03-16 10:13:35 +01:00
select * from t1;
2007-02-14 14:44:34 +01:00
#
# Bug#18628 mysql-test-run: security problem
#
# It should not be possible to load from a file outside of vardir
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
show variables like "secure_file_pri%";
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
select @@secure_file_priv;
--error 1238
set @@secure_file_priv= 0;
# Test "load data"
truncate table t1;
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
--error 1290
eval load data infile '$MYSQL_TEST_DIR/Makefile' into table t1;
select * from t1;
# Test "load_file" returns NULL
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
eval select load_file("$MYSQL_TEST_DIR/Makefile");
2005-03-16 10:13:35 +01:00
# cleanup
drop table t1, t2;
2005-10-26 23:11:08 +02:00
# End of 5.0 tests