1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
SET NAMES utf8;
#
# Testing errors
#
CREATE TABLE t1
(
ID INT NOT NULL
) Engine=CONNECT TABLE_TYPE=CSV FILE_NAME='nonexistent.txt';
SELECT * FROM t1;
ID
Warnings:
Warning 1105 Open(rb) error 2 on DATADIR/test/nonexistent.txt: No such file or directory
DROP TABLE t1;
#
# Testing examples from the manual
#
CREATE TABLE t1
(
name CHAR(12) NOT NULL,
birth DATE NOT NULL DATE_FORMAT='DD/MM/YY',
children SMALLINT(2) NOT NULL
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='people.csv'
HEADER=1 SEP_CHAR=';' QUOTED=1;
SELECT * FROM t1;
name birth children
Archibald 2001-05-17 3
Nabucho 2003-08-12 2
INSERT INTO t1 VALUES ('RONALD','1980-02-26',4);
SELECT * FROM t1;
name birth children
Archibald 2001-05-17 3
Nabucho 2003-08-12 2
RONALD 1980-02-26 4
DROP TABLE t1;
SELECT REPLACE(LOAD_FILE('DATADIR/test/people.csv'),'\r\n','\n');;
REPLACE(LOAD_FILE('DATADIR/test/people.csv'),'\r\n','\n')
Name;birth;children
"Archibald";17/05/01;3
"Nabucho";12/08/03;2
"RONALD";26/02/80;4
#
# Testing READONLY tables
#
CREATE TABLE t1
(
name CHAR(12) NOT NULL,
birth DATE NOT NULL DATE_FORMAT='DD/MM/YY',
children SMALLINT(2) NOT NULL
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='people.csv'
HEADER=1 SEP_CHAR=';' QUOTED=1 READONLY=yes;
INSERT INTO t1 VALUES ('BILL','1973-06-30',5);
ERROR HY000: Table 't1' is read only
UPDATE t1 SET children=6 WHERE name='BILL';
ERROR HY000: Got error 174 'Cannot modify this read/only protected table' from CONNECT
DELETE FROM t1 WHERE name='BILL';
ERROR HY000: Got error 174 'Cannot modify this read/only protected table' from CONNECT
TRUNCATE TABLE t1;
ERROR HY000: Table 't1' is read only
SELECT * FROM t1;
name birth children
Archibald 2001-05-17 3
Nabucho 2003-08-12 2
RONALD 1980-02-26 4
ALTER TABLE t1 READONLY=no;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`name` char(12) NOT NULL,
`birth` date NOT NULL `DATE_FORMAT`='DD/MM/YY',
`children` smallint(2) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`=CSV `FILE_NAME`='people.csv' `HEADER`=1 `SEP_CHAR`=';' `QUOTED`=1 `READONLY`=no
INSERT INTO t1 VALUES ('BILL','1973-06-30',5);
SELECT * FROM t1;
name birth children
Archibald 2001-05-17 3
Nabucho 2003-08-12 2
RONALD 1980-02-26 4
BILL 1973-06-30 5
ALTER TABLE t1 READONLY=1;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`name` char(12) NOT NULL,
`birth` date NOT NULL `DATE_FORMAT`='DD/MM/YY',
`children` smallint(2) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`=CSV `FILE_NAME`='people.csv' `HEADER`=1 `SEP_CHAR`=';' `QUOTED`=1 `READONLY`=1
INSERT INTO t1 VALUES ('BILL','1973-06-30',5);
ERROR HY000: Table 't1' is read only
SELECT * FROM t1;
name birth children
Archibald 2001-05-17 3
Nabucho 2003-08-12 2
RONALD 1980-02-26 4
BILL 1973-06-30 5
DROP TABLE t1;
#
# Testing that the underlying file is created
#
CREATE TABLE t1
(
c1 CHAR(12) NOT NULL,
c2 CHAR(12) NOT NULL
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='tmp.csv'
HEADER=1 SEP_CHAR=',' QUOTED=1;
INSERT INTO t1 VALUES (10,10),(20,20),(300,300),(4000,4000), ('a b','c d');
SELECT * FROM t1;
c1 c2
10 10
20 20
300 300
4000 4000
a b c d
DROP TABLE t1;
SELECT REPLACE(LOAD_FILE('DATADIR/test/tmp.csv'),'\r\n','\n');;
REPLACE(LOAD_FILE('DATADIR/test/tmp.csv'),'\r\n','\n')
"c1","c2"
"10","10"
"20","20"
"300","300"
"4000","4000"
"a b","c d"
#
# Creating a CSV table from a MyISAM table
#
CREATE TABLE t1 (a VARCHAR(10) NOT NULL, b INT NOT NULL) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('test1',1), ('test2',2);
CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='t2.csv'
AS SELECT * FROM t1;
SELECT * FROM t2;
a b
test1 1
test2 2
DROP TABLE t2;
DROP TABLE t1;
SELECT REPLACE(LOAD_FILE('DATADIR/test/t2.csv'),'\r\n','\n');;
REPLACE(LOAD_FILE('DATADIR/test/t2.csv'),'\r\n','\n')
test1,1
test2,2
#
# Testing international data
#
CREATE TABLE t1
(
c1 CHAR(12) NOT NULL
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='t1.csv'
CHARSET=utf8;
INSERT INTO t1 VALUES ('á');
SELECT * FROM t1;
c1
á
DROP TABLE t1;
SELECT HEX(REPLACE(LOAD_FILE('DATADIR/test/t1.csv'),'\r\n','\n'));;
HEX(REPLACE(LOAD_FILE('DATADIR/test/t1.csv'),'\r\n','\n'))
C3A10A
CREATE TABLE t1
(
c1 CHAR(12) NOT NULL
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='t1.csv'
CHARSET=utf8 DATA_CHARSET=latin1;
INSERT INTO t1 VALUES ('á');
SELECT * FROM t1;
c1
á
DROP TABLE t1;
SELECT HEX(REPLACE(LOAD_FILE('DATADIR/test/t1.csv'),'\r\n','\n'));;
HEX(REPLACE(LOAD_FILE('DATADIR/test/t1.csv'),'\r\n','\n'))
E10A
CREATE TABLE t1
(
c1 CHAR(12) NOT NULL
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='t1.csv';
INSERT INTO t1 VALUES ('á');
SELECT * FROM t1;
c1
á
DROP TABLE t1;
SELECT HEX(REPLACE(LOAD_FILE('DATADIR/test/t1.csv'),'\r\n','\n'));;
HEX(REPLACE(LOAD_FILE('DATADIR/test/t1.csv'),'\r\n','\n'))
E10A
CREATE TABLE t1
(
c1 CHAR(12) NOT NULL
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='t1.csv'
CHARSET=latin1;
INSERT INTO t1 VALUES ('á');
SELECT * FROM t1;
c1
á
DROP TABLE t1;
SELECT HEX(REPLACE(LOAD_FILE('DATADIR/test/t1.csv'),'\r\n','\n'));;
HEX(REPLACE(LOAD_FILE('DATADIR/test/t1.csv'),'\r\n','\n'))
E10A
CREATE TABLE t1
(
c1 CHAR(12) NOT NULL
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='t1.csv'
CHARSET=latin1 DATA_CHARSET=utf8;
INSERT INTO t1 VALUES ('á');
SELECT * FROM t1;
c1
á
DROP TABLE t1;
SELECT HEX(REPLACE(LOAD_FILE('DATADIR/test/t1.csv'),'\r\n','\n'));;
HEX(REPLACE(LOAD_FILE('DATADIR/test/t1.csv'),'\r\n','\n'))
C3A10A
CREATE TABLE t1
(
c1 CHAR(12) CHARACTER SET latin1 NOT NULL,
c2 CHAR(12) CHARACTER SET utf8 NOT NULL
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='t1.csv';
INSERT INTO t1 VALUES ('á','á');
SELECT * FROM t1;
c1 c2
á á
DROP TABLE t1;
SELECT HEX(REPLACE(LOAD_FILE('DATADIR/test/t1.csv'),'\r\n','\n'));;
HEX(REPLACE(LOAD_FILE('DATADIR/test/t1.csv'),'\r\n','\n'))
E12CC3A10A
|