]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add new test file e_walhook.test.
authordan <dan@noemail.net>
Wed, 10 Dec 2014 20:29:49 +0000 (20:29 +0000)
committerdan <dan@noemail.net>
Wed, 10 Dec 2014 20:29:49 +0000 (20:29 +0000)
FossilOrigin-Name: 2eb6d3e4fbe388ef28e4b7b846e9e8a4361517a4

manifest
manifest.uuid
src/sqlite.h.in
src/tclsqlite.c
test/e_walhook.test [new file with mode: 0644]

index 18deb8120f0262b49cb8a72201e7dc4ee1e6da69..f7c2015248bb52c5b5d8dd9b6bbc565f3480e5bd 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Revise\smutex\shandling\sby\sthe\ssqlite3_win32_reset_heap()\sfunction.
-D 2014-12-10T17:34:48.091
+C Add\snew\stest\sfile\se_walhook.test.
+D 2014-12-10T20:29:49.614
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 6c4f961fa91d0b4fa121946a19f9e5eac2f2f809
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -230,14 +230,14 @@ F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada
 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e
 F src/select.c f377fb8a5c73c10678ea74f3400f7913943e3d75
 F src/shell.c 45d9c9bd7cde07845af957f2d849933b990773cf
-F src/sqlite.h.in 6c1ca2ee6949a2232029ecd5391dcf3468bf4114
+F src/sqlite.h.in 2e699aabd1df6042aff4265cd93bdc8812629f11
 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad
 F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d
 F src/sqliteInt.h 28049b803b74a7f73242a8226915ea00ebb1309f
 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
 F src/status.c 81712116e826b0089bb221b018929536b2b5406f
 F src/table.c f142bba7903e93ca8d113a5b8877a108ad1a27dc
-F src/tclsqlite.c 0a874655dd39a9875e39c5d3c464db662171d228
+F src/tclsqlite.c c6a21c64da1490e14d53cdc2062d1e2e57942622
 F src/test1.c 7e806af12d7915445e46407d32b275d8ca9db4e7
 F src/test2.c 98049e51a17dc62606a99a9eb95ee477f9996712
 F src/test3.c 1c0e5d6f080b8e33c1ce8b3078e7013fdbcd560c
@@ -479,6 +479,7 @@ F test/e_uri.test 5ae33760fb2039c61aa2d90886f1664664173585
 F test/e_vacuum.test 5bfbdc21b65c0abf24398d0ba31dc88d93ca77a9
 F test/e_wal.test 0967f0b8f1dfda871dc7b9b5574198f1f4f7d69a
 F test/e_walckpt.test 3116a98fa0dd9b2c9e493de7c59730adfe436746
+F test/e_walhook.test 9a859599e9a0f354ffcc7c716f7ec699e41f617c
 F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
 F test/enc2.test 83437a79ba1545a55fb549309175c683fb334473
 F test/enc3.test 90683ad0e6ea587b9d5542ca93568af9a9858c40
@@ -1226,7 +1227,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 3528f8dd39acace8eeb7337994c8617313f4b04b
-R fe43d40d066c10ff075f9f4225f2f387
-U mistachkin
-Z cb29644ec15937d54f010f859dadafbb
+P eacb3b7baa910e84f984b8e45695a2a2f5a4c861
+R de56ad0a085434d1b275f3b398c245cd
+U dan
+Z 076528022e1550b90a78f1e189e33666
index 47c85f88700dc4dfa71569f678982af43ffd5399..989cb2cfa493eece8c258d10bb8f0115a9e3a2a9 100644 (file)
@@ -1 +1 @@
-eacb3b7baa910e84f984b8e45695a2a2f5a4c861
\ No newline at end of file
+2eb6d3e4fbe388ef28e4b7b846e9e8a4361517a4
\ No newline at end of file
index dd07976a1dc7b16c04d03c6931c3582c92fae289..a4ca7939698ff654464668c40a76191d39ad80fa 100644 (file)
@@ -7180,12 +7180,10 @@ void sqlite3_log(int iErrCode, const char *zFormat, ...);
 ** CAPI3REF: Write-Ahead Log Commit Hook
 **
 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
