xref: /netbsd-src/external/public-domain/sqlite/man/sqlite3_wal_hook.3 (revision a24efa7dea9f1f56c3bdb15a927d3516792ace1c)
1.Dd $Mdocdate$
2.Dt SQLITE3_WAL_HOOK 3
3.Os
4.Sh NAME
5.Nm sqlite3_wal_hook
6.Nd Write-Ahead Log Commit Hook
7.Sh SYNOPSIS
8.Ft void *
9.Fo sqlite3_wal_hook
10.Fa "sqlite3*"
11.Fa "int(*)(void *,sqlite3*,const char*,int)"
12.Fa "void* "
13.Fc
14.Sh DESCRIPTION
15The sqlite3_wal_hook() function is used to register
16a callback that will be invoked each time a database connection commits
17data to a write-ahead log (i.e.
18whenever a transaction is committed in  journal_mode=WAL mode).
19.Pp
20The callback is invoked by SQLite after the commit has taken place
21and the associated write-lock on the database released, so the implementation
22may read, write or checkpoint the database as required.
23.Pp
24The first parameter passed to the callback function when it is invoked
25is a copy of the third parameter passed to sqlite3_wal_hook() when
26registering the callback.
27The second is a copy of the database handle.
28The third parameter is the name of the database that was written to
29- either "main" or the name of an ATTACH-ed database.
30The fourth parameter is the number of pages currently in the write-ahead
31log file, including those that were just committed.
32.Pp
33The callback function should normally return SQLITE_OK.
34If an error code is returned, that error will propagate back up through
35the SQLite code base to cause the statement that provoked the callback
36to report an error, though the commit will have still occurred.
37If the callback returns SQLITE_ROW or SQLITE_DONE,
38or if it returns a value that does not correspond to any valid SQLite
39error code, the results are undefined.
40.Pp
41A single database handle may have at most a single write-ahead log
42callback registered at one time.
43Calling sqlite3_wal_hook() replaces any previously
44registered write-ahead log callback.
45Note that the sqlite3_wal_autocheckpoint()
46interface and the wal_autocheckpoint pragma
47both invoke sqlite3_wal_hook() and will those overwrite
48any prior sqlite3_wal_hook() settings.
49.Sh SEE ALSO
50.Xr sqlite3_wal_autocheckpoint 3 ,
51.Xr sqlite3_wal_hook 3 ,
52.Xr SQLITE_OK 3
53