3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # $Id: shared2.test,v 1.8 2009/06/05 17:09:12 drh Exp $
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
16 source $testdir/lock_common.tcl
17 source $testdir/malloc_common.tcl
20 ifcapable !shared_cache {
24 set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
26 # Test that if we delete all rows from a table any read-uncommitted
27 # cursors are correctly invalidated. Test on both table and index btrees.
32 # Set up some data. Table "numbers" has 64 rows after this block
36 CREATE TABLE numbers(a PRIMARY KEY, b);
37 INSERT INTO numbers(oid) VALUES(NULL);
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 INSERT INTO numbers(oid) SELECT NULL FROM numbers;
44 UPDATE numbers set a = oid, b = 'abcdefghijklmnopqrstuvwxyz0123456789';
49 # Put connection 2 in read-uncommitted mode and start a SELECT on table
50 # 'numbers'. Half way through the SELECT, use connection 1 to delete the
51 # contents of this table.
53 pragma read_uncommitted = 1;
55 set count [execsql {SELECT count(*) FROM numbers} db2]
56 db2 eval {SELECT a FROM numbers ORDER BY oid} {
67 # Same test as 1.2, except scan using the index this time.
71 set count [execsql {SELECT count(*) FROM numbers} db2]
72 db2 eval {SELECT a, b FROM numbers ORDER BY a} {
82 #---------------------------------------------------------------------------
83 # These tests, shared2.2.*, test the outcome when data is added to or
84 # removed from a table due to a rollback while a read-uncommitted
85 # cursor is scanning it.
89 INSERT INTO numbers VALUES(1, 'Medium length text field');
90 INSERT INTO numbers VALUES(2, 'Medium length text field');
91 INSERT INTO numbers VALUES(3, 'Medium length text field');
92 INSERT INTO numbers VALUES(4, 'Medium length text field');
94 DELETE FROM numbers WHERE (a%2)=0;
98 SELECT a FROM numbers ORDER BY a;
102 execsql {ROLLBACK} db1
107 do_test shared2-2.2 {
110 INSERT INTO numbers VALUES(5, 'Medium length text field');
111 INSERT INTO numbers VALUES(6, 'Medium length text field');
115 SELECT a FROM numbers ORDER BY a;
119 execsql {ROLLBACK} db1
128 do_test shared2-3.2 {
129 sqlite3_enable_shared_cache 1
132 file delete -force test.db
135 do_test shared2-4.1 {
137 CREATE TABLE t0(a, b);
138 CREATE TABLE t1(a, b DEFAULT 'hello world');
146 do_test shared2-4.2 {
147 execsql { SELECT a, b FROM t0 } db
148 execsql { INSERT INTO t1(a) VALUES(1) } db2
151 do_test shared2-4.3 {
156 # At one point, this was causing a crash.
158 do_test shared2-5.1 {
161 execsql { CREATE TABLE t2(a, b, c) }
163 # The following statement would crash when attempting to sqlite3_free()
164 # a pointer allocated from a lookaside buffer.
165 execsql { CREATE INDEX i1 ON t2(a) } db2
171 # The following test verifies that shared-cache mode does not automatically
172 # turn on exclusive-locking mode for some reason.
173 do_multiclient_test {tn} {
174 sql1 { CREATE TABLE t1(a, b) }
175 sql2 { CREATE TABLE t2(a, b) }
176 do_test shared2-6.$tn.1 { sql1 { SELECT * FROM t2 } } {}
177 do_test shared2-6.$tn.2 { sql2 { SELECT * FROM t1 } } {}
180 sqlite3_enable_shared_cache $::enable_shared_cache