~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/loaddata.test

  • Committer: Brian Aker
  • Date: 2010-10-26 21:34:15 UTC
  • mto: (1887.2.1 merge)
  • mto: This revision was merged to the branch mainline in revision 1888.
  • Revision ID: brian@tangent.org-20101026213415-666ezkzx542h8uf0
Adding cache.h for definition.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
--enable_warnings
8
8
 
9
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;
 
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
12
SELECT * from t1;
13
13
truncate table t1;
14
14
 
15
 
load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',' LINES STARTING BY ',' (b,c,d);
 
15
load data infile '../../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',' LINES STARTING BY ',' (b,c,d);
16
16
SELECT * from t1;
17
17
drop table t1;
18
18
 
19
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 '''';
 
20
load data infile '../../std_data_ln/loaddata2.dat' into table t1 fields terminated by ',' enclosed by '''';
21
21
select concat('|',a,'|'), concat('|',b,'|') from t1;
22
22
drop table t1;
23
23
 
24
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;
 
25
load data infile '../../std_data_ln/loaddata3.dat' into table t1 fields terminated by '' enclosed by '' ignore 1 lines;
26
26
select * from t1;
27
27
truncate table t1;
28
28
 
35
35
# ENCLOSED
36
36
#
37
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);
 
38
load data infile '../../std_data_ln/loaddata_dq.dat' into table t1 fields terminated by ',' enclosed by '"' escaped by '"' (a,b);
39
39
select * from t1;
40
40
drop table t1;
41
41
 
61
61
  ('.r.'), ('.rr.'), ('.rrr.'), ('.rrrr.');
62
62
SELECT * FROM t1;
63
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;
 
64
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
 
65
eval SELECT * INTO OUTFILE '$DRIZZLETEST_VARDIR/tmp/t1' FIELDS ENCLOSED BY 'r' FROM t1;
 
66
cat_file $DRIZZLETEST_VARDIR/tmp/t1;
67
67
 
68
 
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
69
 
eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/t1' INTO TABLE t2 FIELDS ENCLOSED BY 'r';
 
68
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
 
69
eval LOAD DATA INFILE '$DRIZZLETEST_VARDIR/tmp/t1' INTO TABLE t2 FIELDS ENCLOSED BY 'r';
70
70
SELECT t1.id, c1, c2 FROM t1 LEFT  JOIN t2 ON t1.id=t2.id WHERE c1 != c2;
71
71
SELECT t1.id, c1, c2 FROM t1 RIGHT JOIN t2 ON t1.id=t2.id WHERE c1 != c2;
72
72
 
73
 
remove_file $MYSQLTEST_VARDIR/tmp/t1;
 
73
remove_file $DRIZZLETEST_VARDIR/tmp/t1;
74
74
DROP TABLE t1,t2;
75
75
 
76
76
# End of 4.1 tests
80
80
#
81
81
create table t1 (a int default 100, b int, c varchar(60));
82
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);
 
83
load data infile '../../std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set b=@b+10, c=concat("b=",@b);
84
84
select * from t1;
85
85
truncate table t1;
86
86
# we can use filled fields in expressions 
87
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);
 
88
load data infile '../../std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set c= if(a is null,"oops",a);
89
89
select * from t1;
90
90
truncate table t1;
91
91
# we even can use variables in set clause, and missed columns will be set
92
92
# with default values
93
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);
 
94
load data infile '../../std_data_ln/rpl_loaddata.dat' into table t1 (@a, b) set c= if(@a is null,@c,b);
95
95
select * from t1;
96
96
# let us test side-effect of such load
97
 
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, @b);
 
97
load data infile '../../std_data_ln/rpl_loaddata.dat' into table t1 (@a, @b);
98
98
select * from t1;
99
99
select @a, @b;
100
100
truncate table t1;
101
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";
 
102
load data infile '../../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, b) set c="Wow";
103
103
select * from t1;
104
104
truncate table t1;
105
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));
 
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
107
select * from t1;
108
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);
 
109
--error ER_LOAD_FROM_FIXED_SIZE_ROWS_TO_VAR 
 
