mirror of https://github.com/mattn/go-sqlite3.git
SQLITE_OPEN_CREATE should be specified for sqlite3_open_v2 if mode is not rw
Fixes #667 Fixes #669
This commit is contained in:
parent
e924752105
commit
03b96a53ba
22
sqlite3.go
22
sqlite3.go
|
@ -990,7 +990,6 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
|
|||
authPass := ""
|
||||
authCrypt := ""
|
||||
authSalt := ""
|
||||
mutex := C.int(C.SQLITE_OPEN_FULLMUTEX)
|
||||
txlock := "BEGIN"
|
||||
|
||||
// PRAGMA's
|
||||
|
@ -1007,6 +1006,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
|
|||
secureDelete := "DEFAULT"
|
||||
synchronousMode := "NORMAL"
|
||||
writableSchema := -1
|
||||
flags := C.SQLITE_OPEN_READWRITE | C.SQLITE_OPEN_CREATE | C.SQLITE_OPEN_FULLMUTEX
|
||||
|
||||
pos := strings.IndexRune(dsn, '?')
|
||||
if pos >= 1 {
|
||||
|
@ -1015,6 +1015,17 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if val := params.Get("mode"); val != "" {
|
||||
switch val {
|
||||
case "ro":
|
||||
flags |= C.SQLITE_OPEN_READONLY
|
||||
case "rw":
|
||||
flags ^= C.SQLITE_OPEN_CREATE
|
||||
case "rwc":
|
||||
flags |= C.SQLITE_OPEN_CREATE
|
||||
}
|
||||
}
|
||||
|
||||
// Authentication
|
||||
if _, ok := params["_auth"]; ok {
|
||||
authCreate = true
|
||||
|
@ -1049,9 +1060,9 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
|
|||
if val := params.Get("_mutex"); val != "" {
|
||||
switch strings.ToLower(val) {
|
||||
case "no":
|
||||
mutex = C.SQLITE_OPEN_NOMUTEX
|
||||
flags |= C.SQLITE_OPEN_NOMUTEX
|
||||
case "full":
|
||||
mutex = C.SQLITE_OPEN_FULLMUTEX
|
||||
flags |= C.SQLITE_OPEN_FULLMUTEX
|
||||
default:
|
||||
return nil, fmt.Errorf("Invalid _mutex: %v", val)
|
||||
}
|
||||
|
@ -1338,9 +1349,8 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
|
|||
var db *C.sqlite3
|
||||
name := C.CString(dsn)
|
||||
defer C.free(unsafe.Pointer(name))
|
||||
rv := C._sqlite3_open_v2(name, &db,
|
||||
mutex|C.SQLITE_OPEN_READWRITE|C.SQLITE_OPEN_CREATE,
|
||||
nil)
|
||||
|
||||
rv := C._sqlite3_open_v2(name, &db, C.int(flags), nil)
|
||||
if rv != 0 {
|
||||
if db != nil {
|
||||
C.sqlite3_close_v2(db)
|
||||
|
|
Loading…
Reference in New Issue