~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/loaddata.test

  • Committer: Jay Pipes
  • Date: 2008-07-18 20:20:47 UTC
  • mto: This revision was merged to the branch mainline in revision 182.
  • Revision ID: jay@mysql.com-20080718202047-1tnd4i9z3k3cvg9v
DBUG entirely removed from server and client

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
 
--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;
14
 
SELECT * from t1;
15
 
truncate table t1;
16
 
 
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);
19
 
SELECT * from t1;
20
 
drop table t1;
21
 
 
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;
26
 
drop table t1;
27
 
 
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;
31
 
select * from t1;
32
 
truncate table t1;
33
 
 
34
 
# The empty line last comes from the end line field in the file
35
 
select * from t1;
36
 
drop table t1;
37
 
 
38
 
#
39
 
# Bug #11203: LOAD DATA does not accept same characters for ESCAPED and
40
 
# ENCLOSED
41
 
#
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);
45
 
select * from t1;
46
 
drop table t1;
47
 
 
48
 
#
49
 
# Bug #29294 SELECT INTO OUTFILE/LOAD DATA INFILE with special
50
 
# characters in the FIELDS ENCLOSED BY clause
51
 
#
52
 
 
53
 
CREATE TABLE t1 (
54
 
  id INT AUTO_INCREMENT PRIMARY KEY,
55
 
  c1 VARCHAR(255)
56
 
);
57
 
 
58
 
CREATE TABLE t2 (
59
 
  id INT,
60
 
  c2 VARCHAR(255)
61
 
);
62
 
 
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.');
68
 
SELECT * FROM t1;
69
 
 
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;
73
 
 
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;
78
 
 
79
 
remove_file $DRIZZLETEST_VARDIR/tmp/t1;
80
 
DROP TABLE t1,t2;
81
 
 
82
 
# End of 4.1 tests
83
 
 
84
 
#
85
 
# Let us test extended LOAD DATA features
86
 
#
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);
91
 
select * from t1;
92
 
truncate table t1;
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);
97
 
select * from t1;
98
 
truncate table t1;
99
 
# we even can use variables in set clause, and missed columns will be set
100
 
# with default values
101
 
set @c:=123;
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);
104
 
select * from t1;
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);
108
 
select * from t1;
109
 
select @a, @b;
110
 
truncate table t1;
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";
114
 
select * from t1;
115
 
truncate table t1;
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));
119
 
select * from t1;
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);
124
 
 
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');
128
 
truncate table t1;
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);
131
 
select * from t1;
132
 
 
133
 
#
134
 
# Bug#18628 mysql-test-run: security problem
135
 
#
136
 
# It should not be possible to load from a file outside of vardir
137
 
 
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;
144
 
 
145
 
# Test "load data"
146
 
truncate table t1;
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;
150
 
select * from t1;
151
 
 
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");
155
 
 
156
 
# cleanup
157
 
drop table t1, t2;
158
 
 
159
 
#
160
 
# Bug#27670: LOAD DATA does not set CURRENT_TIMESTAMP default value for a
161
 
#            TIMESTAMP field when no value has been provided.
162
 
#
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);
166
 
disable_query_log;
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;
170
 
enable_query_log;
171
 
select f1 from t1 where f2 IS NOT NULL order by f1;
172
 
remove_file $DRIZZLETEST_VARDIR/tmp/t2;
173
 
delete from t1;
174
 
disable_query_log;
175
 
eval SELECT * INTO OUTFILE '$DRIZZLETEST_VARDIR/tmp/t2'
176
 
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n'
177
 
FROM t2;
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';
181
 
enable_query_log;
182
 
select f1 from t1 where f2 IS NOT NULL order by f1;
183
 
remove_file $DRIZZLETEST_VARDIR/tmp/t2;
184
 
drop table t1,t2;
185
 
 
186
 
#
187
 
# Bug#29442: SELECT INTO OUTFILE FIELDS ENCLOSED BY digit, minus sign etc
188
 
#            corrupts non-string fields containing this character.
189
 
#
190
 
 
191
 
CREATE TABLE t1 (c1 INT, c2 TIMESTAMP, c3 REAL, c4 DOUBLE);
192
 
 
193
 
INSERT INTO t1 (c1, c2, c3, c4) VALUES (10, '1970-02-01 01:02:03', 1.1E-100, 1.1E+100);
194
 
SELECT * FROM t1;
195
 
 
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;
199
 
echo EOF;
200
 
 
201
 
TRUNCATE t1;
202
 
 
203
 
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
204
 
eval LOAD DATA INFILE '$DRIZZLETEST_VARDIR/tmp/t1' INTO TABLE t1 FIELDS ENCLOSED BY '-';
205
 
SELECT * FROM t1;
206
 
 
207
 
remove_file $DRIZZLETEST_VARDIR/tmp/t1;
208
 
DROP TABLE t1;