1# 2005 January 19 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# $Id: shared2.test,v 1.1 2006/01/19 08:43:32 danielk1977 Exp $ 13 14set testdir [file dirname $argv0] 15source $testdir/tester.tcl 16db close 17 18ifcapable !shared_cache { 19 finish_test 20 return 21} 22set ::enable_shared_cache [sqlite3_enable_shared_cache 1] 23 24 25# Test that if we delete all rows from a table any read-uncommitted 26# cursors are correctly invalidated. Test on both table and index btrees. 27do_test shared2-1.1 { 28 sqlite3 db1 test.db 29 sqlite3 db2 test.db 30 31 # Set up some data. Table "numbers" has 64 rows after this block 32 # is executed. 33 execsql { 34 BEGIN; 35 CREATE TABLE numbers(a PRIMARY KEY, b); 36 INSERT INTO numbers(oid) VALUES(NULL); 37 INSERT INTO numbers(oid) SELECT NULL FROM numbers; 38 INSERT INTO numbers(oid) SELECT NULL FROM numbers; 39 INSERT INTO numbers(oid) SELECT NULL FROM numbers; 40 INSERT INTO numbers(oid) SELECT NULL FROM numbers; 41 INSERT INTO numbers(oid) SELECT NULL FROM numbers; 42 INSERT INTO numbers(oid) SELECT NULL FROM numbers; 43 UPDATE numbers set a = oid, b = 'abcdefghijklmnopqrstuvwxyz0123456789'; 44 COMMIT; 45 } db1 46} {} 47do_test shared2-1.2 { 48 # Put connection 2 in read-uncommitted mode and start a SELECT on table 49 # 'numbers'. Half way through the SELECT, use connection 1 to delete the 50 # contents of this table. 51 execsql { 52 pragma read_uncommitted = 1; 53 } db2 54 set count [execsql {SELECT count(*) FROM numbers} db2] 55 db2 eval {SELECT a FROM numbers ORDER BY oid} { 56 if {$a==32} { 57 execsql { 58 BEGIN; 59 DELETE FROM numbers; 60 } db1 61 } 62 } 63 list $a $count 64} {32 64} 65do_test shared2-1.3 { 66 # Same test as 1.2, except scan using the index this time. 67 execsql { 68 ROLLBACK; 69 } db1 70 set count [execsql {SELECT count(*) FROM numbers} db2] 71 db2 eval {SELECT a, b FROM numbers ORDER BY a} { 72 if {$a==32} { 73 execsql { 74 DELETE FROM numbers; 75 } db1 76 } 77 } 78 list $a $count 79} {32 64} 80 81db1 close 82db2 close 83 84sqlite3_enable_shared_cache $::enable_shared_cache 85finish_test 86