loaddata.test 4.76 KB
Newer Older
1 2 3 4
#
# Some simple test of load data
#

unknown's avatar
unknown committed
5
--disable_warnings
6
drop table if exists t1, t2;
unknown's avatar
unknown committed
7
--enable_warnings
8 9

create table t1 (a date, b date, c date not null, d date);
10 11
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;
12
SELECT * from t1;
13 14
truncate table t1;

15
load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',' LINES STARTING BY ',' (b,c,d);
16
SELECT * from t1;
17
drop table t1;
18

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 22
select concat('|',a,'|'), concat('|',b,'|') from t1;
drop table t1;
23 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;
26 27
select * from t1;
truncate table t1;
28
load data infile '../std_data_ln/loaddata4.dat' into table t1 fields terminated by '' enclosed by '' lines terminated by '' ignore 1 lines;
29 30 31 32 33

# The empty line last comes from the end line field in the file
select * from t1;
drop table t1;

34 35 36 37 38 39 40
#
# 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;
41
eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t1' from t1;
42
delete from t1;
43
eval load data infile '$MYSQLTEST_VARDIR/tmp/t1' into table t1;
44 45
enable_query_log;
select * from t1;
46
--exec rm $MYSQLTEST_VARDIR/tmp/t1
47 48

disable_query_log;
49
eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t1'
50 51 52
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n'
FROM t1;
delete from t1;
53
eval load data infile '$MYSQLTEST_VARDIR/tmp/t1' into table t1
54 55 56
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n';
enable_query_log;
select * from t1;
57
--exec rm $MYSQLTEST_VARDIR/tmp/t1
58
SET @@SQL_MODE=@OLD_SQL_MODE;
unknown's avatar
unknown committed
59
drop table t1;
60

61 62 63 64 65
#
# Bug #11203: LOAD DATA does not accept same characters for ESCAPED and
# ENCLOSED
#
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);
67 68
select * from t1;
drop table t1;
69

70
# End of 4.1 tests
unknown's avatar
unknown committed
71

unknown's avatar
unknown committed
72 73 74 75 76
#
# 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
77
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set b=@b+10, c=concat("b=",@b);
unknown's avatar
unknown committed
78 79 80 81
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
82
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set c= if(a is null,"oops",a);
unknown's avatar
unknown committed
83 84 85 86 87
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;
88
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, b) set c= if(@a is null,@c,b);
unknown's avatar
unknown committed
89 90
select * from t1;
# let us test side-effect of such load
91
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, @b);
unknown's avatar
unknown committed
92 93 94 95
select * from t1;
select @a, @b;
truncate table t1;
# now going to test fixed field-row file format
96
load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, b) set c="Wow";
unknown's avatar
unknown committed
97 98 99
select * from t1;
truncate table t1;
# this also should work
100
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));
unknown's avatar
unknown committed
101 102 103
select * from t1;
# and this should bark
--error 1409 
104
load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, @b);
105 106 107 108 109

# 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;
110
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);
111 112 113 114
select * from t1;

# cleanup
drop table t1, t2;
115 116

# End of 5.0 tests
unknown's avatar
unknown committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140


#
# Bug#12448 LOAD DATA / SELECT INTO OUTFILE
# doesn't work with multibyte path name
#
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (1);
SET NAMES latin1;
SET character_set_filesystem=filename;
select @@character_set_filesystem;
SELECT * INTO OUTFILE 't-1' FROM t1;
DELETE FROM t1;
LOAD DATA INFILE 't-1' INTO TABLE t1;
SELECT * FROM t1;
DELETE FROM t1;
SET character_set_filesystem=latin1;
select @@character_set_filesystem;
LOAD DATA INFILE 't@002d1' INTO TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
--exec rm $MYSQL_TEST_DIR/var/master-data/test/t@002d1
SET character_set_filesystem=default;
select @@character_set_filesystem;