Repository navigation
Scan SQL for placeholders and named parameters while skipping literals, identifiers, comments and casts. - #23
Merged
Merged
Conversation
…s, identifiers, comments and casts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One scanner,
scan.go, walks a query once and reports only three tokens: a?placeholder, the??escape and a:nameparameter. String literals (with''doubling, PostgresE'...'escapes and a heuristic for MySQL\'), double-quoted and backtick identifiers,--and nested/* */comments and Postgres$tag$quotes are opaque;[...]identifiers are recognised for theATbind type only;#is not a comment.Rebind,InandcompileNamedQueryall use it, andcompileNamedQuerynow takes a string.What that fixes, by upstream issue: a
?inside a literal or comment counted byIn(#961, #487, #608) and renumbered byRebind(the half #984 left out); a:inside a literal or comment taken for a parameter (#206, #253, #302, #368, #443, #872, #947, #394, #894); a trailing name lost at the end of the query (#441); a cast attached to a parameter,:id::uuid(#983); a cast anywhere else,now()::date(#428, #650, #956); non-ASCII parameter names. It supersedes upstream #151, #474, #775, #984, #985 and #1002, whose approaches are credited in the changelog.Behaviour changes, each getting a changelog line: the documented
::escape is gone, so::is a cast and::::stays four colons (a code search found two repositories using the escape against about sixty relying on casts that failed);??is a literal?inInandRebind, soRebind(QUESTION, q)is no longer an identity for a query containing??; a parameter name can no longer start with a digit.Tests: the 91-row matrix from the design work for
In,RebindandcompileNamedQuery; the two::rows ofTestCompileQueryupdated; the Unicode row that was commented out since 2013 enabled;TestEscapedColons, skipped since 2015, enabled; #920's comment case now asserts success; andTestNamedPostgresTypeCastruns the cast query end to end on Postgres, failing on master with the exact upstream error. Local run with Postgres 16, MySQL 8.4 and SQLite: 239 pass, 2 skip, 0 fail. Benchmarks on this machine:Rebind166 to 232 ns,In113 to 136 ns, allocations unchanged.