Skip to content

Commit 2ea5857

Browse files
committed
Closes #597
1 parent e24345b commit 2ea5857

8 files changed

+623
-9
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ script:
2727
- $HOME/gopath/bin/goveralls -repotoken 3qJVUE0iQwqnCbmNcDsjYu1nh4J4KIFXx
2828
- go test -race -v . -tags ""
2929
- go test -race -v . -tags "libsqlite3"
30-
- go test -race -v . -tags "sqlite_allow_uri_authority sqlite_app_armor sqlite_foreign_keys sqlite_fts5 sqlite_icu sqlite_introspect sqlite_json sqlite_secure_delete sqlite_see sqlite_stat4 sqlite_trace sqlite_userauth sqlite_vacuum_incr sqlite_vtable sqlite_unlock_notify"
31-
- go test -race -v . -tags "sqlite_vacuum_full"
30+
- go test -race -v . -tags "sqlite_allow_uri_authority sqlite_app_armor sqlite_foreign_keys sqlite_fts5 sqlite_icu sqlite_introspect sqlite_json sqlite_preupdate_hook sqlite_secure_delete sqlite_see sqlite_stat4 sqlite_trace sqlite_userauth sqlite_vacuum_incr sqlite_vtable sqlite_unlock_notify"
31+
- go test -race -v . -tags "sqlite_vacuum_full"

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,21 @@ Supported Golang version: See .travis.yml
1616

1717
### Overview
1818

19+
- [go-sqlite3](#go-sqlite3)
20+
- [Description](#description)
21+
- [Overview](#overview)
1922
- [Installation](#installation)
2023
- [API Reference](#api-reference)
2124
- [Connection String](#connection-string)
25+
- [DSN Examples](#dsn-examples)
2226
- [Features](#features)
27+
- [Usage](#usage)
28+
- [Feature / Extension List](#feature--extension-list)
2329
- [Compilation](#compilation)
2430
- [Android](#android)
25-
- [ARM](#arm)
26-
- [Cross Compile](#cross-compile)
27-
- [Google Cloud Platform](#google-cloud-platform)
31+
- [ARM](#arm)
32+
- [Cross Compile](#cross-compile)
33+
- [Google Cloud Platform](#google-cloud-platform)
2834
- [Linux](#linux)
2935
- [Alpine](#alpine)
3036
- [Fedora](#fedora)
@@ -34,11 +40,22 @@ Supported Golang version: See .travis.yml
3440
- [Errors](#errors)
3541
- [User Authentication](#user-authentication)
3642
- [Compile](#compile)
37-
- [Usage](#usage)
43+
- [Usage](#usage-1)
44+
- [Create protected database](#create-protected-database)
45+
- [Password Encoding](#password-encoding)
46+
- [Available Encoders](#available-encoders)
47+
- [Restrictions](#restrictions)
48+
- [Support](#support)
49+
- [User Management](#user-management)
50+
- [SQL](#sql)
51+
- [Examples](#examples)
52+
- [*SQLiteConn](#sqliteconn)
53+
- [Attached database](#attached-database)
3854
- [Extensions](#extensions)
3955
- [Spatialite](#spatialite)
4056
- [FAQ](#faq)
4157
- [License](#license)
58+
- [Author](#author)
4259

4360
# Installation
4461

@@ -149,6 +166,7 @@ go build --tags "icu json1 fts5 secure_delete"
149166
| International Components for Unicode | sqlite_icu | This option causes the International Components for Unicode or "ICU" extension to SQLite to be added to the build |
150167
| Introspect PRAGMAS | sqlite_introspect | This option adds some extra PRAGMA statements. <ul><li>PRAGMA function_list</li><li>PRAGMA module_list</li><li>PRAGMA pragma_list</li></ul> |
151168
| JSON SQL Functions | sqlite_json | When this option is defined in the amalgamation, the JSON SQL functions are added to the build automatically |
169+
| Pre Update Hook | sqlite_preupdate_hook | Registers a callback function that is invoked prior to each INSERT, UPDATE, and DELETE operation on a database table. |
152170
| Secure Delete | sqlite_secure_delete | This compile-time option changes the default setting of the secure_delete pragma.<br><br>When this option is not used, secure_delete defaults to off. When this option is present, secure_delete defaults to on.<br><br>The secure_delete setting causes deleted content to be overwritten with zeros. There is a small performance penalty since additional I/O must occur.<br><br>On the other hand, secure_delete can prevent fragments of sensitive information from lingering in unused parts of the database file after it has been deleted. See the documentation on the secure_delete pragma for additional information |
153171
| Secure Delete (FAST) | sqlite_secure_delete_fast | For more information see [PRAGMA secure_delete](https://www.sqlite.org/pragma.html#pragma_secure_delete) |
154172
| Tracing / Debug | sqlite_trace | Activate trace functions |

callback.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,22 @@ func authorizerTrampoline(handle uintptr, op int, arg1 *C.char, arg2 *C.char, ar
8383
return callback(op, C.GoString(arg1), C.GoString(arg2), C.GoString(arg3))
8484
}
8585

86-
// Use handles to avoid passing Go pointers to C.
86+
//export preUpdateHookTrampoline
87+
func preUpdateHookTrampoline(handle uintptr, dbHandle uintptr, op int, db *C.char, table *C.char, oldrowid int64, newrowid int64) {
88+
hval := lookupHandleVal(handle)
89+
data := SQLitePreUpdateData{
90+
Conn: hval.db,
91+
Op: op,
92+
DatabaseName: C.GoString(db),
93+
TableName: C.GoString(table),
94+
OldRowID: oldrowid,
95+
NewRowID: newrowid,
96+
}
97+
callback := hval.val.(func(SQLitePreUpdateData))
98+
callback(data)
99+
}
87100

101+
// Use handles to avoid passing Go pointers to C.
88102
type handleVal struct {
89103
db *SQLiteConn
90104
val interface{}
@@ -103,7 +117,7 @@ func newHandle(db *SQLiteConn, v interface{}) uintptr {
103117
return i
104118
}
105119

106-
func lookupHandle(handle uintptr) interface{} {
120+
func lookupHandleVal(handle uintptr) handleVal {
107121
handleLock.Lock()
108122
defer handleLock.Unlock()
109123
r, ok := handleVals[handle]
@@ -114,7 +128,11 @@ func lookupHandle(handle uintptr) interface{} {
114128
panic("invalid handle")
115129
}
116130
}
117-
return r.val
131+
return r
132+
}
133+
134+
func lookupHandle(handle uintptr) interface{} {
135+
return lookupHandleVal(handle).val
118136
}
119137

120138
func deleteHandles(db *SQLiteConn) {

0 commit comments

Comments
 (0)