| OLD | NEW |
| (Empty) |
| 1 # 2007 June 20 | |
| 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 # This file implements regression tests for SQLite library. The | |
| 12 # focus of this script is testing the FTS3 module. | |
| 13 # | |
| 14 # $Id: fts3ao.test,v 1.1 2007/08/20 17:38:42 shess Exp $ | |
| 15 # | |
| 16 | |
| 17 set testdir [file dirname $argv0] | |
| 18 source $testdir/tester.tcl | |
| 19 | |
| 20 # If SQLITE_ENABLE_FTS3 is not defined, omit this file. | |
| 21 ifcapable !fts3 { | |
| 22 finish_test | |
| 23 return | |
| 24 } | |
| 25 | |
| 26 #--------------------------------------------------------------------- | |
| 27 # These tests, fts3ao-1.*, test that ticket #2429 is fixed. | |
| 28 # | |
| 29 db eval { | |
| 30 CREATE VIRTUAL TABLE t1 USING fts3(a, b, c); | |
| 31 INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one four two'); | |
| 32 } | |
| 33 do_test fts3ao-1.1 { | |
| 34 execsql { | |
| 35 SELECT rowid, snippet(t1) FROM t1 WHERE c MATCH 'four'; | |
| 36 } | |
| 37 } {1 {one <b>four</b> two}} | |
| 38 do_test fts3ao-1.2 { | |
| 39 execsql { | |
| 40 SELECT rowid, snippet(t1) FROM t1 WHERE b MATCH 'four'; | |
| 41 } | |
| 42 } {1 {one <b>four</b>}} | |
| 43 do_test fts3ao-1.3 { | |
| 44 execsql { | |
| 45 SELECT rowid, snippet(t1) FROM t1 WHERE a MATCH 'four'; | |
| 46 } | |
| 47 } {1 {one three <b>four</b>}} | |
| 48 | |
| 49 #--------------------------------------------------------------------- | |
| 50 # Test that it is possible to rename an fts3 table. | |
| 51 # | |
| 52 do_test fts3ao-2.1 { | |
| 53 execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} | |
| 54 } {t1 t1_content t1_segments t1_segdir} | |
| 55 do_test fts3ao-2.2 { | |
| 56 execsql { ALTER TABLE t1 RENAME to fts_t1; } | |
| 57 } {} | |
| 58 do_test fts3ao-2.3 { | |
| 59 execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; } | |
| 60 } {1 {one three <b>four</b>}} | |
| 61 do_test fts3ao-2.4 { | |
| 62 execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} | |
| 63 } {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir} | |
| 64 | |
| 65 # See what happens when renaming the fts3 table fails. | |
| 66 # | |
| 67 do_test fts3ao-2.5 { | |
| 68 catchsql { | |
| 69 CREATE TABLE t1_segdir(a, b, c); | |
| 70 ALTER TABLE fts_t1 RENAME to t1; | |
| 71 } | |
| 72 } {1 {SQL logic error or missing database}} | |
| 73 do_test fts3ao-2.6 { | |
| 74 execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; } | |
| 75 } {1 {one three <b>four</b>}} | |
| 76 do_test fts3ao-2.7 { | |
| 77 execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} | |
| 78 } {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir t1_segdir} | |
| 79 | |
| 80 # See what happens when renaming the fts3 table fails inside a transaction. | |
| 81 # | |
| 82 do_test fts3ao-2.8 { | |
| 83 execsql { | |
| 84 BEGIN; | |
| 85 INSERT INTO fts_t1(a, b, c) VALUES('one two three', 'one four', 'one two'); | |
| 86 } | |
| 87 } {} | |
| 88 do_test fts3ao-2.9 { | |
| 89 catchsql { | |
| 90 ALTER TABLE fts_t1 RENAME to t1; | |
| 91 } | |
| 92 } {1 {SQL logic error or missing database}} | |
| 93 do_test fts3ao-2.10 { | |
| 94 execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; } | |
| 95 } {1 {one three <b>four</b>}} | |
| 96 do_test fts3ao-2.11 { | |
| 97 execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} | |
| 98 } {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir t1_segdir} | |
| 99 do_test fts3ao-2.12 { | |
| 100 execsql COMMIT | |
| 101 execsql {SELECT a FROM fts_t1} | |
| 102 } {{one three four} {one two three}} | |
| 103 do_test fts3ao-2.12 { | |
| 104 execsql { SELECT a, b, c FROM fts_t1 WHERE c MATCH 'four'; } | |
| 105 } {{one three four} {one four} {one four two}} | |
| 106 | |
| 107 #------------------------------------------------------------------- | |
| 108 # Close, delete and reopen the database. The following test should | |
| 109 # be run on an initially empty db. | |
| 110 # | |
| 111 db close | |
| 112 file delete -force test.db test.db-journal | |
| 113 sqlite3 db test.db | |
| 114 | |
| 115 do_test fts3ao-3.1 { | |
| 116 execsql { | |
| 117 CREATE VIRTUAL TABLE t1 USING fts3(a, b, c); | |
| 118 INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one two'); | |
| 119 SELECT a, b, c FROM t1 WHERE c MATCH 'two'; | |
| 120 } | |
| 121 } {{one three four} {one four} {one two}} | |
| 122 | |
| 123 # This test was crashing at one point. | |
| 124 # | |
| 125 do_test fts3ao-3.2 { | |
| 126 execsql { | |
| 127 SELECT a, b, c FROM t1 WHERE c MATCH 'two'; | |
| 128 CREATE TABLE t3(a, b, c); | |
| 129 SELECT a, b, c FROM t1 WHERE c MATCH 'two'; | |
| 130 } | |
| 131 } {{one three four} {one four} {one two} {one three four} {one four} {one two}} | |
| 132 | |
| 133 #--------------------------------------------------------------------- | |
| 134 # Test that it is possible to rename an fts3 table in an attached | |
| 135 # database. | |
| 136 # | |
| 137 file delete -force test2.db test2.db-journal | |
| 138 | |
| 139 do_test fts3ao-3.1 { | |
| 140 execsql { | |
| 141 ATTACH 'test2.db' AS aux; | |
| 142 CREATE VIRTUAL TABLE aux.t1 USING fts3(a, b, c); | |
| 143 INSERT INTO aux.t1(a, b, c) VALUES( | |
| 144 'neung song sahm', 'neung see', 'neung see song' | |
| 145 ); | |
| 146 } | |
| 147 } {} | |
| 148 | |
| 149 do_test fts3ao-3.2 { | |
| 150 execsql { SELECT a, b, c FROM aux.t1 WHERE a MATCH 'song'; } | |
| 151 } {{neung song sahm} {neung see} {neung see song}} | |
| 152 | |
| 153 do_test fts3ao-3.3 { | |
| 154 execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; } | |
| 155 } {{one three four} {one four} {one two}} | |
| 156 | |
| 157 do_test fts3ao-3.4 { | |
| 158 execsql { ALTER TABLE aux.t1 RENAME TO t2 } | |
| 159 } {} | |
| 160 | |
| 161 do_test fts3ao-3.2 { | |
| 162 execsql { SELECT a, b, c FROM t2 WHERE a MATCH 'song'; } | |
| 163 } {{neung song sahm} {neung see} {neung see song}} | |
| 164 | |
| 165 do_test fts3ao-3.3 { | |
| 166 execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; } | |
| 167 } {{one three four} {one four} {one two}} | |
| 168 | |
| 169 finish_test | |
| OLD | NEW |