add support SEE

This commit is contained in:
Yasuhiro Matsumoto 2017-11-15 09:18:20 +09:00
parent ed69081a91
commit 7c9aedc574
3 changed files with 17 additions and 2 deletions

View File

@ -7,7 +7,6 @@ env:
- GOTAGS=trace - GOTAGS=trace
- GOTAGS=vtable - GOTAGS=vtable
go: go:
- 1.7.x
- 1.8.x - 1.8.x
- 1.9.x - 1.9.x
- master - master

View File

@ -46,7 +46,7 @@ FAQ
Use `go build --tags "icu"` Use `go build --tags "icu"`
Available extensions: `json1`, `fts5`, `icu` Available extensions: `json1`, `fts5`, `icu`, `see`
* Can't build go-sqlite3 on windows 64bit. * Can't build go-sqlite3 on windows 64bit.

View File

@ -781,6 +781,8 @@ func errorString(err Error) string {
// Enable or disable enforcement of foreign keys. X can be 1 or 0. // Enable or disable enforcement of foreign keys. X can be 1 or 0.
// _recursive_triggers=X // _recursive_triggers=X
// Enable or disable recursive triggers. X can be 1 or 0. // Enable or disable recursive triggers. X can be 1 or 0.
// _crypto_key=XXX
// Specify symmetric crypto key for use by SEE. X must be text key without quotes.
func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
if C.sqlite3_threadsafe() == 0 { if C.sqlite3_threadsafe() == 0 {
return nil, errors.New("sqlite library was not compiled for thread-safe operation") 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) {
busyTimeout := 5000 busyTimeout := 5000
foreignKeys := -1 foreignKeys := -1
recursiveTriggers := -1 recursiveTriggers := -1
cryptoKey := ""
pos := strings.IndexRune(dsn, '?') pos := strings.IndexRune(dsn, '?')
if pos >= 1 { if pos >= 1 {
params, err := url.ParseQuery(dsn[pos+1:]) params, err := url.ParseQuery(dsn[pos+1:])
@ -857,6 +860,9 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
} }
} }
// _crypto_key
cryptoKey = params.Get("_crypto_key")
if !strings.HasPrefix(dsn, "file:") { if !strings.HasPrefix(dsn, "file:") {
dsn = dsn[:pos] dsn = dsn[:pos]
} }
@ -915,6 +921,16 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
} }
} }
// crypto key must be specified BEFORE any other action
// and works only with SEE version of Sqlite3
if cryptoKey != "" {
tmp := fmt.Sprintf("PRAGMA key = '%s'", strings.Replace(cryptoKey, "'", "''", -1))
if err := exec(tmp); err != nil {
C.sqlite3_close_v2(db)
return nil, err
}
}
conn := &SQLiteConn{db: db, loc: loc, txlock: txlock} conn := &SQLiteConn{db: db, loc: loc, txlock: txlock}
if len(d.Extensions) > 0 { if len(d.Extensions) > 0 {