1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
== `sqlite/hooks.hpp`
WARNING: This API might be subject change, if a better solution for ownership is found.
=== `commit_hook` & `rollback_commit`
The https://www.sqlite.org/c3ref/commit_hook.html[commit hook]
gets called before a commit gets performed.
Likewise the rollback hook gets invoked before a rollback.
If `func` returns true, the commit goes, otherwise it gets rolled back.
NOTE: If the function is not a free function pointer, this function will *NOT* take ownership.
NOTE: If `func` is a `nullptr` the hook gets reset.
[source,cpp]
----
template<typename Func>
bool commit_hook(connection & conn, Func && func);
template<typename Func>
bool rollback_hook(connection & conn, Func && func);
----
return:: `true` if a hook has been replaced.
conn:: The database connection to install the hook in
func:: The hook function. It must be callable without any parameter, return a `bool` and be `noexcept`.
=== `update_hook`
The https://www.sqlite.org/c3ref/update_hook.html[update hook]
The update hook gets called when an update was performed.
NOTE: If the function is not a free function pointer, this function will *NOT* take ownership.
NOTE: If `func` is a `nullptr` the hook gets reset.
[source,cpp]
----
template<typename Func>
bool update_hook(connection & conn, Func && func);
----
return:: `true` if a hook has been replaced.
conn:: The database connection to install the hook in
func:: The signature of the function is `void(int op, core::string_view db, core::string_view table, sqlite3_int64 id)`.
`op` is either `SQLITE_INSERT`, `SQLITE_DELETE` and `SQLITE_UPDATE`. The function must be noexcept.
=== `preupdate_hook`
NOTE: The https://www.sqlite.org/c3ref/preupdate_blobwrite.html[preupdate hook] requires
sqlite to be required with `SQLITE_ENABLE_PREUPDATE_HOOK` true.
This hook gets called before an update.
[source,cpp]
----
struct preupdate_context
{
// Returns the old value, i.e. the value before the update.
system::result<value> old(int column) const;
// The count of colums to be updated
int count() const;
// The nesting depth of the update.
int depth() const;
// The new value to be written to column
system::result<value> new_(int column) const;
// Query the status of blob access, e.g. when using blob_handle <1>
int blob_write() const;
explicit preupdate_context(sqlite3 * db) noexcept;
};
template<typename Func>
bool preupdate_hook(connection & conn, Func && func);
----
<1> See https://www.sqlite.org/c3ref/preupdate_blobwrite.html[sqlite/preupdate_blobwrite]
return:: `true` if a hook has been replaced.
conn:: The database connection to install the hook in
func:: The signature of the function is below:
[source,cpp]
----
void preupdate_hook(sqlite::preupdate_context ctx,
int op,
const char * db_name,
const char * table_name,
sqlite3_int64 current_key,
sqlite3_int64 new_key);
----
|