Skip to content

Commit 7c9aedc

Browse files
committed
add support SEE
1 parent ed69081 commit 7c9aedc

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ env:
77
- GOTAGS=trace
88
- GOTAGS=vtable
99
go:
10-
- 1.7.x
1110
- 1.8.x
1211
- 1.9.x
1312
- master

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ FAQ
4646

4747
Use `go build --tags "icu"`
4848

49-
Available extensions: `json1`, `fts5`, `icu`
49+
Available extensions: `json1`, `fts5`, `icu`, `see`
5050

5151
* Can't build go-sqlite3 on windows 64bit.
5252

sqlite3.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,8 @@ func errorString(err Error) string {
781781
// Enable or disable enforcement of foreign keys. X can be 1 or 0.
782782
// _recursive_triggers=X
783783
// Enable or disable recursive triggers. X can be 1 or 0.
784+
// _crypto_key=XXX
785+
// Specify symmetric crypto key for use by SEE. X must be text key without quotes.
784786
func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
785787
if C.sqlite3_threadsafe() == 0 {
786788
return nil, errors.New("sqlite library was not compiled for thread-safe operation")
@@ -791,6 +793,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
791793
busyTimeout := 5000
792794
foreignKeys := -1
793795
recursiveTriggers := -1
796+
cryptoKey := ""
794797
pos := strings.IndexRune(dsn, '?')
795798
if pos >= 1 {
796799
params, err := url.ParseQuery(dsn[pos+1:])
@@ -857,6 +860,9 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
857860
}
858861
}
859862

863+
// _crypto_key
864+
cryptoKey = params.Get("_crypto_key")
865+
860866
if !strings.HasPrefix(dsn, "file:") {
861867
dsn = dsn[:pos]
862868
}
@@ -915,6 +921,16 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
915921
}
916922
}
917923

924+
// crypto key must be specified BEFORE any other action
925+
// and works only with SEE version of Sqlite3
926+
if cryptoKey != "" {
927+
tmp := fmt.Sprintf("PRAGMA key = '%s'", strings.Replace(cryptoKey, "'", "''", -1))
928+
if err := exec(tmp); err != nil {
929+
C.sqlite3_close_v2(db)
930+
return nil, err
931+
}
932+
}
933+
918934
conn := &SQLiteConn{db: db, loc: loc, txlock: txlock}
919935

920936
if len(d.Extensions) > 0 {

0 commit comments

Comments
 (0)