mirror of https://github.com/mattn/go-sqlite3.git
add support SEE
This commit is contained in:
parent
ed69081a91
commit
7c9aedc574
|
@ -7,7 +7,6 @@ env:
|
|||
- GOTAGS=trace
|
||||
- GOTAGS=vtable
|
||||
go:
|
||||
- 1.7.x
|
||||
- 1.8.x
|
||||
- 1.9.x
|
||||
- master
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
16
sqlite3.go
16
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 {
|
||||
|
|
Loading…
Reference in New Issue