xref: /netbsd-src/external/public-domain/sqlite/man/sqlite3_commit_hook.3 (revision deb6f0161a9109e7de9b519dc8dfb9478668dcdd)
1.Dd March 11, 2017
2.Dt SQLITE3_COMMIT_HOOK 3
3.Os
4.Sh NAME
5.Nm sqlite3_commit_hook ,
6.Nm sqlite3_rollback_hook
7.Nd Commit And Rollback Notification Callbacks
8.Sh SYNOPSIS
9.Ft void *
10.Fo sqlite3_commit_hook
11.Fa "sqlite3*"
12.Fa "int(*)(void*)"
13.Fa "void*"
14.Fc
15.Ft void *
16.Fo sqlite3_rollback_hook
17.Fa "sqlite3*"
18.Fa "void(*)(void *)"
19.Fa "void*"
20.Fc
21.Sh DESCRIPTION
22The sqlite3_commit_hook() interface registers a callback function to
23be invoked whenever a transaction is  committed.
24Any callback set by a previous call to sqlite3_commit_hook() for the
25same database connection is overridden.
26The sqlite3_rollback_hook() interface registers a callback function
27to be invoked whenever a transaction is  rolled back.
28Any callback set by a previous call to sqlite3_rollback_hook() for
29the same database connection is overridden.
30The pArg argument is passed through to the callback.
31If the callback on a commit hook function returns non-zero, then the
32commit is converted into a rollback.
33.Pp
34The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
35return the P argument from the previous call of the same function on
36the same database connection D, or NULL for the
37first call for each function on D.
38.Pp
39The commit and rollback hook callbacks are not reentrant.
40The callback implementation must not do anything that will modify the
41database connection that invoked the callback.
42Any actions to modify the database connection must be deferred until
43after the completion of the sqlite3_step() call that
44triggered the commit or rollback hook in the first place.
45Note that running any other SQL statements, including SELECT statements,
46or merely calling sqlite3_prepare_v2() and sqlite3_step()
47will modify the database connections for the meaning of "modify" in
48this paragraph.
49.Pp
50Registering a NULL function disables the callback.
51.Pp
52When the commit hook callback routine returns zero, the COMMIT
53operation is allowed to continue normally.
54If the commit hook returns non-zero, then the COMMIT is converted
55into a ROLLBACK.
56The rollback hook is invoked on a rollback that results from a commit
57hook returning non-zero, just as it would be with any other rollback.
58.Pp
59For the purposes of this API, a transaction is said to have been rolled
60back if an explicit "ROLLBACK" statement is executed, or an error or
61constraint causes an implicit rollback to occur.
62The rollback callback is not invoked if a transaction is automatically
63rolled back because the database connection is closed.
64.Pp
65See also the sqlite3_update_hook() interface.
66.Sh SEE ALSO
67.Xr sqlite3 3 ,
68.Xr sqlite3_prepare 3 ,
69.Xr sqlite3_step 3 ,
70.Xr sqlite3_update_hook 3
71