Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ env:
- GOTAGS=trace
- GOTAGS=vtable
go:
- 1.7.x
- 1.8.x
- 1.9.x
- master
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
16 changes: 16 additions & 0 deletions sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down