diff --git a/sqlite3.go b/sqlite3.go index 109a0cc..363a44a 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -1400,7 +1400,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { // Encrypt Keys // The key pragma should be always called first if encryptKey != "" { - if err := exec(fmt.Sprintf("PRAGMA key = %s;", encryptKey)); err != nil { + if err := exec(fmt.Sprintf(`PRAGMA key = "%s";`, encryptKey)); err != nil { C.sqlite3_close_v2(db) return nil, err } diff --git a/sqlite3_test.go b/sqlite3_test.go index b184fc4..708b396 100644 --- a/sqlite3_test.go +++ b/sqlite3_test.go @@ -1207,7 +1207,7 @@ func TestEncryptoDatabase(t *testing.T) { defer os.Remove(tempFilename) defer db.Close() - _, err = db.Exec("PRAGMA key = 'password';") + _, err = db.Exec(`PRAGMA key = "x'123ABC'";`) if err != nil { t.Error("Failed to set encrypto key") } @@ -1239,7 +1239,7 @@ func TestEncryptoDatabase(t *testing.T) { t.Error("Failed to db.QueryRow: not matched results") } db.Close() - db, err = sql.Open("sqlite3", tempFilename+"?_key=not_password") + db, err = sql.Open("sqlite3", tempFilename+"?_key=x'123000'") if err != nil { t.Fatal("Failed to open database:", err) } @@ -1249,7 +1249,7 @@ func TestEncryptoDatabase(t *testing.T) { t.Error("Failed to encrypto database") } db.Close() - db, err = sql.Open("sqlite3", tempFilename+"?_key=password") + db, err = sql.Open("sqlite3", tempFilename+"?_key=x'123ABC'") if err != nil { t.Fatal("Failed to open database:", err) }