Skip to content

Commit a76acee

Browse files
committed
more comments in countParams
1 parent bb92c98 commit a76acee

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

main.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,17 +269,24 @@ func countParams(queryStmt *sql.Stmt, queryString string) int {
269269
}
270270

271271
// Query returned an error
272-
// Parse the error to get expected params count
273-
regex := regexp.MustCompile(`sql: expected (\d+) arguments, got 0`)
272+
// Parse the error to get the expected params count
273+
regex := regexp.MustCompile(`sql: expected (\p{N}) arguments, got 0`)
274274
regexSubmatches := regex.FindAllStringSubmatch(err.Error(), 1)
275275
if len(regexSubmatches) != 1 || len(regexSubmatches[0]) != 2 {
276-
// This is weird, return best guess
276+
// This is weird
277+
// queryStmt is prepared (compiled) so it is valid
278+
// but yet there was an error executing queryStmt
279+
// Return best guess
280+
// TODO: Should we maybe return an error and kill the server?
277281
return strings.Count(queryString, "?")
278282
}
279283
count, err := strconv.Atoi(regexSubmatches[0][1])
280284
if err != nil {
281-
// This is weirder because the regex is \d+
285+
// This is even weirder
286+
// The regex is \p{N}+ (unicode number sequence) and there was a match,
287+
// but converting it from string to int returned an error
282288
// Return best guess
289+
// TODO: Should we maybe return an error and kill the server?
283290
return strings.Count(queryString, "?")
284291
}
285292
return count

0 commit comments

Comments
 (0)