]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add tests for snapshot_get(), _open() and _free().
authordan <dan@noemail.net>
Mon, 7 Dec 2015 14:33:07 +0000 (14:33 +0000)
committerdan <dan@noemail.net>
Mon, 7 Dec 2015 14:33:07 +0000 (14:33 +0000)
FossilOrigin-Name: 502cc6f353358946080d9bcd335aed526825b88a

manifest
manifest.uuid
src/wal.c
test/snapshot.test [new file with mode: 0644]

index 2447acbb5aa0a272b6d27be9051cedb3fd20f9ad..1e9eafc39ed6b0944d9ecc69c7e5c323879930e1 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\suntested\simplementations\sof\sexperimental\sAPIs\ssqlite3_snapshot_get(),\s_open()\sand\s_free().
-D 2015-12-05T20:51:54.748
+C Add\stests\sfor\ssnapshot_get(),\s_open()\sand\s_free().
+D 2015-12-07T14:33:07.393
 F Makefile.in 28bcd6149e050dff35d4dcfd97e890cd387a499d
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc e8fdca1cb89a1b58b5f4d3a130ea9a3d28cb314d
@@ -415,7 +415,7 @@ F src/vdbesort.c a7ec02da4494c59dfd071126dd3726be5a11459d
 F src/vdbetrace.c 8befe829faff6d9e6f6e4dee5a7d3f85cc85f1a0
 F src/vtab.c 2a8b44aa372c33f6154208e7a7f6c44254549806
 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb
-F src/wal.c b9b1d5a1dd6e9b4f14f62326f34d719d14b33f08
+F src/wal.c abce669053edf5cd1cd1751d654d48d74ed47839
 F src/wal.h 907943dfdef10b583e81906679a347e0ec6f1b1b
 F src/walker.c 2e14d17f592d176b6dc879c33fbdec4fbccaa2ba
 F src/where.c b18edbb9e5afabb77f4f27550c471c5c824e0fe7
@@ -1020,6 +1020,7 @@ F test/skipscan2.test d1d1450952b7275f0b0a3a981f0230532743951a
 F test/skipscan3.test ec5bab3f81c7038b43450e7b3062e04a198bdbb5
 F test/skipscan5.test 67817a4b6857c47e0e33ba3e506da6f23ef68de2
 F test/skipscan6.test 5866039d03a56f5bd0b3d172a012074a1d90a15b
+F test/snapshot.test 061dc75b77ca65c0e9c5976499625abe5be7a5c0
 F test/soak.test 0b5b6375c9f4110c828070b826b3b4b0bb65cd5f
 F test/softheap1.test 843cd84db9891b2d01b9ab64cef3e9020f98d087
 F test/sort.test 3f492e5b7be1d3f756728d2ff6edf4f6091e84cb
@@ -1408,10 +1409,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 4ecbc75b465533cf80e166a9d0879b9afd3fe2be
-R 89117c604019561442a571d3627293e1
-T *branch * snapshot-get
-T *sym-snapshot-get *
-T -sym-trunk *
+P 0715eb00aa8891400cd50a15509d3d7b13789626
+R e71fd4e8a4bba215d14ff5f093a4f95d
 U dan
