From 9cfc2e23cc0724bce53e6faf9854e461ee5ba404 Mon Sep 17 00:00:00 2001 From: Alexander Barkov <bar@mnogosearch.org> Date: Fri, 8 Feb 2013 12:51:38 +0400 Subject: [PATCH] Adding tests for TABLE_TYPE=CSV added: mysql-test/suite/connect/r/csv.result mysql-test/suite/connect/std_data/people.csv mysql-test/suite/connect/t/csv.test --- mysql-test/suite/connect/r/csv.result | 24 +++++++++ mysql-test/suite/connect/std_data/people.csv | 3 ++ mysql-test/suite/connect/t/csv.test | 56 ++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 mysql-test/suite/connect/r/csv.result create mode 100644 mysql-test/suite/connect/std_data/people.csv create mode 100644 mysql-test/suite/connect/t/csv.test diff --git a/mysql-test/suite/connect/r/csv.result b/mysql-test/suite/connect/r/csv.result new file mode 100644 index 0000000000..16859773c9 --- /dev/null +++ b/mysql-test/suite/connect/r/csv.result @@ -0,0 +1,24 @@ +# +# Testing errors +# +CREATE TABLE t1 +( +ID INT +) 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; +CREATE TABLE t1 +( +name CHAR(12), +birth DATE DATE_FORMAT='DD/MM/YY', +children SMALLINT(2) +) 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 +DROP TABLE t1; diff --git a/mysql-test/suite/connect/std_data/people.csv b/mysql-test/suite/connect/std_data/people.csv new file mode 100644 index 0000000000..64567aec9d --- /dev/null +++ b/mysql-test/suite/connect/std_data/people.csv @@ -0,0 +1,3 @@ +Name;birth;children +"Archibald";17/05/01;3 +"Nabucho";12/08/03;2 diff --git a/mysql-test/suite/connect/t/csv.test b/mysql-test/suite/connect/t/csv.test new file mode 100644 index 0000000000..070c131bc7 --- /dev/null +++ b/mysql-test/suite/connect/t/csv.test @@ -0,0 +1,56 @@ +let $MYSQLD_DATADIR= `select @@datadir`; +--copy_file $MYSQL_TEST_DIR/suite/connect/std_data/people.csv $MYSQLD_DATADIR/test/people.csv + +--echo # +--echo # Testing errors +--echo # +CREATE TABLE t1 +( + ID INT +) Engine=CONNECT TABLE_TYPE=CSV FILE_NAME='nonexistent.txt'; +--replace_regex /on .*test.nonexistent.txt/on DATADIR\/test\/nonexistent.txt/ +# TODO: check why this is needed for Windows +--replace_result Open(rt) Open(rb) +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # Testing examples from the manual +--echo # +CREATE TABLE t1 +( + name CHAR(12), + birth DATE DATE_FORMAT='DD/MM/YY', + children SMALLINT(2) +) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='people.csv' + HEADER=1 SEP_CHAR=';' QUOTED=1; +SELECT * FROM t1; +INSERT INTO t1 VALUES ('RONALD','1980-02-26',4); +SELECT * FROM t1; +DROP TABLE t1; +--chmod 0777 $MYSQLD_DATADIR/test/people.csv +--replace_result $MYSQLD_DATADIR DATADIR +--eval SELECT LOAD_FILE('$MYSQLD_DATADIR/test/people.csv'); + + +--echo # +--echo # Testing that the underlying file is created +--echo # +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; +DROP TABLE t1; +--chmod 0777 $MYSQLD_DATADIR/test/tmp.csv +--replace_result $MYSQLD_DATADIR DATADIR +--eval SELECT LOAD_FILE('$MYSQLD_DATADIR/test/tmp.csv'); + +# +# Clean up +# +--remove_file $MYSQLD_DATADIR/test/people.csv +--remove_file $MYSQLD_DATADIR/test/tmp.csv -- 2.30.9