Skip to content

Commit 2e622a7

Browse files
committed
feat(logging): add logging for unknown queries in Prepare and ExecContext
1 parent 9f613c2 commit 2e622a7

File tree

4 files changed

+7
-0
lines changed

4 files changed

+7
-0
lines changed

template/driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"database/sql"
66
"database/sql/driver"
77
"io"
8+
"log"
89
"strings"
910
"sync"
1011
"time"
@@ -115,6 +116,7 @@ func (c *cacheConn) Prepare(rawQuery string) (driver.Stmt, error) {
115116
queryInfo, ok := queryMap[normalizedQuery]
116117
if !ok {
117118
if !strings.HasPrefix(strings.ToUpper(normalizedQuery), "SELECT") {
119+
log.Println("unknown query:", normalizedQuery)
118120
PurgeAllCaches()
119121
}
120122
return c.inner.Prepare(rawQuery)

template/driver.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func (c *cacheConn) Prepare(rawQuery string) (driver.Stmt, error) {
114114
queryInfo, ok := queryMap[normalizedQuery]
115115
if !ok {
116116
if !strings.HasPrefix(strings.ToUpper(normalizedQuery), "SELECT") {
117+
log.Println("unknown query:", normalizedQuery)
117118
PurgeAllCaches()
118119
}
119120
return c.inner.Prepare(rawQuery)

template/stmt.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"database/sql/driver"
66
"fmt"
7+
"log"
78
"slices"
89
"strings"
910

@@ -209,6 +210,7 @@ func (c *cacheConn) ExecContext(ctx context.Context, rawQuery string, nvargs []d
209210

210211
queryInfo, ok := queryMap[normalizedQuery]
211212
if !ok {
213+
log.Println("unknown query:", normalizedQuery)
212214
PurgeAllCaches()
213215
return inner.ExecContext(ctx, rawQuery, nvargs)
214216
}

template/stmt.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"database/sql/driver"
66
"fmt"
7+
"log"
78
"slices"
89
"strings"
910

@@ -209,6 +210,7 @@ func (c *cacheConn) ExecContext(ctx context.Context, rawQuery string, nvargs []d
209210

210211
queryInfo, ok := queryMap[normalizedQuery]
211212
if !ok {
213+
log.Println("unknown query:", normalizedQuery)
212214
PurgeAllCaches()
213215
return inner.ExecContext(ctx, rawQuery, nvargs)
214216
}

0 commit comments

Comments
 (0)