110
load data infile '../../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, @b);
111
111
 
112
112
# Now let us test LOAD DATA with subselect
113
113
create table t2 (num int primary key, str varchar(10));
114
114
insert into t2 values (10,'Ten'), (15,'Fifteen');
115
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);
 
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
117
select * from t1;
118
118
 
119
119
#
121
121
#
122
122
# It should not be possible to load from a file outside of vardir
123
123
 
124
 
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
124
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
125
125
show variables like "secure_file_pri%";
126
 
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 
126
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
127
127
select @@secure_file_priv;
128
 
--error 1238
 
128
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
129
129
set @@secure_file_priv= 0;
130
130
 
131
131
# Test "load data"
132
132
truncate table t1;
133
133
--replace_result $DRIZZLE_TEST_DIR DRIZZLE_TEST_DIR
134
 
--error 1290
 
134
--error ER_OPTION_PREVENTS_STATEMENT
135
135
eval load data infile '$DRIZZLE_TEST_DIR/t/loaddata.test' into table t1;
136
136
select * from t1;
137
137
 
138
 
# Test "load_file" returns NULL
139
138
--replace_result $DRIZZLE_TEST_DIR DRIZZLE_TEST_DIR
 
139
--error ER_OPTION_PREVENTS_STATEMENT
140
140
eval select load_file("$DRIZZLE_TEST_DIR/t/loaddata.test");
141
141
 
142
142
# cleanup
150
150
create table t2(f1 int);
151
151
insert into t2 values(1),(2);
152
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;
 
153
eval select * into outfile '$DRIZZLETEST_VARDIR/tmp/t2' from t2;
 
154
--error ER_WARN_TOO_FEW_RECORDS
 
155
eval load data infile '$DRIZZLETEST_VARDIR/tmp/t2' into table t1;
156
156
enable_query_log;
157
157
select f1 from t1 where f2 IS NOT NULL order by f1;
158
 
remove_file $MYSQLTEST_VARDIR/tmp/t2;
 
158
remove_file $DRIZZLETEST_VARDIR/tmp/t2;
159
159
delete from t1;
160
160
disable_query_log;
161
 
eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t2'
 
161
eval SELECT * INTO OUTFILE '$DRIZZLETEST_VARDIR/tmp/t2'
162
162
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n'
163
163
FROM t2;
164
 
--error 1261
165
 
eval load data infile '$MYSQLTEST_VARDIR/tmp/t2' into table t1
 
164
--error ER_WARN_TOO_FEW_RECORDS
 
165
eval load data infile '$DRIZZLETEST_VARDIR/tmp/t2' into table t1
166
166
FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n';
167
167
enable_query_log;
168
168
select f1 from t1 where f2 IS NOT NULL order by f1;
169
 
remove_file $MYSQLTEST_VARDIR/tmp/t2;
 
169
remove_file $DRIZZLETEST_VARDIR/tmp/t2;
170
170
drop table t1,t2;
171
171
 
172
172
#
179
179
INSERT INTO t1 (c1, c2, c3, c4) VALUES (10, '1970-02-01 01:02:03', 1.1E-100, 1.1E+100);
180
180
SELECT * FROM t1;
181
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;
 
182
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
 
183
eval SELECT * INTO OUTFILE '$DRIZZLETEST_VARDIR/tmp/t1' FIELDS ENCLOSED BY '-' FROM t1;
 
184
#cat_file $DRIZZLETEST_VARDIR/tmp/t1;
185
185
echo EOF;
186
186
 
187
187
TRUNCATE t1;
188
188
 
189
 
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
190
 
eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/t1' INTO TABLE t1 FIELDS ENCLOSED BY '-';
 
189
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
 
190
eval LOAD DATA INFILE '$DRIZZLETEST_VARDIR/tmp/t1' INTO TABLE t1 FIELDS ENCLOSED BY '-';
191
191
SELECT * FROM t1;
192
192
 
193
 
remove_file $MYSQLTEST_VARDIR/tmp/t1;
 
193
remove_file $DRIZZLETEST_VARDIR/tmp/t1;
194
194
DROP TABLE t1;