xref: /netbsd-src/external/public-domain/sqlite/man/sqlite3_commit_hook.3 (revision b9988867a8ad969c45a52aa7628bc932ec98d46b)
1.Dd January 24, 2024
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.In sqlite3.h
10.Ft void *
11.Fo sqlite3_commit_hook
12.Fa "sqlite3*"
13.Fa "int(*)(void*)"
14.Fa "void*"
15.Fc
16.Ft void *
17.Fo sqlite3_rollback_hook
18.Fa "sqlite3*"
19.Fa "void(*)(void *)"
20.Fa "void*"
21.Fc
22.Sh DESCRIPTION
23The sqlite3_commit_hook() interface registers a callback function to
24be invoked whenever a transaction is committed.
25Any callback set by a previous call to sqlite3_commit_hook() for the
26same database connection is overridden.
27The sqlite3_rollback_hook() interface registers a callback function
28to be invoked whenever a transaction is rolled back.
29Any callback set by a previous call to sqlite3_rollback_hook() for
30the same database connection is overridden.
31The pArg argument is passed through to the callback.
32If the callback on a commit hook function returns non-zero, then the
33commit is converted into a rollback.
34.Pp
35The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
36return the P argument from the previous call of the same function on
37the same database connection D, or NULL for the
38first call for each function on D.
39.Pp
40The commit and rollback hook callbacks are not reentrant.
41The callback implementation must not do anything that will modify the
42database connection that invoked the callback.
43Any actions to modify the database connection must be deferred until
44after the completion of the
45.Fn sqlite3_step
46call that triggered the commit or rollback hook in the first place.
47Note that running any other SQL statements, including SELECT statements,
48or merely calling
49.Fn sqlite3_prepare_v2
50and
51.Fn sqlite3_step
52will modify the database connections for the meaning of "modify" in
53this paragraph.
54.Pp
55Registering a NULL function disables the callback.
56.Pp
57When the commit hook callback routine returns zero, the COMMIT
58operation is allowed to continue normally.
59If the commit hook returns non-zero, then the COMMIT is converted
60into a ROLLBACK.
61The rollback hook is invoked on a rollback that results from a commit
62hook returning non-zero, just as it would be with any other rollback.
63.Pp
64For the purposes of this API, a transaction is said to have been rolled
65back if an explicit "ROLLBACK" statement is executed, or an error or
66constraint causes an implicit rollback to occur.
67The rollback callback is not invoked if a transaction is automatically
68rolled back because the database connection is closed.
69.Pp
70See also the
71.Fn sqlite3_update_hook
72interface.
73.Sh IMPLEMENTATION NOTES
74These declarations were extracted from the
75interface documentation at line 6722.
76.Bd -literal
77SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
78SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
79.Ed
80.Sh SEE ALSO
81.Xr sqlite3 3 ,
82.Xr sqlite3_prepare 3 ,
83.Xr sqlite3_step 3 ,
84.Xr sqlite3_update_hook 3
85