From 6455f6117979f954d4b44849892d5240013f8309 Mon Sep 17 00:00:00 2001 From: Ian Chiles Date: Wed, 13 Sep 2017 11:59:37 -0500 Subject: [PATCH] allow NOMUTEX|READONLY --- sqlite3.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/sqlite3.go b/sqlite3.go index 1ff58c3..234582c 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -712,11 +712,17 @@ 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, - C.SQLITE_OPEN_FULLMUTEX| - C.SQLITE_OPEN_READWRITE| - C.SQLITE_OPEN_CREATE, - nil) + var rv C.int + if strings.Contains(dsn, "immutable") { + rv = C._sqlite3_open_v2(name, &db, C.SQLITE_OPEN_NOMUTEX|C.SQLITE_OPEN_READONLY, nil) + } else { + rv = C._sqlite3_open_v2(name, &db, + C.SQLITE_OPEN_FULLMUTEX| + C.SQLITE_OPEN_READWRITE| + C.SQLITE_OPEN_CREATE, + nil) + } + if rv != 0 { return nil, Error{Code: ErrNo(rv)} }