Commit a09c1c19 authored by gwenn's avatar gwenn

Add binding to sqlite3_config(SQLITE_CONFIG_MEMSTATUS|SQLITE_CONFIG_URI).

parent 5a25a02d
...@@ -48,4 +48,8 @@ int goSqlite3ConfigLog(void *udp) { ...@@ -48,4 +48,8 @@ int goSqlite3ConfigLog(void *udp) {
int goSqlite3ConfigThreadMode(int mode) { int goSqlite3ConfigThreadMode(int mode) {
return sqlite3_config(mode); return sqlite3_config(mode);
}
int goSqlite3Config(int op, int mode) {
return sqlite3_config(op, mode);
} }
\ No newline at end of file
...@@ -21,6 +21,7 @@ static void my_log(int iErrCode, char *msg) { ...@@ -21,6 +21,7 @@ static void my_log(int iErrCode, char *msg) {
int goSqlite3ConfigLog(void *udp); int goSqlite3ConfigLog(void *udp);
int goSqlite3ConfigThreadMode(int mode); int goSqlite3ConfigThreadMode(int mode);
int goSqlite3Config(int op, int mode);
*/ */
import "C" import "C"
...@@ -303,19 +304,40 @@ func ConfigLog(f Logger, udp interface{}) error { ...@@ -303,19 +304,40 @@ func ConfigLog(f Logger, udp interface{}) error {
return Errno(rv) return Errno(rv)
} }
type ThreadMode int type ThreadingMode int
const ( const (
SINGLETHREAD ThreadMode = C.SQLITE_CONFIG_SINGLETHREAD SINGLETHREAD ThreadingMode = C.SQLITE_CONFIG_SINGLETHREAD
MULTITHREAD ThreadMode = C.SQLITE_CONFIG_MULTITHREAD MULTITHREAD ThreadingMode = C.SQLITE_CONFIG_MULTITHREAD
SERIALIZED ThreadMode = C.SQLITE_CONFIG_SERIALIZED SERIALIZED ThreadingMode = C.SQLITE_CONFIG_SERIALIZED
) )
// Alters threading mode
// (See sqlite3_config(SQLITE_CONFIG_SINGLETHREAD|SQLITE_CONFIG_MULTITHREAD|SQLITE_CONFIG_SERIALIZED): http://sqlite.org/c3ref/config.html) // (See sqlite3_config(SQLITE_CONFIG_SINGLETHREAD|SQLITE_CONFIG_MULTITHREAD|SQLITE_CONFIG_SERIALIZED): http://sqlite.org/c3ref/config.html)
func ConfigThreadMode(mode ThreadMode) error { func ConfigThreadingMode(mode ThreadingMode) error {
rv := C.goSqlite3ConfigThreadMode(C.int(mode)) rv := C.goSqlite3ConfigThreadMode(C.int(mode))
if rv == C.SQLITE_OK { if rv == C.SQLITE_OK {
return nil return nil
} }
return Errno(rv) return Errno(rv)
} }
// Enables or disables the collection of memory allocation statistics
// (See sqlite3_config(SQLITE_CONFIG_MEMSTATUS): http://sqlite.org/c3ref/config.html)
func ConfigMemStatus(b bool) error {
rv := C.goSqlite3Config(C.SQLITE_CONFIG_MEMSTATUS, btocint(b))
if rv == C.SQLITE_OK {
return nil
}
return Errno(rv)
}
// Enables or disables URI handling
// (See sqlite3_config(SQLITE_CONFIG_URI): http://sqlite.org/c3ref/config.html)
func ConfigUri(b bool) error {
rv := C.goSqlite3Config(C.SQLITE_CONFIG_URI, btocint(b))
if rv == C.SQLITE_OK {
return nil
}
return Errno(rv)
}
...@@ -11,9 +11,13 @@ import ( ...@@ -11,9 +11,13 @@ import (
) )
func init() { func init() {
err := ConfigThreadMode(SERIALIZED) err := ConfigThreadingMode(SERIALIZED)
if err != nil { if err != nil {
panic(fmt.Sprintf("cannot change thread mode: '%s'", err)) panic(fmt.Sprintf("cannot change threading mode: '%s'", err))
}
err = ConfigMemStatus(true)
if err != nil {
panic(fmt.Sprintf("cannot activate mem status: '%s'", err))
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment