diff --git a/.travis.yml b/.travis.yml index 46e70cb..a919d61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ env: - GOTAGS=trace - GOTAGS=vtable go: - - 1.7.x - 1.8.x - 1.9.x - master diff --git a/README.md b/README.md index ad00f10..73d05a8 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ FAQ Use `go build --tags "icu"` - Available extensions: `json1`, `fts5`, `icu` + Available extensions: `json1`, `fts5`, `icu`, `see` * Can't build go-sqlite3 on windows 64bit. diff --git a/sqlite3.go b/sqlite3.go index a931735..e3bd334 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -781,6 +781,8 @@ func errorString(err Error) string { // Enable or disable enforcement of foreign keys. X can be 1 or 0. // _recursive_triggers=X // 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) { if C.sqlite3_threadsafe() == 0 { 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 foreignKeys := -1 recursiveTriggers := -1 + cryptoKey := "" pos := strings.IndexRune(dsn, '?') if 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:") { 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} if len(d.Extensions) > 0 {