@@ -100,6 +100,9 @@ int _sqlite3_create_function(
100
100
}
101
101
102
102
void callbackTrampoline(sqlite3_context*, int, sqlite3_value**);
103
+ int commitHookTrampoline(void*);
104
+ void rollbackHookTrampoline(void*);
105
+ void updateHookTrampoline(void*, int, char*, char*, sqlite3_int64);
103
106
*/
104
107
import "C"
105
108
import (
@@ -150,6 +153,12 @@ func Version() (libVersion string, libVersionNumber int, sourceID string) {
150
153
return libVersion , libVersionNumber , sourceID
151
154
}
152
155
156
+ const (
157
+ SQLITE_DELETE = C .SQLITE_DELETE
158
+ SQLITE_INSERT = C .SQLITE_INSERT
159
+ SQLITE_UPDATE = C .SQLITE_UPDATE
160
+ )
161
+
153
162
// SQLiteDriver implement sql.Driver.
154
163
type SQLiteDriver struct {
155
164
Extensions []string
@@ -315,6 +324,51 @@ func (tx *SQLiteTx) Rollback() error {
315
324
return err
316
325
}
317
326
327
+ // RegisterCommitHook sets the commit hook for a connection.
328
+ //
329
+ // If the callback returns non-zero the transaction will become a rollback.
330
+ //
331
+ // If there is an existing commit hook for this connection, it will be
332
+ // removed. If callback is nil the existing hook (if any) will be removed
333
+ // without creating a new one.
334
+ func (c * SQLiteConn ) RegisterCommitHook (callback func () int ) {
335
+ if callback == nil {
336
+ C .sqlite3_commit_hook (c .db , nil , nil )
337
+ } else {
338
+ C .sqlite3_commit_hook (c .db , (* [0 ]byte )(unsafe .Pointer (C .commitHookTrampoline )), unsafe .Pointer (newHandle (c , callback )))
339
+ }
340
+ }
341
+
342
+ // RegisterRollbackHook sets the rollback hook for a connection.
343
+ //
344
+ // If there is an existing rollback hook for this connection, it will be
345
+ // removed. If callback is nil the existing hook (if any) will be removed
346
+ // without creating a new one.
347
+ func (c * SQLiteConn ) RegisterRollbackHook (callback func ()) {
348
+ if callback == nil {
349
+ C .sqlite3_rollback_hook (c .db , nil , nil )
350
+ } else {
351
+ C .sqlite3_rollback_hook (c .db , (* [0 ]byte )(unsafe .Pointer (C .rollbackHookTrampoline )), unsafe .Pointer (newHandle (c , callback )))
352
+ }
353
+ }
354
+
355
+ // RegisterUpdateHook sets the update hook for a connection.
356
+ //
357
+ // The parameters to the callback are the operation (one of the constants
358
+ // SQLITE_INSERT, SQLITE_DELETE, or SQLITE_UPDATE), the database name, the
359
+ // table name, and the rowid.
360
+ //
361
+ // If there is an existing update hook for this connection, it will be
362
+ // removed. If callback is nil the existing hook (if any) will be removed
363
+ // without creating a new one.
364
+ func (c * SQLiteConn ) RegisterUpdateHook (callback func (int , string , string , int64 )) {
365
+ if callback == nil {
366
+ C .sqlite3_update_hook (c .db , nil , nil )
367
+ } else {
368
+ C .sqlite3_update_hook (c .db , (* [0 ]byte )(unsafe .Pointer (C .updateHookTrampoline )), unsafe .Pointer (newHandle (c , callback )))
369
+ }
370
+ }
371
+
318
372
// RegisterFunc makes a Go function available as a SQLite function.
319
373
//
320
374
// The Go function can have arguments of the following types: any
0 commit comments