fix trace callback.

Close #352
This commit is contained in:
Yasuhiro Matsumoto
2016-11-08 12:19:13 +09:00
parent 3e26a9df84
commit dd2c82226b
4 changed files with 97 additions and 31 deletions

View File

@@ -17,7 +17,7 @@ package sqlite3
void stepTrampoline(sqlite3_context*, int, sqlite3_value**);
void doneTrampoline(sqlite3_context*);
void traceCallbackTrampoline(unsigned traceEventCode, void *ctx, void *p, void *x);
int traceCallbackTrampoline(unsigned int traceEventCode, void *ctx, void *p, void *x);
*/
import "C"
@@ -76,7 +76,7 @@ type TraceUserCallback func(TraceInfo) int
type TraceConfig struct {
Callback TraceUserCallback
EventMask uint
EventMask C.uint
WantExpandedSQL bool
}
@@ -102,13 +102,13 @@ func fillExpandedSQL(info *TraceInfo, db *C.sqlite3, pStmt unsafe.Pointer) {
//export traceCallbackTrampoline
func traceCallbackTrampoline(
traceEventCode uint,
traceEventCode C.uint,
// Parameter named 'C' in SQLite docs = Context given at registration:
ctx unsafe.Pointer,
// Parameter named 'P' in SQLite docs (Primary event data?):
p unsafe.Pointer,
// Parameter named 'X' in SQLite docs (eXtra event data?):
xValue unsafe.Pointer) int {
xValue unsafe.Pointer) C.int {
if ctx == nil {
panic(fmt.Sprintf("No context (ev 0x%x)", traceEventCode))
@@ -196,7 +196,7 @@ func traceCallbackTrampoline(
if traceConf.Callback != nil {
r = traceConf.Callback(info)
}
return r
return C.int(r)
}
type traceMapEntry struct {
@@ -358,7 +358,7 @@ func (c *SQLiteConn) RegisterAggregator(name string, impl interface{}, pure bool
if pure {
opts |= C.SQLITE_DETERMINISTIC
}
rv := C._sqlite3_create_function(c.db, cname, C.int(stepNArgs), C.int(opts), C.uintptr_t(newHandle(c, &ai)), nil, (*[0]byte)(unsafe.Pointer(C.stepTrampoline)), (*[0]byte)(unsafe.Pointer(C.doneTrampoline)))
rv := sqlite3_create_function(c.db, cname, C.int(stepNArgs), C.int(opts), C.uintptr_t(newHandle(c, &ai)), nil, C.stepTrampoline, C.doneTrampoline)
if rv != C.SQLITE_OK {
return c.lastError()
}