OLD | NEW |
1 # 2007 March 24 | 1 # 2007 March 24 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 do_test exclusive-2.7 { | 205 do_test exclusive-2.7 { |
206 catchsql { | 206 catchsql { |
207 COMMIT | 207 COMMIT |
208 } db2 | 208 } db2 |
209 } {1 {database is locked}} | 209 } {1 {database is locked}} |
210 do_test exclusive-2.8 { | 210 do_test exclusive-2.8 { |
211 execsql { | 211 execsql { |
212 ROLLBACK; | 212 ROLLBACK; |
213 } db2 | 213 } db2 |
214 } {} | 214 } {} |
215 sqlite3_soft_heap_limit $soft_limit | 215 sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) |
216 | 216 |
217 do_test exclusive-2.9 { | 217 do_test exclusive-2.9 { |
218 # Write the database to establish the exclusive lock with connection 'db. | 218 # Write the database to establish the exclusive lock with connection 'db. |
219 execsql { | 219 execsql { |
220 INSERT INTO abc VALUES(7, 8, 9); | 220 INSERT INTO abc VALUES(7, 8, 9); |
221 } db | 221 } db |
222 catchsql { | 222 catchsql { |
223 SELECT * FROM abc; | 223 SELECT * FROM abc; |
224 } db2 | 224 } db2 |
225 } {1 {database is locked}} | 225 } {1 {database is locked}} |
(...skipping 20 matching lines...) Expand all Loading... |
246 #---------------------------------------------------------------------- | 246 #---------------------------------------------------------------------- |
247 # Tests exclusive-3.X - test that a connection in exclusive mode | 247 # Tests exclusive-3.X - test that a connection in exclusive mode |
248 # truncates instead of deletes the journal file when committing | 248 # truncates instead of deletes the journal file when committing |
249 # a transaction. | 249 # a transaction. |
250 # | 250 # |
251 # These tests are not run on windows because the windows backend | 251 # These tests are not run on windows because the windows backend |
252 # opens the journal file for exclusive access, preventing its contents | 252 # opens the journal file for exclusive access, preventing its contents |
253 # from being inspected externally. | 253 # from being inspected externally. |
254 # | 254 # |
255 if {$tcl_platform(platform) != "windows"} { | 255 if {$tcl_platform(platform) != "windows"} { |
| 256 |
| 257 # Return a list of two booleans (either 0 or 1). The first is true |
| 258 # if the named file exists. The second is true only if the file |
| 259 # exists and the first 28 bytes contain at least one non-zero byte. |
| 260 # |
256 proc filestate {fname} { | 261 proc filestate {fname} { |
257 set exists 0 | 262 set exists 0 |
258 set content 0 | 263 set content 0 |
259 if {[file exists $fname]} { | 264 if {[file exists $fname]} { |
260 set exists 1 | 265 set exists 1 |
261 set hdr [hexio_read $fname 0 28] | 266 set hdr [hexio_read $fname 0 28] |
262 set content [expr {0==[string match $hdr [string repeat 0 56]]}] | 267 set content [expr {0==[string match $hdr [string repeat 0 56]]}] |
263 } | 268 } |
264 list $exists $content | 269 list $exists $content |
265 } | 270 } |
| 271 |
266 do_test exclusive-3.0 { | 272 do_test exclusive-3.0 { |
267 filestate test.db-journal | 273 filestate test.db-journal |
268 } {0 0} | 274 } {0 0} |
269 do_test exclusive-3.1 { | 275 do_test exclusive-3.1 { |
270 execsql { | 276 execsql { |
271 PRAGMA locking_mode = exclusive; | 277 PRAGMA locking_mode = exclusive; |
272 BEGIN; | 278 BEGIN; |
273 DELETE FROM abc; | 279 DELETE FROM abc; |
274 } | 280 } |
275 filestate test.db-journal | 281 filestate test.db-journal |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 389 |
384 #---------------------------------------------------------------------- | 390 #---------------------------------------------------------------------- |
385 # Tests exclusive-5.X - test that statement journals are truncated | 391 # Tests exclusive-5.X - test that statement journals are truncated |
386 # instead of deleted when in exclusive access mode. | 392 # instead of deleted when in exclusive access mode. |
387 # | 393 # |
388 | 394 |
389 # Close and reopen the database so that the temp database is no | 395 # Close and reopen the database so that the temp database is no |
390 # longer active. | 396 # longer active. |
391 # | 397 # |
392 db close | 398 db close |
393 sqlite db test.db | 399 sqlite3 db test.db |
394 | 400 |
395 # if we're using proxy locks, we use 3 filedescriptors for a db | 401 # if we're using proxy locks, we use 3 filedescriptors for a db |
396 # that is open but NOT writing changes, normally | 402 # that is open but NOT writing changes, normally |
397 # sqlite uses 1 (proxy locking adds the conch and the local lock) | 403 # sqlite uses 1 (proxy locking adds the conch and the local lock) |
398 set using_proxy 0 | 404 set using_proxy 0 |
399 foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] { | 405 foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] { |
400 set using_proxy $value | 406 set using_proxy $value |
401 } | 407 } |
402 set extrafds 0 | 408 set extrafds 0 |
403 if {$using_proxy!=0} { | 409 if {$using_proxy!=0} { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 PRAGMA locking_mode = normal; | 462 PRAGMA locking_mode = normal; |
457 SELECT * FROM abc; | 463 SELECT * FROM abc; |
458 } | 464 } |
459 } {normal 1 2 3 2 3 4 5 6 7 11 12 13 12 13 14 15 16 17} | 465 } {normal 1 2 3 2 3 4 5 6 7 11 12 13 12 13 14 15 16 17} |
460 do_test exclusive-5.7 { | 466 do_test exclusive-5.7 { |
461 # Just the db open. | 467 # Just the db open. |
462 set sqlite_open_file_count | 468 set sqlite_open_file_count |
463 expr $sqlite_open_file_count-$extrafds | 469 expr $sqlite_open_file_count-$extrafds |
464 } {1} | 470 } {1} |
465 | 471 |
| 472 #------------------------------------------------------------------------- |
| 473 |
| 474 do_execsql_test exclusive-6.1 { |
| 475 CREATE TABLE t4(a, b); |
| 476 INSERT INTO t4 VALUES('Eden', 1955); |
| 477 BEGIN; |
| 478 INSERT INTO t4 VALUES('Macmillan', 1957); |
| 479 INSERT INTO t4 VALUES('Douglas-Home', 1963); |
| 480 INSERT INTO t4 VALUES('Wilson', 1964); |
| 481 } |
| 482 do_test exclusive-6.2 { |
| 483 forcedelete test2.db test2.db-journal |
| 484 file copy test.db test2.db |
| 485 file copy test.db-journal test2.db-journal |
| 486 sqlite3 db test2.db |
| 487 } {} |
| 488 |
| 489 do_execsql_test exclusive-6.3 { |
| 490 PRAGMA locking_mode = EXCLUSIVE; |
| 491 SELECT * FROM t4; |
| 492 } {exclusive Eden 1955} |
| 493 |
| 494 do_test exclusive-6.4 { |
| 495 db close |
| 496 forcedelete test.db test.db-journal |
| 497 set fd [open test.db-journal w] |
| 498 puts $fd x |
| 499 close $fd |
| 500 sqlite3 db test.db |
| 501 } {} |
| 502 |
| 503 do_execsql_test exclusive-6.5 { |
| 504 PRAGMA locking_mode = EXCLUSIVE; |
| 505 SELECT * FROM sqlite_master; |
| 506 } {exclusive} |
| 507 |
466 finish_test | 508 finish_test |
| 509 |
OLD | NEW |