-** will be invoked each time a database connection commits data to a
-** [write-ahead log] (i.e. whenever a transaction is committed in
-** [journal_mode | journal_mode=WAL mode]). 
+** is invoked each time data is committed to a database in wal mode.
 **
-** ^The callback is invoked by SQLite after the commit has taken place and 
-** the associated write-lock on the database released, so the implementation 
+** ^(The callback is invoked by SQLite after the commit has taken place and 
+** the associated write-lock on the database released)^, so the implementation 
 ** may read, write or [checkpoint] the database as required.
 **
 ** ^The first parameter passed to the callback function when it is invoked
index 4fb78a5d12c2564d43a41f2ac8edf63b2d09ab8f..32de5273015368749b89f2b00a9d64f10004a915 100644 (file)
@@ -635,6 +635,7 @@ static int DbWalHandler(
   Tcl_Interp *interp = pDb->interp;
   assert(pDb->pWalHook);
 
+  assert( db==pDb->db );
   p = Tcl_DuplicateObj(pDb->pWalHook);
   Tcl_IncrRefCount(p);
   Tcl_ListObjAppendElement(interp, p, Tcl_NewStringObj(zDb, -1));
diff --git a/test/e_walhook.test b/test/e_walhook.test
new file mode 100644 (file)
index 0000000..e12d3b5
--- /dev/null
@@ -0,0 +1,199 @@
+# 2014 December 04
+#
+# 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.
+#
+#***********************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/wal_common.tcl
+set testprefix e_walhook
+
+
+# EVIDENCE-OF: R-00752-43975 The sqlite3_wal_hook() function is used to
+# register a callback that is invoked each time data is committed to a
+# database in wal mode.
+#
+#   1.1: shows that the wal-hook is not invoked in rollback mode.
+#   1.2: but is invoked in wal mode.
+#
+set ::wal_hook_count 0
+proc my_wal_hook {args} {
+  incr ::wal_hook_count
+  return 0
+}
+
+do_test 1.1.1 {
+  db wal_hook my_wal_hook
+  execsql {
+    CREATE TABLE t1(x);
+    INSERT INTO t1 VALUES(1);
+  }
+  set ::wal_hook_count
+} 0
+do_test 1.1.2 {
+  execsql { PRAGMA journal_mode = wal }
+  set ::wal_hook_count
+} 0
+
+do_test 1.3 {
+  execsql { INSERT INTO t1 VALUES(2) }
+  set wal_hook_count
+} 1
+
+do_test 1.4 {
+  execsql { 
+    BEGIN;
+      INSERT INTO t1 VALUES(3);
+      INSERT INTO t1 VALUES(4);
+    COMMIT;
+  }
+  set wal_hook_count
+} 2
+
+# EVIDENCE-OF: R-65366-15139 The callback is invoked by SQLite after the
+# commit has taken place and the associated write-lock on the database
+# released
+#
+set ::read_ok 0
+proc my_wal_hook {args} {
+  sqlite3 db2 test.db
+  if {[db2 eval { SELECT * FROM t1 }] == "1 2 3 4 5"} {
+    set ::read_ok 1
+  }
+  db2 close
+}
+do_test 2.1 {
+  execsql { INSERT INTO t1 VALUES(5) }
+  set ::read_ok
+} 1
+
+# EVIDENCE-OF: R-44294-52863 The third parameter is the name of the
+# database that was written to - either "main" or the name of an
+# ATTACH-ed database.
+#
+# EVIDENCE-OF: R-18913-19355 The fourth parameter is the number of pages
+# currently in the write-ahead log file, including those that were just
+# committed.
+#
+set ::wal_hook_args [list]
+proc my_wal_hook {dbname nEntry} {
+  set ::wal_hook_args [list $dbname $nEntry]
+}
+forcedelete test.db2
+do_test 3.0 {
+  execsql {
+    ATTACH 'test.db2' AS aux;
+    CREATE TABLE aux.t2(x);
+    PRAGMA aux.journal_mode = wal;
+  }
+} {wal}
+
+# Database "aux"
+do_test 3.1.1 {
+  set wal_hook_args [list]
+  execsql { INSERT INTO t2 VALUES('a') }
+} {}
+do_test 3.1.2 {
+  set wal_hook_args
+} [list aux [wal_frame_count test.db2-wal 1024]]
+
+# Database "main"
+do_test 3.2.1 {
+  set wal_hook_args [list]
+  execsql { INSERT INTO t1 VALUES(6) }
+} {}
+do_test 3.1.2 {
+  set wal_hook_args
+} [list main [wal_frame_count test.db-wal 1024]]
+
+# EVIDENCE-OF: R-14034-00929 If an error code is returned, that error
+# will propagate back up through the SQLite code base to cause the
+# statement that provoked the callback to report an error, though the
+# commit will have still occurred.
+#
+proc my_wal_hook {args} { return 1 ;# SQLITE_ERROR }
+do_catchsql_test 4.1 {
+  INSERT INTO t1 VALUES(7)
+} {1 {SQL logic error or missing database}}
+
+proc my_wal_hook {args} { return 5 ;# SQLITE_BUSY }
+do_catchsql_test 4.2 {
+  INSERT INTO t1 VALUES(8)
+} {1 {database is locked}}
+
+proc my_wal_hook {args} { return 14 ;# SQLITE_CANTOPEN }
+do_catchsql_test 4.3 {
+  INSERT INTO t1 VALUES(9)
+} {1 {unable to open database file}}
+
+do_execsql_test 4.4 {
+  SELECT * FROM t1
+} {1 2 3 4 5 6 7 8 9}
+
+# EVIDENCE-OF: R-10466-53920 Calling sqlite3_wal_hook() replaces any
+# previously registered write-ahead log callback.
+set ::old_wal_hook 0
+proc my_old_wal_hook {args} {
+  incr ::old_wal_hook 
+  return 0
+}
+db wal_hook my_old_wal_hook
+do_test 5.1 {
+  execsql { INSERT INTO t1 VALUES(10) }
+  set ::old_wal_hook
+} {1}
+
+# Replace old_wal_hook. Observe that it is not invoked after it has 
+# been replaced.
+proc my_new_wal_hook {args} { return 0 }
+db wal_hook my_new_wal_hook
+do_test 5.2 {
+  execsql { INSERT INTO t1 VALUES(11) }
+  set ::old_wal_hook
+} {1}
+
+
+
+# EVIDENCE-OF: R-42842-27162 Note that the sqlite3_wal_autocheckpoint()
+# interface and the wal_autocheckpoint pragma both invoke
+# sqlite3_wal_hook() and will those overwrite any prior
+# sqlite3_wal_hook() settings.
+#
+set ::old_wal_hook 0
+proc my_old_wal_hook {args} { incr ::old_wal_hook ; return 0 }
+do_test 6.1.1 {
+  execsql { INSERT INTO t1 VALUES(12) }
+  set ::old_wal_hook
+} {1}
+do_test 6.1.2 {
+  execsql { PRAGA wal_autocheckpoint = 1000 }
+  execsql { INSERT INTO t1 VALUES(12) }
+  set ::old_wal_hook
+} {1}
+
+# EVIDENCE-OF: R-52629-38967 The first parameter passed to the callback
+# function when it is invoked is a copy of the third parameter passed to
+# sqlite3_wal_hook() when registering the callback.
+#
+#    This is tricky to test using the tcl interface. However, the
+#    mechanism used to invoke the tcl script registered as a wal-hook
+#    depends on the context pointer being correctly passed through. And
+#    since multiple different wal-hook scripts have been successfully
+#    invoked by this test script, consider this tested.
+#
+# EVIDENCE-OF: R-23378-42536 The second is a copy of the database
+# handle.
+#
+#    There is an assert() in the C wal-hook used by tclsqlite.c to
+#    prove this. And that hook has been invoked multiple times when
+#    running this script. So consider this requirement tested as well.
+#
+
+finish_test