parent
6c771bb988
commit
324c3f7deb
|
@ -95,7 +95,7 @@ func main() {
|
||||||
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
|
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
|
||||||
err := conn.SetTrace(&sqlite3.TraceConfig{
|
err := conn.SetTrace(&sqlite3.TraceConfig{
|
||||||
Callback: traceCallback,
|
Callback: traceCallback,
|
||||||
EventMask: uint(eventMask),
|
EventMask: eventMask,
|
||||||
WantExpandedSQL: true,
|
WantExpandedSQL: true,
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -28,10 +28,10 @@ import (
|
||||||
// Trace... constants identify the possible events causing callback invocation.
|
// Trace... constants identify the possible events causing callback invocation.
|
||||||
// Values are same as the corresponding SQLite Trace Event Codes.
|
// Values are same as the corresponding SQLite Trace Event Codes.
|
||||||
const (
|
const (
|
||||||
TraceStmt = C.SQLITE_TRACE_STMT
|
TraceStmt = uint32(C.SQLITE_TRACE_STMT)
|
||||||
TraceProfile = C.SQLITE_TRACE_PROFILE
|
TraceProfile = uint32(C.SQLITE_TRACE_PROFILE)
|
||||||
TraceRow = C.SQLITE_TRACE_ROW
|
TraceRow = uint32(C.SQLITE_TRACE_ROW)
|
||||||
TraceClose = C.SQLITE_TRACE_CLOSE
|
TraceClose = uint32(C.SQLITE_TRACE_CLOSE)
|
||||||
)
|
)
|
||||||
|
|
||||||
type TraceInfo struct {
|
type TraceInfo struct {
|
||||||
|
@ -71,7 +71,7 @@ type TraceUserCallback func(TraceInfo) int
|
||||||
|
|
||||||
type TraceConfig struct {
|
type TraceConfig struct {
|
||||||
Callback TraceUserCallback
|
Callback TraceUserCallback
|
||||||
EventMask C.uint
|
EventMask uint32
|
||||||
WantExpandedSQL bool
|
WantExpandedSQL bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +105,8 @@ func traceCallbackTrampoline(
|
||||||
// Parameter named 'X' in SQLite docs (eXtra event data?):
|
// Parameter named 'X' in SQLite docs (eXtra event data?):
|
||||||
xValue unsafe.Pointer) C.int {
|
xValue unsafe.Pointer) C.int {
|
||||||
|
|
||||||
|
eventCode := uint32(traceEventCode)
|
||||||
|
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
panic(fmt.Sprintf("No context (ev 0x%x)", traceEventCode))
|
panic(fmt.Sprintf("No context (ev 0x%x)", traceEventCode))
|
||||||
}
|
}
|
||||||
|
@ -114,7 +116,7 @@ func traceCallbackTrampoline(
|
||||||
|
|
||||||
var traceConf TraceConfig
|
var traceConf TraceConfig
|
||||||
var found bool
|
var found bool
|
||||||
if traceEventCode == TraceClose {
|
if eventCode == TraceClose {
|
||||||
// clean up traceMap: 'pop' means get and delete
|
// clean up traceMap: 'pop' means get and delete
|
||||||
traceConf, found = popTraceMapping(connHandle)
|
traceConf, found = popTraceMapping(connHandle)
|
||||||
} else {
|
} else {
|
||||||
|
@ -123,16 +125,16 @@ func traceCallbackTrampoline(
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
panic(fmt.Sprintf("Mapping not found for handle 0x%x (ev 0x%x)",
|
panic(fmt.Sprintf("Mapping not found for handle 0x%x (ev 0x%x)",
|
||||||
connHandle, traceEventCode))
|
connHandle, eventCode))
|
||||||
}
|
}
|
||||||
|
|
||||||
var info TraceInfo
|
var info TraceInfo
|
||||||
|
|
||||||
info.EventCode = uint32(traceEventCode)
|
info.EventCode = eventCode
|
||||||
info.AutoCommit = (int(C.sqlite3_get_autocommit(contextDB)) != 0)
|
info.AutoCommit = (int(C.sqlite3_get_autocommit(contextDB)) != 0)
|
||||||
info.ConnHandle = connHandle
|
info.ConnHandle = connHandle
|
||||||
|
|
||||||
switch traceEventCode {
|
switch eventCode {
|
||||||
case TraceStmt:
|
case TraceStmt:
|
||||||
info.StmtHandle = uintptr(p)
|
info.StmtHandle = uintptr(p)
|
||||||
|
|
||||||
|
@ -183,7 +185,7 @@ func traceCallbackTrampoline(
|
||||||
// registering this callback trampoline with SQLite --- for cleanup.
|
// registering this callback trampoline with SQLite --- for cleanup.
|
||||||
// In the future there may be more events forced to "selected" in SQLite
|
// In the future there may be more events forced to "selected" in SQLite
|
||||||
// for the driver's needs.
|
// for the driver's needs.
|
||||||
if traceConf.EventMask&traceEventCode == 0 {
|
if traceConf.EventMask&eventCode == 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue