aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/corrupt2.test46
-rw-r--r--test/shared6.test79
2 files changed, 123 insertions, 2 deletions
diff --git a/test/corrupt2.test b/test/corrupt2.test
index 652f7844a..3f5019623 100644
--- a/test/corrupt2.test
+++ b/test/corrupt2.test
@@ -13,7 +13,7 @@
# This file implements tests to make sure SQLite does not crash or
# segfault if it sees a corrupt database file.
#
-# $Id: corrupt2.test,v 1.18 2008/09/29 11:49:48 danielk1977 Exp $
+# $Id: corrupt2.test,v 1.19 2009/04/02 18:28:08 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -455,4 +455,48 @@ corruption_test -sqlprep {
} {SQLITE_CORRUPT}
}
+corruption_test -sqlprep {
+ PRAGMA auto_vacuum = incremental;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
+ CREATE TABLE t2(a INTEGER PRIMARY KEY, b);
+ INSERT INTO t1 VALUES(1, randstr(100,100));
+ INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1;
+ INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1;
+ INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1;
+ INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1;
+ INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1;
+ INSERT INTO t2 SELECT * FROM t1;
+ DELETE FROM t1;
+} -corrupt {
+ set offset [expr [file size corrupt.db] - 1024]
+ hexio_write corrupt.db $offset FF
+ hexio_write corrupt.db 24 12345678
+} -test {
+ do_test corrupt2-11.1 {
+ catchsql { PRAGMA incremental_vacuum }
+ } {1 {database disk image is malformed}}
+}
+
+corruption_test -sqlprep {
+ PRAGMA auto_vacuum = incremental;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
+ CREATE TABLE t2(a INTEGER PRIMARY KEY, b);
+ INSERT INTO t1 VALUES(1, randstr(100,100));
+ INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1;
+ INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1;
+ INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1;
+ INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1;
+ INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1;
+ INSERT INTO t2 SELECT * FROM t1;
+ DELETE FROM t1;
+} -corrupt {
+ set pgno [expr [file size corrupt.db] / 1024]
+ hexio_write corrupt.db [expr 1024+5*($pgno-3)] 03
+ hexio_write corrupt.db 24 12345678
+} -test {
+ do_test corrupt2-12.1 {
+ catchsql { PRAGMA incremental_vacuum }
+ } {1 {database disk image is malformed}}
+}
+
finish_test
diff --git a/test/shared6.test b/test/shared6.test
index 2d22a301a..ef04aac85 100644
--- a/test/shared6.test
+++ b/test/shared6.test
@@ -9,7 +9,7 @@
#
#***********************************************************************
#
-# $Id: shared6.test,v 1.2 2009/04/01 18:25:54 danielk1977 Exp $
+# $Id: shared6.test,v 1.3 2009/04/02 18:28:08 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -21,6 +21,7 @@ do_test shared6-1.1.1 {
CREATE TABLE t2(c, d);
CREATE TABLE t3(e, f);
}
+ db close
} {}
do_test shared6-1.1.2 {
set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
@@ -133,9 +134,11 @@ do_test shared6-1.X {
db2 close
} {}
+#-------------------------------------------------------------------------
# The following tests - shared6-2.* - test that two database connections
# that connect to the same file using different VFS implementations do
# not share a cache.
+#
if {$::tcl_platform(platform) eq "unix"} {
do_test shared6-2.1 {
sqlite3 db1 test.db -vfs unix
@@ -174,6 +177,80 @@ if {$::tcl_platform(platform) eq "unix"} {
} {}
}
+#-------------------------------------------------------------------------
+# Test that it is possible to open an exclusive transaction while
+# already holding a read-lock on the database file. And that it is
+# not possible if some other connection holds such a lock.
+#
+do_test shared6-3.1 {
+ sqlite3 db1 test.db
+ sqlite3 db2 test.db
+ sqlite3 db3 test.db
+} {}
+db1 eval {SELECT * FROM t1} {
+ # Within this block [db1] is holding a read-lock on t1. Test that
+ # this means t1 cannot be written by [db2].
+ #
+ do_test shared6-3.2 {
+ catchsql { INSERT INTO t1 VALUES(1, 2) } db2
+ } {1 {database table is locked: t1}}
+
+ do_test shared6-3.3 {
+ execsql { BEGIN EXCLUSIVE } db1
+ } {}
+ break
+}
+do_test shared6-3.4 {
+ catchsql { SELECT * FROM t1 } db2
+} {1 {database schema is locked: main}}
+do_test shared6-3.5 {
+ execsql COMMIT db1
+} {}
+db2 eval {SELECT * FROM t1} {
+ do_test shared6-3.6 {
+ catchsql { BEGIN EXCLUSIVE } db1
+ } {1 {database table is locked}}
+ break
+}
+do_test shared6-3.7 {
+ execsql { BEGIN } db1
+ execsql { BEGIN } db2
+} {}
+db2 eval {SELECT * FROM t1} {
+ do_test shared6-3.8 {
+ catchsql { INSERT INTO t1 VALUES(1, 2) } db1
+ } {1 {database table is locked: t1}}
+ break
+}
+do_test shared6-3.9 {
+ execsql { BEGIN ; ROLLBACK } db3
+} {}
+do_test shared6-3.10 {
+ catchsql { SELECT * FROM t1 } db3
+} {1 {database table is locked}}
+do_test shared6-3.X {
+ db1 close
+ db2 close
+ db3 close
+} {}
+
+do_test shared6-4.1 {
+ #file delete -force test.db test.db-journal
+ sqlite3 db1 test.db
+ sqlite3 db2 test.db
+
+ set ::STMT [sqlite3_prepare_v2 db1 "SELECT * FROM t1" -1 DUMMY]
+ execsql { CREATE TABLE t5(a, b) } db2
+} {}
+do_test shared6-4.2 {
+ sqlite3_finalize $::STMT
+} {SQLITE_OK}
+do_test shared6-4.X {
+
+ db1 close
+ db2 close
+} {}
+
sqlite3_enable_shared_cache $::enable_shared_cache
finish_test