diff --git a/.travis.yml b/.travis.yml index 46e70cb0..a919d61e 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 4870adfe..59982c80 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 2edeb2fb..58ef4d8f 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -789,6 +789,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. // _mutex=XXX // Specify mutex mode. XXX can be "no", "full". func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { @@ -801,6 +803,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { busyTimeout := 5000 foreignKeys := -1 recursiveTriggers := -1 + cryptoKey := "" mutex := C.int(C.SQLITE_OPEN_FULLMUTEX) pos := strings.IndexRune(dsn, '?') if pos >= 1 { @@ -868,6 +871,9 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { } } + // _crypto_key + cryptoKey = params.Get("_crypto_key") + // _mutex if val := params.Get("_mutex"); val != "" { switch val { @@ -936,6 +942,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 {