~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/loaddata.test

  • Committer: lbieber
  • Date: 2010-09-26 02:09:47 UTC
  • mfrom: (1791.3.5 local-catalog)
  • mto: This revision was merged to the branch mainline in revision 1794.
  • Revision ID: lbieber@orisndriz08-20100926020947-o28psemscwvlwg05
Merge Monty - Beginning of catalog support, adds a default local catalog. 

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
 
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
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);
 
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
#