Repository navigation
feat: bind SQL parameters safely and fail before writing output - #15
Merged
Merged
Conversation
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.
Summary
Generated code is only trustworthy if every placeholder in the SQL it executes
has exactly one known Java value behind it. sqlcj previously substituted
placeholder text across the whole query string and analyzed only some of the
expressions it accepted, so a query could compile and still execute SQL whose
markers did not line up with the arguments passed to it. Parameter handling is
now driven by the SQL parser's own tokens, and a query that cannot be bound
safely fails at compile time with a diagnostic that names where it came from.
Changes
$Nparameter tokens the SQL parser actually reported,copying every other source byte unchanged, so placeholder-like text inside
string literals, quoted identifiers, and comments survives byte for byte.
placeholder tokens exactly, in the same textual order, so a placeholder in a
location sqlcj does not analyze is a compile error instead of an argument
list that silently comes up short.
$Nindex to repeat or appear out of order: the generated methodexposes one correctly typed parameter per logical index, and the runtime
receives that value once per textual
?position.?, named:name,index
$0, gapped indexes, and an index whose occurrences infer conflictingJava types — with a focused message that names the offending placeholder.
SELECTmust be:oneor:many, supported writes must be:exec, andRETURNINGis rejected.focused reason instead of a stack trace.
any file, so a failure in a later source cannot leave a mixture of old and
new generated classes behind.
Scope and non-goals
The supported SQL subset is unchanged: this affects how the existing
SELECT,single-row
INSERT, direct-placeholderUPDATE, and single-tableDELETEshapes are compiled, not which shapes are accepted. No new projections,
predicates, join kinds, write shapes, or SQL types are added,
RETURNINGstaysunsupported, named parameters and query macros remain out of scope, and SQL is
never reformatted or rewritten beyond parameter markers. The sample
queries.sqlnow uses$1where it previously used an anonymous?.