danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 1 | # 2005 December 30 |
| 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 | #*********************************************************************** |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 11 | # |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 12 | # $Id: shared.test,v 1.14 2006/01/16 12:46:41 danielk1977 Exp $ |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 13 | |
| 14 | set testdir [file dirname $argv0] |
| 15 | source $testdir/tester.tcl |
| 16 | db close |
| 17 | |
| 18 | ifcapable !shared_cache { |
| 19 | finish_test |
| 20 | return |
| 21 | } |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 22 | |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 23 | set ::enable_shared_cache [sqlite3_enable_shared_cache 1] |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 24 | |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 25 | foreach av [list 0 1] { |
| 26 | |
| 27 | ifcapable !autovacuum { |
| 28 | if {$av} break |
| 29 | } |
| 30 | |
| 31 | # Open the database connection and execute the auto-vacuum pragma |
| 32 | do_test shared-$av.1.0 { |
| 33 | file delete -force test.db |
| 34 | sqlite3 db test.db |
| 35 | execsql "pragma auto_vacuum=$::av" |
| 36 | execsql {pragma auto_vacuum} |
| 37 | } "$av" |
| 38 | incr av |
| 39 | |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 40 | # Test organization: |
| 41 | # |
| 42 | # shared-1.*: Simple test to verify basic sanity of table level locking when |
| 43 | # two connections share a pager cache. |
| 44 | # shared-2.*: Test that a read transaction can co-exist with a |
| 45 | # write-transaction, including a simple test to ensure the |
| 46 | # external locking protocol is still working. |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 47 | # shared-3.*: Simple test of read-uncommitted mode. |
danielk1977 | de0fe3e | 2006-01-06 06:33:12 +0000 | [diff] [blame] | 48 | # shared-4.*: Check that the schema is locked and unlocked correctly. |
danielk1977 | aaf2268 | 2006-01-06 15:03:48 +0000 | [diff] [blame] | 49 | # shared-5.*: Test that creating/dropping schema items works when databases |
| 50 | # are attached in different orders to different handles. |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 51 | # shared-6.*: Locking, UNION ALL queries and sub-queries. |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 52 | # shared-7.*: Autovacuum and shared-cache. |
danielk1977 | de0fe3e | 2006-01-06 06:33:12 +0000 | [diff] [blame] | 53 | # |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 54 | |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 55 | do_test shared-$av.1.1 { |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 56 | # Open a second database on the file test.db. It should use the same pager |
| 57 | # cache and schema as the original connection. Verify that only 1 file is |
| 58 | # opened. |
| 59 | sqlite3 db2 test.db |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 60 | set ::sqlite_open_file_count |
| 61 | } {1} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 62 | do_test shared-$av.1.2 { |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 63 | # Add a table and a single row of data via the first connection. |
| 64 | # Ensure that the second connection can see them. |
| 65 | execsql { |
| 66 | CREATE TABLE abc(a, b, c); |
| 67 | INSERT INTO abc VALUES(1, 2, 3); |
| 68 | } db |
| 69 | execsql { |
| 70 | SELECT * FROM abc; |
| 71 | } db2 |
| 72 | } {1 2 3} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 73 | do_test shared-$av.1.3 { |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 74 | # Have the first connection begin a transaction and obtain a read-lock |
| 75 | # on table abc. This should not prevent the second connection from |
| 76 | # querying abc. |
| 77 | execsql { |
| 78 | BEGIN; |
| 79 | SELECT * FROM abc; |
| 80 | } |
| 81 | execsql { |
| 82 | SELECT * FROM abc; |
| 83 | } db2 |
| 84 | } {1 2 3} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 85 | do_test shared-$av.1.4 { |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 86 | # Try to insert a row into abc via connection 2. This should fail because |
| 87 | # of the read-lock connection 1 is holding on table abc (obtained in the |
| 88 | # previous test case). |
| 89 | catchsql { |
| 90 | INSERT INTO abc VALUES(4, 5, 6); |
| 91 | } db2 |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 92 | } {1 {database table is locked: abc}} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 93 | do_test shared-$av.1.5 { |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 94 | # Using connection 2 (the one without the open transaction), try to create |
| 95 | # a new table. This should fail because of the open read transaction |
| 96 | # held by connection 1. |
| 97 | catchsql { |
| 98 | CREATE TABLE def(d, e, f); |
| 99 | } db2 |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 100 | } {1 {database table is locked: sqlite_master}} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 101 | do_test shared-$av.1.6 { |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 102 | # Upgrade connection 1's transaction to a write transaction. Create |
| 103 | # a new table - def - and insert a row into it. Because the connection 1 |
| 104 | # transaction modifies the schema, it should not be possible for |
| 105 | # connection 2 to access the database at all until the connection 1 |
| 106 | # has finished the transaction. |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 107 | execsql { |
| 108 | CREATE TABLE def(d, e, f); |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 109 | INSERT INTO def VALUES('IV', 'V', 'VI'); |
| 110 | } |
| 111 | } {} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 112 | do_test shared-$av.1.7 { |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 113 | # Read from the sqlite_master table with connection 1 (inside the |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 114 | # transaction). Then test that we can not do this with connection 2. This |
| 115 | # is because of the schema-modified lock established by connection 1 |
| 116 | # in the previous test case. |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 117 | execsql { |
| 118 | SELECT * FROM sqlite_master; |
| 119 | } |
| 120 | catchsql { |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 121 | SELECT * FROM sqlite_master; |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 122 | } db2 |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 123 | } {1 {database schema is locked: main}} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 124 | do_test shared-$av.1.8 { |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 125 | # Commit the connection 1 transaction. |
| 126 | execsql { |
| 127 | COMMIT; |
| 128 | } |
| 129 | } {} |
| 130 | |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 131 | do_test shared-$av.2.1 { |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 132 | # Open connection db3 to the database. Use a different path to the same |
| 133 | # file so that db3 does *not* share the same pager cache as db and db2 |
| 134 | # (there should be two open file handles). |
| 135 | sqlite3 db3 ./test.db |
| 136 | set ::sqlite_open_file_count |
| 137 | } {2} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 138 | do_test shared-$av.2.2 { |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 139 | # Start read transactions on db and db2 (the shared pager cache). Ensure |
| 140 | # db3 cannot write to the database. |
| 141 | execsql { |
| 142 | BEGIN; |
| 143 | SELECT * FROM abc; |
| 144 | } |
| 145 | execsql { |
| 146 | BEGIN; |
| 147 | SELECT * FROM abc; |
| 148 | } db2 |
| 149 | catchsql { |
| 150 | INSERT INTO abc VALUES(1, 2, 3); |
| 151 | } db2 |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 152 | } {1 {database table is locked: abc}} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 153 | do_test shared-$av.2.3 { |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 154 | # Turn db's transaction into a write-transaction. db3 should still be |
| 155 | # able to read from table def (but will not see the new row). Connection |
| 156 | # db2 should not be able to read def (because of the write-lock). |
| 157 | |
| 158 | # Todo: The failed "INSERT INTO abc ..." statement in the above test |
| 159 | # has started a write-transaction on db2 (should this be so?). This |
| 160 | # would prevent connection db from starting a write-transaction. So roll the |
| 161 | # db2 transaction back and replace it with a new read transaction. |
| 162 | execsql { |
| 163 | ROLLBACK; |
| 164 | BEGIN; |
| 165 | SELECT * FROM abc; |
| 166 | } db2 |
| 167 | |
| 168 | execsql { |
| 169 | INSERT INTO def VALUES('VII', 'VIII', 'IX'); |
| 170 | } |
| 171 | concat [ |
| 172 | catchsql { SELECT * FROM def; } db3 |
| 173 | ] [ |
| 174 | catchsql { SELECT * FROM def; } db2 |
| 175 | ] |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 176 | } {0 {IV V VI} 1 {database table is locked: def}} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 177 | do_test shared-$av.2.4 { |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 178 | # Commit the open transaction on db. db2 still holds a read-transaction. |
| 179 | # This should prevent db3 from writing to the database, but not from |
| 180 | # reading. |
| 181 | execsql { |
| 182 | COMMIT; |
| 183 | } |
| 184 | concat [ |
| 185 | catchsql { SELECT * FROM def; } db3 |
| 186 | ] [ |
| 187 | catchsql { INSERT INTO def VALUES('X', 'XI', 'XII'); } db3 |
| 188 | ] |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 189 | } {0 {IV V VI VII VIII IX} 1 {database is locked}} |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 190 | |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 191 | catchsql COMMIT db2 |
| 192 | |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 193 | do_test shared-$av.3.1.1 { |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 194 | # This test case starts a linear scan of table 'seq' using a |
| 195 | # read-uncommitted connection. In the middle of the scan, rows are added |
| 196 | # to the end of the seq table (ahead of the current cursor position). |
| 197 | # The uncommitted rows should be included in the results of the scan. |
| 198 | execsql " |
| 199 | CREATE TABLE seq(i, x); |
| 200 | INSERT INTO seq VALUES(1, '[string repeat X 500]'); |
| 201 | INSERT INTO seq VALUES(2, '[string repeat X 500]'); |
| 202 | " |
| 203 | execsql {SELECT * FROM sqlite_master} db2 |
| 204 | execsql {PRAGMA read_uncommitted = 1} db2 |
| 205 | |
| 206 | set ret [list] |
| 207 | db2 eval {SELECT i FROM seq} { |
| 208 | if {$i < 4} { |
danielk1977 | 1576cd9 | 2006-01-14 08:02:28 +0000 | [diff] [blame] | 209 | set max [execsql {SELECT max(i) FROM seq}] |
| 210 | db eval { |
| 211 | INSERT INTO seq SELECT i + $max, x FROM seq; |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | lappend ret $i |
| 215 | } |
| 216 | set ret |
| 217 | } {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 218 | do_test shared-$av.3.1.2 { |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 219 | # Another linear scan through table seq using a read-uncommitted connection. |
| 220 | # This time, delete each row as it is read. Should not affect the results of |
| 221 | # the scan, but the table should be empty after the scan is concluded |
| 222 | # (test 3.1.3 verifies this). |
| 223 | set ret [list] |
| 224 | db2 eval {SELECT i FROM seq} { |
| 225 | db eval {DELETE FROM seq WHERE i = $i} |
| 226 | lappend ret $i |
| 227 | } |
| 228 | set ret |
| 229 | } {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 230 | do_test shared-$av.3.1.3 { |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 231 | execsql { |
| 232 | SELECT * FROM seq; |
| 233 | } |
| 234 | } {} |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 235 | |
| 236 | catch {db close} |
| 237 | catch {db2 close} |
| 238 | catch {db3 close} |
| 239 | |
danielk1977 | de0fe3e | 2006-01-06 06:33:12 +0000 | [diff] [blame] | 240 | #-------------------------------------------------------------------------- |
| 241 | # Tests shared-4.* test that the schema locking rules are applied |
| 242 | # correctly. i.e.: |
| 243 | # |
| 244 | # 1. All transactions require a read-lock on the schemas of databases they |
| 245 | # access. |
| 246 | # 2. Transactions that modify a database schema require a write-lock on that |
| 247 | # schema. |
| 248 | # 3. It is not possible to compile a statement while another handle has a |
| 249 | # write-lock on the schema. |
| 250 | # |
| 251 | |
| 252 | # Open two database handles db and db2. Each has a single attach database |
| 253 | # (as well as main): |
| 254 | # |
| 255 | # db.main -> ./test.db |
| 256 | # db.test2 -> ./test2.db |
| 257 | # db2.main -> ./test2.db |
| 258 | # db2.test -> ./test.db |
| 259 | # |
| 260 | file delete -force test.db |
| 261 | file delete -force test2.db |
| 262 | file delete -force test2.db-journal |
| 263 | sqlite3 db test.db |
| 264 | sqlite3 db2 test2.db |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 265 | do_test shared-$av.4.1.1 { |
danielk1977 | de0fe3e | 2006-01-06 06:33:12 +0000 | [diff] [blame] | 266 | set sqlite_open_file_count |
| 267 | } {2} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 268 | do_test shared-$av.4.1.2 { |
danielk1977 | de0fe3e | 2006-01-06 06:33:12 +0000 | [diff] [blame] | 269 | execsql {ATTACH 'test2.db' AS test2} |
| 270 | set sqlite_open_file_count |
| 271 | } {2} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 272 | do_test shared-$av.4.1.3 { |
danielk1977 | de0fe3e | 2006-01-06 06:33:12 +0000 | [diff] [blame] | 273 | execsql {ATTACH 'test.db' AS test} db2 |
| 274 | set sqlite_open_file_count |
| 275 | } {2} |
| 276 | |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 277 | # Sanity check: Create a table in ./test.db via handle db, and test that handle |
| 278 | # db2 can "see" the new table immediately. A handle using a seperate pager |
| 279 | # cache would have to reload the database schema before this were possible. |
| 280 | # |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 281 | do_test shared-$av.4.2.1 { |
danielk1977 | de0fe3e | 2006-01-06 06:33:12 +0000 | [diff] [blame] | 282 | execsql { |
| 283 | CREATE TABLE abc(a, b, c); |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 284 | CREATE TABLE def(d, e, f); |
danielk1977 | de0fe3e | 2006-01-06 06:33:12 +0000 | [diff] [blame] | 285 | INSERT INTO abc VALUES('i', 'ii', 'iii'); |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 286 | INSERT INTO def VALUES('I', 'II', 'III'); |
danielk1977 | de0fe3e | 2006-01-06 06:33:12 +0000 | [diff] [blame] | 287 | } |
| 288 | } {} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 289 | do_test shared-$av.4.2.2 { |
danielk1977 | de0fe3e | 2006-01-06 06:33:12 +0000 | [diff] [blame] | 290 | execsql { |
| 291 | SELECT * FROM test.abc; |
| 292 | } db2 |
| 293 | } {i ii iii} |
| 294 | |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 295 | # Open a read-transaction and read from table abc via handle 2. Check that |
| 296 | # handle 1 can read table abc. Check that handle 1 cannot modify table abc |
| 297 | # or the database schema. Then check that handle 1 can modify table def. |
| 298 | # |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 299 | do_test shared-$av.4.3.1 { |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 300 | execsql { |
| 301 | BEGIN; |
| 302 | SELECT * FROM test.abc; |
| 303 | } db2 |
| 304 | } {i ii iii} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 305 | do_test shared-$av.4.3.2 { |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 306 | catchsql { |
| 307 | INSERT INTO abc VALUES('iv', 'v', 'vi'); |
| 308 | } |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 309 | } {1 {database table is locked: abc}} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 310 | do_test shared-$av.4.3.3 { |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 311 | catchsql { |
| 312 | CREATE TABLE ghi(g, h, i); |
| 313 | } |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 314 | } {1 {database table is locked: sqlite_master}} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 315 | do_test shared-$av.4.3.3 { |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 316 | catchsql { |
| 317 | INSERT INTO def VALUES('IV', 'V', 'VI'); |
| 318 | } |
| 319 | } {0 {}} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 320 | do_test shared-$av.4.3.4 { |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 321 | # Cleanup: commit the transaction opened by db2. |
| 322 | execsql { |
| 323 | COMMIT |
| 324 | } db2 |
| 325 | } {} |
| 326 | |
| 327 | # Open a write-transaction using handle 1 and modify the database schema. |
| 328 | # Then try to execute a compiled statement to read from the same |
| 329 | # database via handle 2 (fails to get the lock on sqlite_master). Also |
| 330 | # try to compile a read of the same database using handle 2 (also fails). |
| 331 | # Finally, compile a read of the other database using handle 2. This |
| 332 | # should also fail. |
| 333 | # |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 334 | do_test shared-$av.4.4.1.2 { |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 335 | # Sanity check 1: Check that the schema is what we think it is when viewed |
| 336 | # via handle 1. |
| 337 | execsql { |
| 338 | CREATE TABLE test2.ghi(g, h, i); |
| 339 | SELECT 'test.db:'||name FROM sqlite_master |
| 340 | UNION ALL |
| 341 | SELECT 'test2.db:'||name FROM test2.sqlite_master; |
| 342 | } |
| 343 | } {test.db:abc test.db:def test2.db:ghi} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 344 | do_test shared-$av.4.4.1.2 { |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 345 | # Sanity check 2: Check that the schema is what we think it is when viewed |
| 346 | # via handle 2. |
| 347 | execsql { |
| 348 | SELECT 'test2.db:'||name FROM sqlite_master |
| 349 | UNION ALL |
| 350 | SELECT 'test.db:'||name FROM test.sqlite_master; |
| 351 | } db2 |
| 352 | } {test2.db:ghi test.db:abc test.db:def} |
| 353 | |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 354 | do_test shared-$av.4.4.2 { |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 355 | set ::DB2 [sqlite3_connection_pointer db2] |
| 356 | set sql {SELECT * FROM abc} |
| 357 | set ::STMT1 [sqlite3_prepare $::DB2 $sql -1 DUMMY] |
| 358 | execsql { |
| 359 | BEGIN; |
| 360 | CREATE TABLE jkl(j, k, l); |
| 361 | } |
| 362 | sqlite3_step $::STMT1 |
| 363 | } {SQLITE_ERROR} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 364 | do_test shared-$av.4.4.3 { |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 365 | sqlite3_finalize $::STMT1 |
| 366 | } {SQLITE_LOCKED} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 367 | do_test shared-$av.4.4.4 { |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 368 | set rc [catch { |
| 369 | set ::STMT1 [sqlite3_prepare $::DB2 $sql -1 DUMMY] |
| 370 | } msg] |
| 371 | list $rc $msg |
| 372 | } {1 {(6) database schema is locked: test}} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 373 | do_test shared-$av.4.4.5 { |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 374 | set rc [catch { |
| 375 | set ::STMT1 [sqlite3_prepare $::DB2 "SELECT * FROM ghi" -1 DUMMY] |
| 376 | } msg] |
| 377 | list $rc $msg |
| 378 | } {1 {(6) database schema is locked: test}} |
| 379 | |
danielk1977 | aaf2268 | 2006-01-06 15:03:48 +0000 | [diff] [blame] | 380 | |
danielk1977 | de0fe3e | 2006-01-06 06:33:12 +0000 | [diff] [blame] | 381 | catch {db2 close} |
| 382 | catch {db close} |
| 383 | |
danielk1977 | aaf2268 | 2006-01-06 15:03:48 +0000 | [diff] [blame] | 384 | #-------------------------------------------------------------------------- |
| 385 | # Tests shared-5.* |
| 386 | # |
| 387 | foreach db [list test.db test1.db test2.db test3.db] { |
| 388 | file delete -force $db ${db}-journal |
| 389 | } |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 390 | do_test shared-$av.5.1.1 { |
danielk1977 | aaf2268 | 2006-01-06 15:03:48 +0000 | [diff] [blame] | 391 | sqlite3 db1 test.db |
| 392 | sqlite3 db2 test.db |
| 393 | execsql { |
| 394 | ATTACH 'test1.db' AS test1; |
| 395 | ATTACH 'test2.db' AS test2; |
| 396 | ATTACH 'test3.db' AS test3; |
| 397 | } db1 |
| 398 | execsql { |
| 399 | ATTACH 'test3.db' AS test3; |
| 400 | ATTACH 'test2.db' AS test2; |
| 401 | ATTACH 'test1.db' AS test1; |
| 402 | } db2 |
| 403 | } {} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 404 | do_test shared-$av.5.1.2 { |
danielk1977 | aaf2268 | 2006-01-06 15:03:48 +0000 | [diff] [blame] | 405 | execsql { |
| 406 | CREATE TABLE test1.t1(a, b); |
| 407 | CREATE INDEX test1.i1 ON t1(a, b); |
| 408 | CREATE VIEW test1.v1 AS SELECT * FROM t1; |
| 409 | CREATE TRIGGER test1.trig1 AFTER INSERT ON t1 BEGIN |
| 410 | INSERT INTO t1 VALUES(new.a, new.b); |
| 411 | END; |
| 412 | } db1 |
| 413 | execsql { |
| 414 | DROP INDEX i1; |
| 415 | DROP VIEW v1; |
| 416 | DROP TRIGGER trig1; |
| 417 | DROP TABLE t1; |
| 418 | } db2 |
| 419 | } {} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 420 | do_test shared-$av.5.1.2 { |
danielk1977 | aaf2268 | 2006-01-06 15:03:48 +0000 | [diff] [blame] | 421 | execsql { |
| 422 | SELECT * FROM sqlite_master UNION ALL SELECT * FROM test1.sqlite_master |
| 423 | } db1 |
| 424 | } {} |
| 425 | |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 426 | #-------------------------------------------------------------------------- |
| 427 | # Tests shared-6.* test that a query obtains all the read-locks it needs |
| 428 | # before starting execution of the query. This means that there is no chance |
| 429 | # some rows of data will be returned before a lock fails and SQLITE_LOCK |
| 430 | # is returned. |
| 431 | # |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 432 | do_test shared-$av.6.1.1 { |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 433 | execsql { |
| 434 | CREATE TABLE t1(a, b); |
| 435 | CREATE TABLE t2(a, b); |
| 436 | INSERT INTO t1 VALUES(1, 2); |
| 437 | INSERT INTO t2 VALUES(3, 4); |
| 438 | } db1 |
| 439 | execsql { |
| 440 | SELECT * FROM t1 UNION ALL SELECT * FROM t2; |
| 441 | } db2 |
| 442 | } {1 2 3 4} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 443 | do_test shared-$av.6.1.2 { |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 444 | # Establish a write lock on table t2 via connection db2. Then make a |
| 445 | # UNION all query using connection db1 that first accesses t1, followed |
| 446 | # by t2. If the locks are grabbed at the start of the statement (as |
| 447 | # they should be), no rows are returned. If (as was previously the case) |
| 448 | # they are grabbed as the tables are accessed, the t1 rows will be |
| 449 | # returned before the query fails. |
| 450 | # |
| 451 | execsql { |
| 452 | BEGIN; |
| 453 | INSERT INTO t2 VALUES(5, 6); |
| 454 | } db2 |
| 455 | set ret [list] |
| 456 | catch { |
| 457 | db1 eval {SELECT * FROM t1 UNION ALL SELECT * FROM t2} { |
| 458 | lappend ret $a $b |
| 459 | } |
| 460 | } |
| 461 | set ret |
| 462 | } {} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 463 | do_test shared-$av.6.1.3 { |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 464 | execsql { |
| 465 | COMMIT; |
| 466 | BEGIN; |
| 467 | INSERT INTO t1 VALUES(7, 8); |
| 468 | } db2 |
| 469 | set ret [list] |
| 470 | catch { |
| 471 | db1 eval { |
| 472 | SELECT (CASE WHEN a>4 THEN (SELECT a FROM t1) ELSE 0 END) AS d FROM t2; |
| 473 | } { |
| 474 | lappend ret $d |
| 475 | } |
| 476 | } |
| 477 | set ret |
| 478 | } {} |
| 479 | |
danielk1977 | aaf2268 | 2006-01-06 15:03:48 +0000 | [diff] [blame] | 480 | catch {db1 close} |
| 481 | catch {db2 close} |
danielk1977 | e501b89 | 2006-01-09 06:29:47 +0000 | [diff] [blame] | 482 | foreach f [list test.db test2.db] { |
| 483 | file delete -force $f ${f}-journal |
| 484 | } |
| 485 | |
| 486 | #-------------------------------------------------------------------------- |
| 487 | # Tests shared-7.* test auto-vacuum does not invalidate cursors from |
| 488 | # other shared-cache users when it reorganizes the database on |
| 489 | # COMMIT. |
| 490 | # |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 491 | do_test shared-$av.7.1 { |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 492 | # This test case sets up a test database in auto-vacuum mode consisting |
| 493 | # of two tables, t1 and t2. Both have a single index. Table t1 is |
| 494 | # populated first (so consists of pages toward the start of the db file), |
| 495 | # t2 second (pages toward the end of the file). |
danielk1977 | e501b89 | 2006-01-09 06:29:47 +0000 | [diff] [blame] | 496 | sqlite3 db test.db |
| 497 | sqlite3 db2 test.db |
| 498 | execsql { |
| 499 | PRAGMA auto_vacuum = 1; |
| 500 | BEGIN; |
| 501 | CREATE TABLE t1(a PRIMARY KEY, b); |
| 502 | CREATE TABLE t2(a PRIMARY KEY, b); |
| 503 | } |
drh | 7a91dd8 | 2006-01-11 01:08:34 +0000 | [diff] [blame] | 504 | set ::contents {} |
danielk1977 | e501b89 | 2006-01-09 06:29:47 +0000 | [diff] [blame] | 505 | for {set i 0} {$i < 100} {incr i} { |
| 506 | set a [string repeat "$i " 20] |
| 507 | set b [string repeat "$i " 20] |
| 508 | db eval { |
| 509 | INSERT INTO t1 VALUES($a, $b); |
| 510 | } |
| 511 | lappend ::contents [list [expr $i+1] $a $b] |
| 512 | } |
| 513 | execsql { |
| 514 | INSERT INTO t2 SELECT * FROM t1; |
| 515 | COMMIT; |
| 516 | } |
| 517 | execsql { |
| 518 | PRAGMA auto_vacuum; |
| 519 | } |
| 520 | } {1} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 521 | do_test shared-$av.7.2 { |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 522 | # This test case deletes the contents of table t1 (the one at the start of |
| 523 | # the file) while many cursors are open on table t2 and it's index. All of |
| 524 | # the non-root pages will be moved from the end to the start of the file |
| 525 | # when the DELETE is committed - this test verifies that moving the pages |
| 526 | # does not disturb the open cursors. |
| 527 | # |
| 528 | |
danielk1977 | e501b89 | 2006-01-09 06:29:47 +0000 | [diff] [blame] | 529 | proc lockrow {db tbl oids body} { |
| 530 | set ret [list] |
| 531 | db eval "SELECT oid AS i, a, b FROM $tbl ORDER BY a" { |
| 532 | if {$i==[lindex $oids 0]} { |
| 533 | set noids [lrange $oids 1 end] |
| 534 | if {[llength $noids]==0} { |
| 535 | set subret [eval $body] |
| 536 | } else { |
| 537 | set subret [lockrow $db $tbl $noids $body] |
| 538 | } |
| 539 | } |
| 540 | lappend ret [list $i $a $b] |
| 541 | } |
| 542 | return [linsert $subret 0 $ret] |
| 543 | } |
| 544 | proc locktblrows {db tbl body} { |
| 545 | set oids [db eval "SELECT oid FROM $tbl"] |
| 546 | lockrow $db $tbl $oids $body |
| 547 | } |
| 548 | |
| 549 | set scans [locktblrows db t2 { |
| 550 | execsql { |
| 551 | DELETE FROM t1; |
| 552 | } db2 |
| 553 | }] |
| 554 | set error 0 |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 555 | |
| 556 | # Test that each SELECT query returned the expected contents of t2. |
danielk1977 | e501b89 | 2006-01-09 06:29:47 +0000 | [diff] [blame] | 557 | foreach s $scans { |
| 558 | if {[lsort -integer -index 0 $s]!=$::contents} { |
| 559 | set error 1 |
| 560 | } |
| 561 | } |
| 562 | set error |
| 563 | } {0} |
| 564 | |
| 565 | catch {db close} |
| 566 | catch {db2 close} |
drh | 7a91dd8 | 2006-01-11 01:08:34 +0000 | [diff] [blame] | 567 | unset -nocomplain contents |
danielk1977 | aaf2268 | 2006-01-06 15:03:48 +0000 | [diff] [blame] | 568 | |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 569 | #-------------------------------------------------------------------------- |
| 570 | # The following tests try to trick the shared-cache code into assuming |
| 571 | # the wrong encoding for a database. |
| 572 | # |
| 573 | file delete -force test.db test.db-journal |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 574 | do_test shared-$av.8.1.1 { |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 575 | sqlite3 db test.db |
| 576 | execsql { |
| 577 | PRAGMA encoding = 'UTF-16'; |
| 578 | SELECT * FROM sqlite_master; |
| 579 | } |
| 580 | } {} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 581 | do_test shared-$av.8.1.2 { |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 582 | string range [execsql {PRAGMA encoding;}] 0 end-2 |
| 583 | } {UTF-16} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 584 | do_test shared-$av.8.1.3 { |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 585 | sqlite3 db2 test.db |
| 586 | execsql { |
| 587 | PRAGMA encoding = 'UTF-8'; |
| 588 | CREATE TABLE abc(a, b, c); |
| 589 | } db2 |
| 590 | } {} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 591 | do_test shared-$av.8.1.4 { |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 592 | execsql { |
| 593 | SELECT * FROM sqlite_master; |
| 594 | } |
| 595 | } "table abc abc [expr $AUTOVACUUM?3:2] {CREATE TABLE abc(a, b, c)}" |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 596 | do_test shared-$av.8.1.5 { |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 597 | db2 close |
| 598 | execsql { |
| 599 | PRAGMA encoding; |
| 600 | } |
| 601 | } {UTF-8} |
| 602 | file delete -force test2.db test2.db-journal |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 603 | do_test shared-$av.8.2.1 { |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 604 | execsql { |
| 605 | ATTACH 'test2.db' AS aux; |
| 606 | SELECT * FROM aux.sqlite_master; |
| 607 | } |
| 608 | } {} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 609 | do_test shared-$av.8.2.2 { |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 610 | sqlite3 db2 test2.db |
| 611 | execsql { |
| 612 | PRAGMA encoding = 'UTF-16'; |
| 613 | CREATE TABLE def(d, e, f); |
| 614 | } db2 |
| 615 | string range [execsql {PRAGMA encoding;} db2] 0 end-2 |
| 616 | } {UTF-16} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 617 | do_test shared-$av.8.2.3 { |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 618 | catchsql { |
| 619 | SELECT * FROM aux.sqlite_master; |
| 620 | } |
| 621 | } {1 {attached databases must use the same text encoding as main database}} |
| 622 | |
| 623 | catch {db close} |
| 624 | catch {db2 close} |
danielk1977 | eecfb3e | 2006-01-10 12:31:39 +0000 | [diff] [blame] | 625 | file delete -force test.db test2.db |
| 626 | |
danielk1977 | eecfb3e | 2006-01-10 12:31:39 +0000 | [diff] [blame] | 627 | #--------------------------------------------------------------------------- |
| 628 | # The following tests - shared-9.* - test interactions between TEMP triggers |
| 629 | # and shared-schemas. |
| 630 | # |
| 631 | ifcapable trigger&&tempdb { |
| 632 | |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 633 | do_test shared-$av.9.1 { |
danielk1977 | eecfb3e | 2006-01-10 12:31:39 +0000 | [diff] [blame] | 634 | sqlite3 db test.db |
| 635 | sqlite3 db2 test.db |
| 636 | execsql { |
| 637 | CREATE TABLE abc(a, b, c); |
| 638 | CREATE TABLE abc_mirror(a, b, c); |
| 639 | CREATE TEMP TRIGGER BEFORE INSERT ON abc BEGIN |
| 640 | INSERT INTO abc_mirror(a, b, c) VALUES(new.a, new.b, new.c); |
| 641 | END; |
| 642 | INSERT INTO abc VALUES(1, 2, 3); |
| 643 | SELECT * FROM abc_mirror; |
| 644 | } |
| 645 | } {1 2 3} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 646 | do_test shared-$av.9.2 { |
danielk1977 | eecfb3e | 2006-01-10 12:31:39 +0000 | [diff] [blame] | 647 | execsql { |
| 648 | INSERT INTO abc VALUES(4, 5, 6); |
| 649 | SELECT * FROM abc_mirror; |
| 650 | } db2 |
| 651 | } {1 2 3} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 652 | do_test shared-$av.9.3 { |
danielk1977 | eecfb3e | 2006-01-10 12:31:39 +0000 | [diff] [blame] | 653 | db close |
| 654 | db2 close |
| 655 | } {} |
| 656 | |
| 657 | } ; # End shared-9.* |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 658 | |
danielk1977 | b597f74 | 2006-01-15 11:39:18 +0000 | [diff] [blame] | 659 | #--------------------------------------------------------------------------- |
| 660 | # The following tests - shared-10.* - test that the library behaves |
| 661 | # correctly when a connection to a shared-cache is closed. |
| 662 | # |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 663 | do_test shared-$av.10.1 { |
danielk1977 | b597f74 | 2006-01-15 11:39:18 +0000 | [diff] [blame] | 664 | # Create a small sample database with two connections to it (db and db2). |
| 665 | file delete -force test.db |
| 666 | sqlite3 db test.db |
| 667 | sqlite3 db2 test.db |
| 668 | execsql { |
| 669 | CREATE TABLE ab(a PRIMARY KEY, b); |
| 670 | CREATE TABLE de(d PRIMARY KEY, e); |
| 671 | INSERT INTO ab VALUES('Chiang Mai', 100000); |
| 672 | INSERT INTO ab VALUES('Bangkok', 8000000); |
| 673 | INSERT INTO de VALUES('Ubon', 120000); |
| 674 | INSERT INTO de VALUES('Khon Kaen', 200000); |
| 675 | } |
| 676 | } {} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 677 | do_test shared-$av.10.2 { |
danielk1977 | b597f74 | 2006-01-15 11:39:18 +0000 | [diff] [blame] | 678 | # Open a read-transaction with the first connection, a write-transaction |
| 679 | # with the second. |
| 680 | execsql { |
| 681 | BEGIN; |
| 682 | SELECT * FROM ab; |
| 683 | } |
| 684 | execsql { |
| 685 | BEGIN; |
| 686 | INSERT INTO de VALUES('Pataya', 30000); |
| 687 | } db2 |
| 688 | } {} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 689 | do_test shared-$av.10.3 { |
danielk1977 | b597f74 | 2006-01-15 11:39:18 +0000 | [diff] [blame] | 690 | # An external connection should be able to read the database, but not |
| 691 | # prepare a write operation. |
| 692 | sqlite3 db3 ./test.db |
| 693 | execsql { |
| 694 | SELECT * FROM ab; |
| 695 | } db3 |
| 696 | catchsql { |
| 697 | BEGIN; |
| 698 | INSERT INTO de VALUES('Pataya', 30000); |
| 699 | } db3 |
| 700 | } {1 {database is locked}} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 701 | do_test shared-$av.10.4 { |
danielk1977 | b597f74 | 2006-01-15 11:39:18 +0000 | [diff] [blame] | 702 | # Close the connection with the write-transaction open |
| 703 | db2 close |
| 704 | } {} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 705 | do_test shared-$av.10.5 { |
danielk1977 | b597f74 | 2006-01-15 11:39:18 +0000 | [diff] [blame] | 706 | # Test that the db2 transaction has been automatically rolled back. |
| 707 | # If it has not the ('Pataya', 30000) entry will still be in the table. |
| 708 | execsql { |
| 709 | SELECT * FROM de; |
| 710 | } |
| 711 | } {Ubon 120000 {Khon Kaen} 200000} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 712 | do_test shared-$av.10.5 { |
danielk1977 | b597f74 | 2006-01-15 11:39:18 +0000 | [diff] [blame] | 713 | # Closing db2 should have dropped the shared-cache back to a read-lock. |
| 714 | # So db3 should be able to prepare a write... |
| 715 | catchsql {INSERT INTO de VALUES('Pataya', 30000);} db3 |
| 716 | } {0 {}} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 717 | do_test shared-$av.10.6 { |
danielk1977 | b597f74 | 2006-01-15 11:39:18 +0000 | [diff] [blame] | 718 | # ... but not commit it. |
| 719 | catchsql {COMMIT} db3 |
| 720 | } {1 {database is locked}} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 721 | do_test shared-$av.10.7 { |
danielk1977 | b597f74 | 2006-01-15 11:39:18 +0000 | [diff] [blame] | 722 | # Commit the (read-only) db transaction. Check via db3 to make sure the |
| 723 | # contents of table "de" are still as they should be. |
| 724 | execsql { |
| 725 | COMMIT; |
| 726 | } |
| 727 | execsql { |
| 728 | SELECT * FROM de; |
| 729 | } db3 |
| 730 | } {Ubon 120000 {Khon Kaen} 200000 Pataya 30000} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 731 | do_test shared-$av.10.9 { |
danielk1977 | b597f74 | 2006-01-15 11:39:18 +0000 | [diff] [blame] | 732 | # Commit the external transaction. |
| 733 | catchsql {COMMIT} db3 |
| 734 | } {0 {}} |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 735 | integrity_check shared-$av.10.10 |
| 736 | do_test shared-$av.10.11 { |
danielk1977 | b597f74 | 2006-01-15 11:39:18 +0000 | [diff] [blame] | 737 | db close |
| 738 | db3 close |
| 739 | } {} |
| 740 | |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 741 | } |
| 742 | |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 743 | sqlite3_enable_shared_cache $::enable_shared_cache |
danielk1977 | a96a710 | 2006-01-16 12:46:41 +0000 | [diff] [blame^] | 744 | finish_test |