Commit f857010b authored by gwenn's avatar gwenn

Wraps sqlite3_progress_handler.

parent 808b499d
......@@ -138,6 +138,7 @@ type Conn struct {
authorizer *sqliteAuthorizer
busyHandler *sqliteBusyHandler
profile *sqliteProfile
progressHandler *sqliteProgressHandler
trace *sqliteTrace
}
......
......@@ -20,6 +20,11 @@ func profile(d interface{}, sql string, nanoseconds uint64) {
fmt.Printf("%s: %s = %d\n", d, sql, nanoseconds/1000)
}
func progressHandler(d interface{}) int {
fmt.Print("+")
return 0
}
func open(t *testing.T) *Conn {
db, err := Open("", OPEN_READWRITE, OPEN_CREATE, OPEN_FULLMUTEX, OPEN_URI)
if err != nil {
......@@ -36,6 +41,7 @@ func open(t *testing.T) *Conn {
}
*/
//db.Profile(profile, "PROFILE")
//db.ProgressHandler(progressHandler, 20, nil)
return db
}
......
......@@ -32,6 +32,12 @@ extern int goXBusy(void *pArg, int n);
static int goSqlite3BusyHandler(sqlite3 *db, void *pArg) {
return sqlite3_busy_handler(db, goXBusy, pArg);
}
extern int goXProgress(void *pArg);
static void goSqlite3ProgressHandler(sqlite3 *db, int freq, void *pArg) {
sqlite3_progress_handler(db, freq, goXProgress, pArg);
}
*/
import "C"
......@@ -186,3 +192,30 @@ func (c *Conn) BusyHandler(f BusyHandler, arg interface{}) os.Error {
c.busyHandler = &sqliteBusyHandler{f, arg}
return c.error(C.goSqlite3BusyHandler(c.db, unsafe.Pointer(c.busyHandler)))
}
// Returns non-zero to interrupt.
type ProgressHandler func(d interface{}) int
type sqliteProgressHandler struct {
f ProgressHandler
d interface{}
}
//export goXProgress
func goXProgress(pArg unsafe.Pointer) C.int {
arg := (*sqliteProgressHandler)(pArg)
result := arg.f(arg.d)
return C.int(result)
}
// Calls http://sqlite.org/c3ref/progress_handler.html
func (c *Conn) ProgressHandler(f ProgressHandler, freq int, arg interface{}) {
if f == nil {
c.progressHandler = nil
C.sqlite3_progress_handler(c.db, 0, nil, nil)
return
}
// To make sure it is not gced, keep a reference in the connection.
c.progressHandler = &sqliteProgressHandler{f, arg}
C.goSqlite3ProgressHandler(c.db, C.int(freq), unsafe.Pointer(c.progressHandler))
}
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