1# 2015 Jun 10 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 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. 9# 10#*********************************************************************** 11# 12# Tests focusing on fts5 tables with the columnsize=0 option. 13# 14 15source [file join [file dirname [info script]] fts5_common.tcl] 16set testprefix fts5columnsize 17 18# If SQLITE_ENABLE_FTS5 is defined, omit this file. 19ifcapable !fts5 { 20 finish_test 21 return 22} 23 24#------------------------------------------------------------------------- 25# Check that the option can be parsed and that the %_docsize table is 26# only created if it is set to true. 27# 28foreach {tn outcome stmt} { 29 1 0 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=0) } 30 2 1 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=1) } 31 3 0 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize='0') } 32 4 1 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize='1') } 33 5 2 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize='') } 34 6 2 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=2) } 35 7 1 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=0, columnsize=1) } 36 8 1 { CREATE VIRTUAL TABLE t1 USING fts5(x) } 37 9 2 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=11) } 38} { 39 execsql { 40 DROP TABLE IF EXISTS t1; 41 } 42 if {$outcome==2} { 43 do_catchsql_test 1.$tn.1 $stmt {1 {malformed columnsize=... directive}} 44 } else { 45 do_execsql_test 1.$tn.2 $stmt 46 do_execsql_test 1.$tn.3 { 47 SELECT count(*) FROM sqlite_master WHERE name = 't1_docsize' 48 } $outcome 49 } 50} 51 52#------------------------------------------------------------------------- 53# Run tests on a table with no %_content or %_docsize backing store. 54# 55do_execsql_test 2.0 { 56 CREATE VIRTUAL TABLE t2 USING fts5(x, columnsize=0, content=''); 57} 58do_catchsql_test 2.1 { 59 INSERT INTO t2 VALUES('a b c d e f'); 60} {1 {datatype mismatch}} 61do_execsql_test 2.2 { 62 INSERT INTO t2(rowid, x) VALUES(1, 'c d e f'); 63 INSERT INTO t2(rowid, x) VALUES(2, 'c d e f g h'); 64 INSERT INTO t2(rowid, x) VALUES(3, 'a b c d e f g h'); 65} {} 66do_execsql_test 2.3 { 67 SELECT rowid FROM t2 WHERE t2 MATCH 'b'; SELECT '::'; 68 SELECT rowid FROM t2 WHERE t2 MATCH 'e'; SELECT '::'; 69 SELECT rowid FROM t2 WHERE t2 MATCH 'h'; 70} {3 :: 1 2 3 :: 2 3} 71do_execsql_test 2.4 { 72 INSERT INTO t2(t2, rowid, x) VALUES('delete', 2, 'c d e f g h'); 73 SELECT rowid FROM t2 WHERE t2 MATCH 'b'; SELECT '::'; 74 SELECT rowid FROM t2 WHERE t2 MATCH 'e'; SELECT '::'; 75 SELECT rowid FROM t2 WHERE t2 MATCH 'h'; 76} {3 :: 1 3 :: 3} 77do_execsql_test 2.5 { 78 INSERT INTO t2(t2) VALUES('delete-all'); 79 SELECT rowid FROM t2 WHERE t2 MATCH 'b'; SELECT '::'; 80 SELECT rowid FROM t2 WHERE t2 MATCH 'e'; SELECT '::'; 81 SELECT rowid FROM t2 WHERE t2 MATCH 'h'; 82} {:: ::} 83do_execsql_test 2.6 { 84 INSERT INTO t2(rowid, x) VALUES(1, 'o t t f'); 85 INSERT INTO t2(rowid, x) VALUES(2, 'f s s e'); 86 INSERT INTO t2(rowid, x) VALUES(3, 'n t e t'); 87} 88 89do_catchsql_test 2.7.1 { 90 SELECT rowid FROM t2 91} {1 {t2: table does not support scanning}} 92do_catchsql_test 2.7.2 { 93 SELECT rowid FROM t2 WHERE rowid=2 94} {1 {t2: table does not support scanning}} 95do_catchsql_test 2.7.3 { 96 SELECT rowid FROM t2 WHERE rowid BETWEEN 1 AND 3 97} {1 {t2: table does not support scanning}} 98 99do_execsql_test 2.X { 100 DROP TABLE t2 101} 102 103#------------------------------------------------------------------------- 104# Test the xColumnSize() API 105# 106fts5_aux_test_functions db 107 108do_execsql_test 3.1.0 { 109 CREATE VIRTUAL TABLE t3 USING fts5(x, y UNINDEXED, z, columnsize=0); 110 INSERT INTO t3 VALUES('a a', 'b b b', 'c'); 111 INSERT INTO t3 VALUES('x a x', 'b b b y', ''); 112} 113do_execsql_test 3.1.1 { 114 SELECT rowid, fts5_test_columnsize(t3) FROM t3 WHERE t3 MATCH 'a' 115} { 116 1 {2 0 1} 2 {3 0 0} 117} 118do_execsql_test 3.1.2 { 119 INSERT INTO t3 VALUES(NULL, NULL, 'a a a a'); 120 DELETE FROM t3 WHERE rowid = 1; 121 SELECT rowid, fts5_test_columnsize(t3) FROM t3 WHERE t3 MATCH 'a' 122} { 123 2 {3 0 0} 3 {0 0 4} 124} 125 126do_execsql_test 3.2.0 { 127 CREATE VIRTUAL TABLE t4 USING fts5(x, y UNINDEXED, z, columnsize=0, content=''); 128 INSERT INTO t4(rowid, x, y, z) VALUES(1, 'a a', 'b b b', 'c'); 129 INSERT INTO t4(rowid, x, y, z) VALUES(2, 'x a x', 'b b b y', ''); 130} 131do_execsql_test 3.2.1 { 132 SELECT rowid, fts5_test_columnsize(t4) FROM t4 WHERE t4 MATCH 'a' 133} { 134 1 {-1 0 -1} 2 {-1 0 -1} 135} 136 137#------------------------------------------------------------------------- 138# Test the integrity-check 139# 140do_execsql_test 4.1.1 { 141 CREATE VIRTUAL TABLE t5 USING fts5(x, columnsize=0); 142 INSERT INTO t5 VALUES('1 2 3 4'); 143 INSERT INTO t5 VALUES('2 4 6 8'); 144} 145 146do_execsql_test 4.1.2 { 147 INSERT INTO t5(t5) VALUES('integrity-check'); 148} 149 150finish_test 151