Skip to content

Commit 324c3f7

Browse files
committed
fix type of event code
fixes #520
1 parent 6c771bb commit 324c3f7

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

Diff for: _example/trace/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func main() {
9595
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
9696
err := conn.SetTrace(&sqlite3.TraceConfig{
9797
Callback: traceCallback,
98-
EventMask: uint(eventMask),
98+
EventMask: eventMask,
9999
WantExpandedSQL: true,
100100
})
101101
return err

Diff for: sqlite3_trace.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ import (
2828
// Trace... constants identify the possible events causing callback invocation.
2929
// Values are same as the corresponding SQLite Trace Event Codes.
3030
const (
31-
TraceStmt = C.SQLITE_TRACE_STMT
32-
TraceProfile = C.SQLITE_TRACE_PROFILE
33-
TraceRow = C.SQLITE_TRACE_ROW
34-
TraceClose = C.SQLITE_TRACE_CLOSE
31+
TraceStmt = uint32(C.SQLITE_TRACE_STMT)
32+
TraceProfile = uint32(C.SQLITE_TRACE_PROFILE)
33+
TraceRow = uint32(C.SQLITE_TRACE_ROW)
34+
TraceClose = uint32(C.SQLITE_TRACE_CLOSE)
3535
)
3636

3737
type TraceInfo struct {
@@ -71,7 +71,7 @@ type TraceUserCallback func(TraceInfo) int
7171

7272
type TraceConfig struct {
7373
Callback TraceUserCallback
74-
EventMask C.uint
74+
EventMask uint32
7575
WantExpandedSQL bool
7676
}
7777

@@ -105,6 +105,8 @@ func traceCallbackTrampoline(
105105
// Parameter named 'X' in SQLite docs (eXtra event data?):
106106
xValue unsafe.Pointer) C.int {
107107

108+
eventCode := uint32(traceEventCode)
109+
108110
if ctx == nil {
109111
panic(fmt.Sprintf("No context (ev 0x%x)", traceEventCode))
110112
}
@@ -114,7 +116,7 @@ func traceCallbackTrampoline(
114116

115117
var traceConf TraceConfig
116118
var found bool
117-
if traceEventCode == TraceClose {
119+
if eventCode == TraceClose {
118120
// clean up traceMap: 'pop' means get and delete
119121
traceConf, found = popTraceMapping(connHandle)
120122
} else {
@@ -123,16 +125,16 @@ func traceCallbackTrampoline(
123125

124126
if !found {
125127
panic(fmt.Sprintf("Mapping not found for handle 0x%x (ev 0x%x)",
126-
connHandle, traceEventCode))
128+
connHandle, eventCode))
127129
}
128130

129131
var info TraceInfo
130132

131-
info.EventCode = uint32(traceEventCode)
133+
info.EventCode = eventCode
132134
info.AutoCommit = (int(C.sqlite3_get_autocommit(contextDB)) != 0)
133135
info.ConnHandle = connHandle
134136

135-
switch traceEventCode {
137+
switch eventCode {
136138
case TraceStmt:
137139
info.StmtHandle = uintptr(p)
138140

@@ -183,7 +185,7 @@ func traceCallbackTrampoline(
183185
// registering this callback trampoline with SQLite --- for cleanup.
184186
// In the future there may be more events forced to "selected" in SQLite
185187
// for the driver's needs.
186-
if traceConf.EventMask&traceEventCode == 0 {
188+
if traceConf.EventMask&eventCode == 0 {
187189
return 0
188190
}
189191

0 commit comments

Comments
 (0)