blob: ab76517a9acca3da10847a0029ad73c7ca35137f [file] [log] [blame]
danielk1977ed429312006-01-19 08:43:31 +00001# 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#
danielk19777246f5b2006-01-24 11:30:27 +000012# $Id: shared2.test,v 1.2 2006/01/24 11:30:27 danielk1977 Exp $
danielk1977ed429312006-01-19 08:43:31 +000013
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
danielk19777246f5b2006-01-24 11:30:27 +000084do_test shared2-1.4 {
85 sqlite3_thread_cleanup
86 sqlite3_enable_shared_cache 1
87} {0}
88
danielk1977ed429312006-01-19 08:43:31 +000089sqlite3_enable_shared_cache $::enable_shared_cache
90finish_test