3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
12 # Test cases for CSV virtual table.
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
18 ifcapable !vtab||!cte { finish_test ; return }
20 load_static_extension db csv
23 CREATE VIRTUAL TABLE temp.t1 USING csv(
32 SELECT * FROM t1 WHERE c1=10;
35 SELECT * FROM t1 WHERE c1='10';
43 CREATE VIRTUAL TABLE temp.t2 USING csv(
51 schema='CREATE TABLE t2(a INT, b TEXT, c REAL, d BLOB)'
53 SELECT * FROM t2 WHERE a=9;
56 SELECT * FROM t2 WHERE b=10;
59 SELECT * FROM t2 WHERE c=11;
62 SELECT * FROM t2 WHERE d=12;
65 SELECT * FROM t2 WHERE d='12';
68 SELECT * FROM t2 WHERE a='9';
73 CREATE VIRTUAL TABLE temp.t3 USING csv(
82 'CREATE TABLE t3(a PRIMARY KEY,b TEXT,c TEXT,d TEXT) WITHOUT ROWID',
85 SELECT a FROM t3 WHERE b=6 OR c=7 OR d=12 ORDER BY +a;
88 SELECT a FROM t3 WHERE +b=6 OR c=7 OR d=12 ORDER BY +a;
91 # The rowid column is not visible on a WITHOUT ROWID virtual table
92 do_catchsql_test 3.2 {
93 SELECT rowid, a FROM t3;
94 } {1 {no such column: rowid}}
96 # Multi-column WITHOUT ROWID virtual tables may not be writable.
97 do_catchsql_test 4.0 {
99 CREATE VIRTUAL TABLE temp.t4 USING csv_wr(
107 'CREATE TABLE t3(a,b,c,d,PRIMARY KEY(a,b)) WITHOUT ROWID',
110 } {1 {vtable constructor failed: t4}}
112 # WITHOUT ROWID tables with a single-column PRIMARY KEY may be writable.
113 do_catchsql_test 4.1 {
114 DROP TABLE IF EXISTS t4;
115 CREATE VIRTUAL TABLE temp.t4 USING csv_wr(
123 'CREATE TABLE t3(a,b,c,d,PRIMARY KEY(b)) WITHOUT ROWID',
128 do_catchsql_test 4.2 {
129 DROP TABLE IF EXISTS t5;
130 CREATE VIRTUAL TABLE temp.t5 USING csv_wr(
138 'CREATE TABLE t3(a,b,c,d) WITHOUT ROWID',
141 } {1 {vtable constructor failed: t5}}
144 # Memory leak reported on the sqlite-users mailing list by Ralf Junker.
146 do_catchsql_test 4.3 {
147 CREATE VIRTUAL TABLE IF NOT EXISTS temp.t1
148 USING csv(filename='FileDoesNotExist.csv');
149 } {1 {cannot open 'FileDoesNotExist.csv' for reading}}
152 # Problem with single-column CSV support reported on the mailing list
155 do_execsql_test 4.4 {
156 CREATE VIRTUAL TABLE temp.trent USING csv(data='1');