OLD | NEW |
| 1 # |
1 # 2010 September 17 | 2 # 2010 September 17 |
2 # | 3 # |
3 # May you do good and not evil. | 4 # May you do good and not evil. |
4 # May you find forgiveness for yourself and forgive others. | 5 # May you find forgiveness for yourself and forgive others. |
5 # May you share freely, never taking more than you give. | 6 # May you share freely, never taking more than you give. |
6 # | 7 # |
7 #*********************************************************************** | 8 #*********************************************************************** |
| 9 # This file implements regression tests for SQLite library. The |
| 10 # focus of this file is the interactions between the FTS3/4 module |
| 11 # and shared-cache mode. |
8 # | 12 # |
9 | 13 |
10 set testdir [file dirname $argv0] | 14 set testdir [file dirname $argv0] |
11 source $testdir/tester.tcl | 15 source $testdir/tester.tcl |
12 | 16 |
13 ifcapable !fts3||!shared_cache { | 17 ifcapable !fts3||!shared_cache { |
14 finish_test | 18 finish_test |
15 return | 19 return |
16 } | 20 } |
| 21 set ::testprefix fts3shared |
17 | 22 |
18 db close | 23 db close |
19 set ::enable_shared_cache [sqlite3_enable_shared_cache 1] | 24 set ::enable_shared_cache [sqlite3_enable_shared_cache 1] |
20 | 25 |
21 # Open two connections to the database in shared-cache mode. | 26 # Open two connections to the database in shared-cache mode. |
22 # | 27 # |
23 sqlite3 db test.db | 28 sqlite3 db test.db |
24 sqlite3 db2 test.db | 29 sqlite3 db2 test.db |
25 | 30 |
26 # Create a virtual FTS3 table. Populate it with some initial data. | 31 # Create a virtual FTS3 table. Populate it with some initial data. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 do_execsql_test fts3shared-1.5 { COMMIT } {} | 65 do_execsql_test fts3shared-1.5 { COMMIT } {} |
61 do_test fts3shared-1.6 { sqlite3_get_autocommit db } 1 | 66 do_test fts3shared-1.6 { sqlite3_get_autocommit db } 1 |
62 | 67 |
63 # Verify that the second connection still has an open transaction. | 68 # Verify that the second connection still has an open transaction. |
64 # | 69 # |
65 do_test fts3shared-1.6 { sqlite3_get_autocommit db2 } 0 | 70 do_test fts3shared-1.6 { sqlite3_get_autocommit db2 } 0 |
66 | 71 |
67 db close | 72 db close |
68 db2 close | 73 db2 close |
69 | 74 |
| 75 #------------------------------------------------------------------------- |
| 76 # The following tests - fts3shared-2.* - test that unless FTS is bypassed |
| 77 # and the underlying tables accessed directly, it is not possible for an |
| 78 # SQLITE_LOCKED error to be enountered when committing an FTS transaction. |
| 79 # |
| 80 # Any SQLITE_LOCKED error should be returned when the fts4 (or fts4aux) |
| 81 # table is first read/written within a transaction, not later on. |
| 82 # |
| 83 set LOCKED {1 {database table is locked}} |
| 84 forcedelete test.db |
| 85 sqlite3 dbR test.db |
| 86 sqlite3 dbW test.db |
| 87 do_test 2.1 { |
| 88 execsql { |
| 89 CREATE VIRTUAL TABLE t1 USING fts4; |
| 90 CREATE TABLE t2ext(a, b); |
| 91 CREATE VIRTUAL TABLE t2 USING fts4(content=t2ext); |
| 92 CREATE VIRTUAL TABLE t1aux USING fts4aux(t1); |
| 93 CREATE VIRTUAL TABLE t2aux USING fts4aux(t2); |
| 94 |
| 95 INSERT INTO t1 VALUES('a b c'); |
| 96 INSERT INTO t2(rowid, a, b) VALUES(1, 'd e f', 'g h i'); |
| 97 } dbW |
| 98 } {} |
| 99 |
| 100 # Test that once [dbW] has written to the FTS table, no client may read |
| 101 # from the FTS or fts4aux table. |
| 102 do_test 2.2.1 { |
| 103 execsql { |
| 104 BEGIN; |
| 105 INSERT INTO t1 VALUES('j k l'); |
| 106 } dbW |
| 107 execsql BEGIN dbR |
| 108 } {} |
| 109 do_test 2.2.2 { catchsql "SELECT * FROM t1 WHERE rowid=1" dbR } $LOCKED |
| 110 do_test 2.2.3 { catchsql "SELECT * FROM t1 WHERE t1 MATCH 'a'" dbR } $LOCKED |
| 111 do_test 2.2.4 { catchsql "SELECT rowid FROM t1 WHERE t1 MATCH 'a'" dbR } $LOCKED |
| 112 do_test 2.2.5 { catchsql "SELECT * FROM t1" dbR } $LOCKED |
| 113 do_test 2.2.6 { catchsql "SELECT * FROM t1aux" dbR } $LOCKED |
| 114 do_test 2.2.7 { execsql COMMIT dbW } {} |
| 115 do_test 2.2.8 { execsql COMMIT dbR } {} |
| 116 |
| 117 # Same test as 2.2.*, except with a content= table. |
| 118 # |
| 119 do_test 2.3.1 { |
| 120 execsql { |
| 121 BEGIN; |
| 122 INSERT INTO t2(rowid, a, b) VALUES(2, 'j k l', 'm n o'); |
| 123 } dbW |
| 124 execsql BEGIN dbR |
| 125 } {} |
| 126 do_test 2.3.3 { catchsql "SELECT * FROM t2 WHERE t2 MATCH 'a'" dbR } $LOCKED |
| 127 do_test 2.3.4 { catchsql "SELECT rowid FROM t2 WHERE t2 MATCH 'a'" dbR } $LOCKED |
| 128 do_test 2.3.6 { catchsql "SELECT * FROM t2aux" dbR } $LOCKED |
| 129 do_test 2.3.7 { execsql COMMIT dbW } {} |
| 130 do_test 2.3.8 { execsql COMMIT dbR } {} |
| 131 |
| 132 # Test that once a connection has read from the FTS or fts4aux table, |
| 133 # another connection may not write to the FTS table. |
| 134 # |
| 135 foreach {tn sql} { |
| 136 1 "SELECT * FROM t1 WHERE rowid=1" |
| 137 2 "SELECT * FROM t1 WHERE t1 MATCH 'a'" |
| 138 3 "SELECT rowid FROM t1 WHERE t1 MATCH 'a'" |
| 139 4 "SELECT * FROM t1" |
| 140 5 "SELECT * FROM t1aux" |
| 141 } { |
| 142 |
| 143 do_test 2.4.$tn { |
| 144 execsql BEGIN dbR |
| 145 execsql $::sql dbR |
| 146 execsql BEGIN dbW |
| 147 catchsql "INSERT INTO t1 VALUES('p q r')" dbW |
| 148 } $LOCKED |
| 149 |
| 150 execsql ROLLBACK dbR |
| 151 execsql ROLLBACK dbW |
| 152 } |
| 153 |
| 154 # Same test as 2.4.*, except with a content= table. |
| 155 # |
| 156 foreach {tn sql} { |
| 157 2 "SELECT * FROM t2 WHERE t2 MATCH 'a'" |
| 158 3 "SELECT rowid FROM t2 WHERE t2 MATCH 'a'" |
| 159 5 "SELECT * FROM t2aux" |
| 160 } { |
| 161 |
| 162 do_test 2.5.$tn { |
| 163 execsql BEGIN dbR |
| 164 execsql $::sql dbR |
| 165 execsql BEGIN dbW |
| 166 catchsql "INSERT INTO t2(rowid, a, b) VALUES(3, 's t u', 'v w x')" dbW |
| 167 } $LOCKED |
| 168 |
| 169 execsql ROLLBACK dbR |
| 170 execsql ROLLBACK dbW |
| 171 } |
| 172 |
| 173 dbW close |
| 174 dbR close |
70 sqlite3_enable_shared_cache $::enable_shared_cache | 175 sqlite3_enable_shared_cache $::enable_shared_cache |
71 finish_test | 176 finish_test |
72 | |
OLD | NEW |