~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/t/loaddata.test

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Some simple test of load data
 
3
#
 
4
 
 
5
--disable_warnings
 
6
drop table if exists t1, t2;
 
7
--enable_warnings
 
8
 
 
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;
 
12
SELECT * from t1;
 
13
truncate table t1;
 
14
 
 
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
select concat('|',a,'|'), concat('|',b,'|') from t1;
 
22
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
select * from t1;
 
27
truncate table t1;
 
28
 
 
29
# The empty line last comes from the end line field in the file
 
30
select * from t1;
 
31
drop table t1;
 
32
 
 
33
#
 
34
# Bug #11203: LOAD DATA does not accept same characters for ESCAPED and
 
35
# ENCLOSED
 
36
#
 
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);
 
39
select * from t1;
 
40
drop table t1;
 
41
 
 
42
#
 
43
# Bug #29294 SELECT INTO OUTFILE/LOAD DATA INFILE with special
 
44
# characters in the FIELDS ENCLOSED BY clause
 
45
#
 
46
 
 
47
CREATE TABLE t1 (
 
48
  id INT AUTO_INCREMENT PRIMARY KEY,
 
49
  c1 VARCHAR(255)
 
50
);
 
51
 
 
52
CREATE TABLE t2 (
 
53
  id INT,
 
54
  c2 VARCHAR(255)
 
55
);
 
56
 
 
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.');
 
62
SELECT * FROM t1;
 
63
 
 
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;
 
67
 
 
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;
 
72
 
 
73
remove_file $MYSQLTEST_VARDIR/tmp/t1;
 
74
DROP TABLE t1,t2;
 
75
 
 
76
# End of 4.1 tests
 
77
 
 
78
#
 
79
# Let us test extended LOAD DATA features
 
80
#
 
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);
 
84
select * from t1;
 
85
truncate table t1;
 
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);
 
89
select * from t1;
 
90
truncate table t1;
 
91
# we even can use variables in set clause, and missed columns will be set
 
92
# with default values
 
93
set @c:=123;
 
94
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, b) set c= if(@a is null,@c,b);
 
95
select * from t1;
 
96
# let us test side-effect of such load
 
97
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, @b);
 
98
select * from t1;
 
99
select @a, @b;
 
100
truncate table t1;
 
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";
 
103
select * from t1;
 
104
truncate table t1;
 
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));
 
107
select * from t1;
 
108
# and this should bark
 
109
--error 1409 
 
110
load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, @b);
 
111
 
 
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');
 
115
truncate table t1;
 
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);
 
117
select * from t1;
 
118
 
 
119
#
 
120
# Bug#18628 mysql-test-run: security problem
 
121
#
 
122
# It should not be possible to load from a file outside of vardir
 
123
 
 
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;
 
128
--error 1238
 
129
set @@secure_file_priv= 0;
 
130
 
 
131
# Test "load data"
 
132
truncate table t1;
 
133
--replace_result $DRIZZLE_TEST_DIR DRIZZLE_TEST_DIR
 
134
--error 1290
 
135
eval load data infile '$DRIZZLE_TEST_DIR/t/loaddata.test' into table t1;
 
136
select * from t1;
 
137
 
 
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");
 
141
 
 
142
# cleanup
 
143
drop table t1, t2;
 
144
 
 
145
#
 
146
# Bug#27670: LOAD DATA does not set CURRENT_TIMESTAMP default value for a
 
147
#            TIMESTAMP field when no value has been provided.
 
148
#
 
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);
 
152
disable_query_log;
 
153
eval select * into outfile '$MYSQLTEST_VARDIR/tmp/t2' from t2;
 
154
--error 1261
 
155
eval load data infile '$MYSQLTEST_VARDIR/tmp/t2' into table t1;
 
156
enable_query_log;
 
157
select f1 from t1 where f2 IS NOT NULL order by f1;
 
158
remove_file $MYSQLTEST_VARDIR/tmp/t2;
 
159
delete from t1;
 
160
disable_query_log;
 
161
eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t2'
 
162
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n'
 
163
FROM t2;
 
164
--error 1261
 
165
eval load data infile '$MYSQLTEST_VARDIR/tmp/t2' into table t1
 
166
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n';
 
167
enable_query_log;
 
168
select f1 from t1 where f2 IS NOT NULL order by f1;
 
169
remove_file $MYSQLTEST_VARDIR/tmp/t2;
 
170
drop table t1,t2;
 
171
 
 
172
#
 
173
# Bug#29442: SELECT INTO OUTFILE FIELDS ENCLOSED BY digit, minus sign etc
 
174
#            corrupts non-string fields containing this character.
 
175
#
 
176
 
 
177
CREATE TABLE t1 (c1 INT, c2 TIMESTAMP, c3 REAL, c4 DOUBLE);
 
178
 
 
179
INSERT INTO t1 (c1, c2, c3, c4) VALUES (10, '1970-02-01 01:02:03', 1.1E-100, 1.1E+100);
 
180
SELECT * FROM t1;
 
181
 
 
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;
 
185
echo EOF;
 
186
 
 
187
TRUNCATE t1;
 
188
 
 
189
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
190
eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/t1' INTO TABLE t1 FIELDS ENCLOSED BY '-';
 
191
SELECT * FROM t1;
 
192
 
 
193
remove_file $MYSQLTEST_VARDIR/tmp/t1;
 
194
DROP TABLE t1;