Skip to content

Commit

Permalink
Merge pull request #10 from ValentinMontmirail/feature/latest-sql-fea…
Browse files Browse the repository at this point in the history
…tures-supported

Add `cipher_compatibility` support for SQLCipher
  • Loading branch information
ValentinMontmirail committed Dec 26, 2023
2 parents 76577e9 + 0788963 commit 62f3831
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions sqlite3.go
Expand Up @@ -1019,6 +1019,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {

// PRAGMA's
encryptKey := ""
cipher_compatibility := -1
autoVacuum := -1
busyTimeout := 5000
caseSensitiveLike := -1
Expand All @@ -1045,6 +1046,15 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
encryptKey = val
}

// _cipher_compatibility
if val := params.Get("_cipher_compatibility"); val != "" {
iv, err := strconv.ParseInt(val, 10, 64)
if err != nil {
return nil, fmt.Errorf("Invalid _cipher_compatibility: %v: %v", val, err)
}
cipher_compatibility = int(iv)
}

// Authentication
if _, ok := params["_auth"]; ok {
authCreate = true
Expand Down Expand Up @@ -1409,6 +1419,15 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
}
}

// Cipher Compatibility
// The cipher_compatibility pragma should be called immediately after if provided
if cipher_compatibility > -1 {
if err := exec(fmt.Sprintf("PRAGMA cipher_compatibility = %d;", cipher_compatibility)); err != nil {
C.sqlite3_close_v2(db)
return nil, err
}
}

// USER AUTHENTICATION
//
// User Authentication is always performed even when
Expand Down

0 comments on commit 62f3831

Please sign in to comment.