sl@0
|
1 |
# 2005 January 19
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
#
|
sl@0
|
12 |
# $Id: shared2.test,v 1.5 2007/08/23 02:47:54 drh Exp $
|
sl@0
|
13 |
|
sl@0
|
14 |
set testdir [file dirname $argv0]
|
sl@0
|
15 |
source $testdir/tester.tcl
|
sl@0
|
16 |
db close
|
sl@0
|
17 |
|
sl@0
|
18 |
ifcapable !shared_cache {
|
sl@0
|
19 |
finish_test
|
sl@0
|
20 |
return
|
sl@0
|
21 |
}
|
sl@0
|
22 |
set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
|
sl@0
|
23 |
|
sl@0
|
24 |
# Test that if we delete all rows from a table any read-uncommitted
|
sl@0
|
25 |
# cursors are correctly invalidated. Test on both table and index btrees.
|
sl@0
|
26 |
do_test shared2-1.1 {
|
sl@0
|
27 |
sqlite3 db1 test.db
|
sl@0
|
28 |
sqlite3 db2 test.db
|
sl@0
|
29 |
|
sl@0
|
30 |
# Set up some data. Table "numbers" has 64 rows after this block
|
sl@0
|
31 |
# is executed.
|
sl@0
|
32 |
execsql {
|
sl@0
|
33 |
BEGIN;
|
sl@0
|
34 |
CREATE TABLE numbers(a PRIMARY KEY, b);
|
sl@0
|
35 |
INSERT INTO numbers(oid) VALUES(NULL);
|
sl@0
|
36 |
INSERT INTO numbers(oid) SELECT NULL FROM numbers;
|
sl@0
|
37 |
INSERT INTO numbers(oid) SELECT NULL FROM numbers;
|
sl@0
|
38 |
INSERT INTO numbers(oid) SELECT NULL FROM numbers;
|
sl@0
|
39 |
INSERT INTO numbers(oid) SELECT NULL FROM numbers;
|
sl@0
|
40 |
INSERT INTO numbers(oid) SELECT NULL FROM numbers;
|
sl@0
|
41 |
INSERT INTO numbers(oid) SELECT NULL FROM numbers;
|
sl@0
|
42 |
UPDATE numbers set a = oid, b = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
sl@0
|
43 |
COMMIT;
|
sl@0
|
44 |
} db1
|
sl@0
|
45 |
} {}
|
sl@0
|
46 |
do_test shared2-1.2 {
|
sl@0
|
47 |
# Put connection 2 in read-uncommitted mode and start a SELECT on table
|
sl@0
|
48 |
# 'numbers'. Half way through the SELECT, use connection 1 to delete the
|
sl@0
|
49 |
# contents of this table.
|
sl@0
|
50 |
execsql {
|
sl@0
|
51 |
pragma read_uncommitted = 1;
|
sl@0
|
52 |
} db2
|
sl@0
|
53 |
set count [execsql {SELECT count(*) FROM numbers} db2]
|
sl@0
|
54 |
db2 eval {SELECT a FROM numbers ORDER BY oid} {
|
sl@0
|
55 |
if {$a==32} {
|
sl@0
|
56 |
execsql {
|
sl@0
|
57 |
BEGIN;
|
sl@0
|
58 |
DELETE FROM numbers;
|
sl@0
|
59 |
} db1
|
sl@0
|
60 |
}
|
sl@0
|
61 |
}
|
sl@0
|
62 |
list $a $count
|
sl@0
|
63 |
} {32 64}
|
sl@0
|
64 |
do_test shared2-1.3 {
|
sl@0
|
65 |
# Same test as 1.2, except scan using the index this time.
|
sl@0
|
66 |
execsql {
|
sl@0
|
67 |
ROLLBACK;
|
sl@0
|
68 |
} db1
|
sl@0
|
69 |
set count [execsql {SELECT count(*) FROM numbers} db2]
|
sl@0
|
70 |
db2 eval {SELECT a, b FROM numbers ORDER BY a} {
|
sl@0
|
71 |
if {$a==32} {
|
sl@0
|
72 |
execsql {
|
sl@0
|
73 |
DELETE FROM numbers;
|
sl@0
|
74 |
} db1
|
sl@0
|
75 |
}
|
sl@0
|
76 |
}
|
sl@0
|
77 |
list $a $count
|
sl@0
|
78 |
} {32 64}
|
sl@0
|
79 |
|
sl@0
|
80 |
#---------------------------------------------------------------------------
|
sl@0
|
81 |
# These tests, shared2.2.*, test the outcome when data is added to or
|
sl@0
|
82 |
# removed from a table due to a rollback while a read-uncommitted
|
sl@0
|
83 |
# cursor is scanning it.
|
sl@0
|
84 |
#
|
sl@0
|
85 |
do_test shared2-2.1 {
|
sl@0
|
86 |
execsql {
|
sl@0
|
87 |
INSERT INTO numbers VALUES(1, 'Medium length text field');
|
sl@0
|
88 |
INSERT INTO numbers VALUES(2, 'Medium length text field');
|
sl@0
|
89 |
INSERT INTO numbers VALUES(3, 'Medium length text field');
|
sl@0
|
90 |
INSERT INTO numbers VALUES(4, 'Medium length text field');
|
sl@0
|
91 |
BEGIN;
|
sl@0
|
92 |
DELETE FROM numbers WHERE (a%2)=0;
|
sl@0
|
93 |
} db1
|
sl@0
|
94 |
set res [list]
|
sl@0
|
95 |
db2 eval {
|
sl@0
|
96 |
SELECT a FROM numbers ORDER BY a;
|
sl@0
|
97 |
} {
|
sl@0
|
98 |
lappend res $a
|
sl@0
|
99 |
if {$a==3} {
|
sl@0
|
100 |
execsql {ROLLBACK} db1
|
sl@0
|
101 |
}
|
sl@0
|
102 |
}
|
sl@0
|
103 |
set res
|
sl@0
|
104 |
} {1 3 4}
|
sl@0
|
105 |
do_test shared2-2.2 {
|
sl@0
|
106 |
execsql {
|
sl@0
|
107 |
BEGIN;
|
sl@0
|
108 |
INSERT INTO numbers VALUES(5, 'Medium length text field');
|
sl@0
|
109 |
INSERT INTO numbers VALUES(6, 'Medium length text field');
|
sl@0
|
110 |
} db1
|
sl@0
|
111 |
set res [list]
|
sl@0
|
112 |
db2 eval {
|
sl@0
|
113 |
SELECT a FROM numbers ORDER BY a;
|
sl@0
|
114 |
} {
|
sl@0
|
115 |
lappend res $a
|
sl@0
|
116 |
if {$a==5} {
|
sl@0
|
117 |
execsql {ROLLBACK} db1
|
sl@0
|
118 |
}
|
sl@0
|
119 |
}
|
sl@0
|
120 |
set res
|
sl@0
|
121 |
} {1 2 3 4 5}
|
sl@0
|
122 |
|
sl@0
|
123 |
db1 close
|
sl@0
|
124 |
db2 close
|
sl@0
|
125 |
|
sl@0
|
126 |
do_test shared2-3.2 {
|
sl@0
|
127 |
sqlite3_enable_shared_cache 1
|
sl@0
|
128 |
} {1}
|
sl@0
|
129 |
|
sl@0
|
130 |
sqlite3_enable_shared_cache $::enable_shared_cache
|
sl@0
|
131 |
finish_test
|