Skip to content
Open
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
34 changes: 34 additions & 0 deletions sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,8 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
writableSchema := -1
vfsName := ""
var cacheSize *int64
encryptionKey := ""
cipherPageSize := -1

pos := strings.IndexRune(dsn, '?')
if pos >= 1 {
Expand Down Expand Up @@ -1196,6 +1198,19 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
return nil, fmt.Errorf("Invalid _auto_vacuum: %v, expecting value of '0 NONE 1 FULL 2 INCREMENTAL'", val)
}
}
// _pragma_key
if val := params.Get("_pragma_key"); val != "" {
encryptionKey = val
}

// _pragma_cipher_page_size
if val := params.Get("_pragma_cipher_page_size"); val != "" {
pageSize, err := strconv.Atoi(val)
if err != nil {
return nil, fmt.Errorf("sqlite3: _pragma_cipher_page_size cannot be parsed: %s", err)
}
cipherPageSize = pageSize
}

// Busy Timeout (_busy_timeout)
//
Expand Down Expand Up @@ -1492,6 +1507,25 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
C.sqlite3_close_v2(db)
return nil, err
}

// _pragma_key
if encryptionKey != "" {
query := fmt.Sprintf("PRAGMA key = \"%s\";", pragmaKey)
if err := exec(query); err != nil {
C.sqlite3_close_v2(db)
return nil, err
}
}

// _pragma_cipher_page_size
if cipherPageSize != -1 {
query := fmt.Sprintf("PRAGMA cipher_page_size = %d;",
pragmaCipherPageSize)
if err := exec(query); err != nil {
C.sqlite3_close_v2(db)
return nil, err
}
}

// USER AUTHENTICATION
//
Expand Down