-Z 6ebcf0f2bc9e753be007db23f7cb64c3
+Z b314e37499d3a0450136f5ece5d06812
index f4219011d620b0234cc06f643cc7f21a62327156..d3b0195b25f2d199d9a8b629c24024bb1b898cf2 100644 (file)
@@ -1 +1 @@
-0715eb00aa8891400cd50a15509d3d7b13789626
\ No newline at end of file
+502cc6f353358946080d9bcd335aed526825b88a
\ No newline at end of file
index c4823c7cd2d640148b47d811e18c0b72237abac8..49811fb9b413517d8b7af4ab4e54b1a109785730 100644 (file)
--- a/src/wal.c
+++ b/src/wal.c
@@ -2259,7 +2259,9 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){
   mxI = 0;
   mxFrame = pWal->hdr.mxFrame;
 #ifdef SQLITE_ENABLE_SNAPSHOT
-  if( pWal->pSnapshot ) mxFrame = pWal->pSnapshot->mxFrame;
+  if( pWal->pSnapshot && pWal->pSnapshot->mxFrame<mxFrame ){
+    mxFrame = pWal->pSnapshot->mxFrame;
+  }
 #endif
   for(i=1; i<WAL_NREADER; i++){
     u32 thisMark = pInfo->aReadMark[i];
diff --git a/test/snapshot.test b/test/snapshot.test
new file mode 100644 (file)
index 0000000..4d94225
--- /dev/null
@@ -0,0 +1,218 @@
+# 2015 December 7
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.  The
+# focus of this file is testing the SELECT statement.
+#
+# $Id: select1.test,v 1.70 2009/05/28 01:00:56 drh Exp $
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix snapshot
+
+#-------------------------------------------------------------------------
+# Check some error conditions in snapshot_get(). It is an error if:
+#
+#  1) snapshot_get() is called on a non-WAL database.
+#  2) there is no open read transaction on the database, or
+#  3) there is an open write transaction on the database.
+#
+do_execsql_test 1.0 {
+  CREATE TABLE t1(a, b);
+  INSERT INTO t1 VALUES(1, 2);
+  INSERT INTO t1 VALUES(3, 4);
+}
+
+do_test 1.1.1 {
+  execsql { BEGIN; SELECT * FROM t1; }
+  list [catch { sqlite3_snapshot_get db main } msg] $msg
+} {1 SQLITE_ERROR}
+do_execsql_test 1.1.2 COMMIT
+
+do_test 1.2.1 {
+  execsql {
+    PRAGMA journal_mode = wal;
+    INSERT INTO t1 VALUES(5, 6);
+  }
+  list [catch { sqlite3_snapshot_get db main } msg] $msg
+} {1 SQLITE_ERROR}
+
+do_test 1.3.1 {
+  execsql {
+    BEGIN;
+      INSERT INTO t1 VALUES(7, 8);
+  }
+  list [catch { sqlite3_snapshot_get db main } msg] $msg
+} {1 SQLITE_ERROR}
+do_execsql_test 1.3.2 COMMIT
+
+#-------------------------------------------------------------------------
+# Check that a simple case works. Reuse the database created by the
+# block of tests above.
+#
+do_execsql_test 2.0 {
+  BEGIN;
+    SELECT * FROM t1;
+} {1 2 3 4 5 6 7 8}
+
+do_test 2.1 {
+  set snapshot [sqlite3_snapshot_get db main]
+  execsql {
+    COMMIT;
+    INSERT INTO t1 VALUES(9, 10);
+    SELECT * FROM t1;
+  }
+} {1 2 3 4 5 6 7 8 9 10}
+
+do_test 2.2 {
+  execsql BEGIN
+  sqlite3_snapshot_open db main $snapshot
+  execsql { SELECT * FROM t1 }
+} {1 2 3 4 5 6 7 8}
+
+do_test 2.3 {
+  sqlite3_snapshot_free $snapshot
+  execsql COMMIT
+} {}
+
+#-------------------------------------------------------------------------
+# Check some errors in sqlite3_snapshot_open(). It is an error if:
+#
+#   1) the db is in auto-commit mode,
+#   2) the db has an open (read or write) transaction,
+#   3) the db is not a wal database,
+#
+# Reuse the database created by earlier tests.
+#
+do_execsql_test 3.0.0 {
+  CREATE TABLE t2(x, y);
+  INSERT INTO t2 VALUES('a', 'b');
+  INSERT INTO t2 VALUES('c', 'd');
+  BEGIN;
+    SELECT * FROM t2;
+} {a b c d}
+do_test 3.0.1 {
+  set snapshot [sqlite3_snapshot_get db main]
+  execsql { COMMIT }
+  execsql { INSERT INTO t2 VALUES('e', 'f'); }
+} {}
+
+do_test 3.1 {
+  list [catch {sqlite3_snapshot_open db main $snapshot } msg] $msg
+} {1 SQLITE_ERROR}
+
+do_test 3.2.1 {
+  execsql {
+    BEGIN;
+      SELECT * FROM t2;
+  }
+} {a b c d e f}
+do_test 3.2.2 {
+  list [catch {sqlite3_snapshot_open db main $snapshot } msg] $msg
+} {1 SQLITE_ERROR}
+
+do_test 3.2.3 {
+  execsql {
+    COMMIT;
+    BEGIN;
+      INSERT INTO t2 VALUES('g', 'h');
+  }
+  list [catch {sqlite3_snapshot_open db main $snapshot } msg] $msg
+} {1 SQLITE_ERROR}
+do_execsql_test 3.2.4 COMMIT
+
+do_test 3.3.1 {
+  execsql { PRAGMA journal_mode = DELETE }
+  execsql { BEGIN }
+  list [catch {sqlite3_snapshot_open db main $snapshot } msg] $msg
+} {1 SQLITE_ERROR}
+
+do_test 3.3.2 {
+  sqlite3_snapshot_free $snapshot
+  execsql COMMIT
+} {}
+
+#-------------------------------------------------------------------------
+# Check that SQLITE_BUSY_SNAPSHOT is returned if the specified snapshot
+# no longer exists because the wal file has been checkpointed.
+#
+#   1. Reading a snapshot from the middle of a wal file is not possible
+#      after the wal file has been checkpointed.
+#
+#   2. That a snapshot from the end of a wal file can not be read once
+#      the wal file has been wrapped.
+#
+do_execsql_test 4.1.0 {
+  PRAGMA journal_mode = wal;
+  CREATE TABLE t3(i, j);
+  INSERT INTO t3 VALUES('o', 't');
+  INSERT INTO t3 VALUES('t', 'f');
+  BEGIN;
+    SELECT * FROM t3;
+} {wal o t t f}
+
+do_test 4.1.1 {
+  set snapshot [sqlite3_snapshot_get db main]
+  execsql COMMIT
+} {}
+do_test 4.1.2 {
+  execsql { 
+    INSERT INTO t3 VALUES('f', 's'); 
+    BEGIN;
+  }
+  sqlite3_snapshot_open db main $snapshot
+  execsql { SELECT * FROM t3 }
+} {o t t f}
+
+do_test 4.1.3 {
+  execsql { 
+    COMMIT;
+    PRAGMA wal_checkpoint;
+    BEGIN;
+  }
+  list [catch {sqlite3_snapshot_open db main $snapshot} msg] $msg
+} {1 SQLITE_BUSY_SNAPSHOT}
+do_test 4.1.4 {
+  sqlite3_snapshot_free $snapshot
+  execsql COMMIT
+} {}
+
+do_test 4.2.1 {
+  execsql {
+    INSERT INTO t3 VALUES('s', 'e');
+    INSERT INTO t3 VALUES('n', 't');
+    BEGIN;
+      SELECT * FROM t3;
+  }
+} {o t t f f s s e n t}
+do_test 4.2.2 {
+  set snapshot [sqlite3_snapshot_get db main]
+  execsql {
+    COMMIT;
+    PRAGMA wal_checkpoint;
+    BEGIN;
+  }
+  sqlite3_snapshot_open db main $snapshot
+  execsql { SELECT * FROM t3 }
+} {o t t f f s s e n t}
+do_test 4.2.3 {
+  execsql {
+    COMMIT;
+    INSERT INTO t3 VALUES('e', 't');
+    BEGIN;
+  }
+  list [catch {sqlite3_snapshot_open db main $snapshot} msg] $msg
+} {1 SQLITE_BUSY_SNAPSHOT}
+do_test 4.2.4 {
+  sqlite3_snapshot_free $snapshot
+} {}
+
+finish_test
+