aboutsummaryrefslogtreecommitdiff
path: root/test/shared.test
diff options
context:
space:
mode:
Diffstat (limited to 'test/shared.test')
-rw-r--r--test/shared.test74
1 files changed, 73 insertions, 1 deletions
diff --git a/test/shared.test b/test/shared.test
index 6929e50a0..f41290385 100644
--- a/test/shared.test
+++ b/test/shared.test
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the SELECT statement.
#
-# $Id: shared.test,v 1.6 2006/01/07 13:21:04 danielk1977 Exp $
+# $Id: shared.test,v 1.7 2006/01/09 06:29:49 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -35,6 +35,7 @@ set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
# shared-5.*: Test that creating/dropping schema items works when databases
# are attached in different orders to different handles.
# shared-6.*: Locking, UNION ALL queries and sub-queries.
+# shared-6.*: Autovacuum and shared-cache.
#
do_test shared-1.1 {
@@ -464,6 +465,77 @@ do_test shared-6.1.3 {
catch {db1 close}
catch {db2 close}
+foreach f [list test.db test2.db] {
+ file delete -force $f ${f}-journal
+}
+
+#--------------------------------------------------------------------------
+# Tests shared-7.* test auto-vacuum does not invalidate cursors from
+# other shared-cache users when it reorganizes the database on
+# COMMIT.
+#
+do_test shared-7.1 {
+ sqlite3 db test.db
+ sqlite3 db2 test.db
+ execsql {
+ PRAGMA auto_vacuum = 1;
+ BEGIN;
+ CREATE TABLE t1(a PRIMARY KEY, b);
+ CREATE TABLE t2(a PRIMARY KEY, b);
+ }
+ for {set i 0} {$i < 100} {incr i} {
+ set a [string repeat "$i " 20]
+ set b [string repeat "$i " 20]
+ db eval {
+ INSERT INTO t1 VALUES($a, $b);
+ }
+ lappend ::contents [list [expr $i+1] $a $b]
+ }
+ execsql {
+ INSERT INTO t2 SELECT * FROM t1;
+ COMMIT;
+ }
+ execsql {
+ PRAGMA auto_vacuum;
+ }
+} {1}
+do_test shared-7.2 {
+ proc lockrow {db tbl oids body} {
+ set ret [list]
+ db eval "SELECT oid AS i, a, b FROM $tbl ORDER BY a" {
+ if {$i==[lindex $oids 0]} {
+ set noids [lrange $oids 1 end]
+ if {[llength $noids]==0} {
+ set subret [eval $body]
+ } else {
+ set subret [lockrow $db $tbl $noids $body]
+ }
+ }
+ lappend ret [list $i $a $b]
+ }
+ return [linsert $subret 0 $ret]
+ }
+ proc locktblrows {db tbl body} {
+ set oids [db eval "SELECT oid FROM $tbl"]
+ lockrow $db $tbl $oids $body
+ }
+
+ set scans [locktblrows db t2 {
+ execsql {
+ DELETE FROM t1;
+ } db2
+ }]
+ set error 0
+ foreach s $scans {
+ if {[lsort -integer -index 0 $s]!=$::contents} {
+ set error 1
+ }
+ }
+ set error
+} {0}
+
+catch {db close}
+catch {db2 close}
finish_test
sqlite3_enable_shared_cache $::enable_shared_cache