Repository navigation
Fix placeholder parsing: literals, comments and multiple %% (4.0.12) - #13
Merged
Merged
Conversation
Statement::sql() turned every ? and %% into a placeholder, so SQL such as WHERE note = 'Why?' broke. sql() now tracks quoted strings, backtick identifiers and comments, across sql() calls, and only replaces placeholders in SQL code. Inside backticks %% is still a placeholder, so `%%` with bRaw() can still name a table. execute() now joins sql() calls with newlines, as getComputed() already did, so a -- comment in one call no longer comments out the calls after it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sql() named every %% with the current raw bind position without
advancing it, so two %% in one sql() call got the same name and both
were filled with the first raw value: sql('VALUES (%%, %%)')
->bFloat(1)->bFloat(2) produced VALUES (1.000, 1.000). %% now has its
own counter, matched in order to the raw binds, as ? already is.
Also sets the CHANGELOG and README "Latest" entries to 4.0.12.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Added one more fix: two $s->sql('VALUES (%%, %%)')->bFloat(1)->bFloat(2);
// before: VALUES (1.000, 1.000)
// after: VALUES (1.000, 2.000)
Also added 3 tests (two 🤖 Generated with Claude Code |
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.
Statement::sql()turned every?and%%into a placeholder, even inside quoted strings in your own SQL:How it works:
sql()now tracks where it is in the statement, character by character, and only replaces placeholders in SQL code.?%%'...'and"..."strings (incl.''and\'escapes)`...`identifiers`%%`withbRaw()can name a table, as the tests and README do--,#and/* */commentsThe state carries across
sql()calls, so a string split over two calls is handled.reset()clears it.Also fixed:
execute()joined thesql()calls with spaces, whilegetComputed()used newlines. With spaces, a-- commentin onesql()call silently commented out every call after it.execute()now uses newlines too.Tests
tests/StatementPlaceholderTest.php: 19 cases covering strings, escapes, identifiers, comments,--without a space (subtraction, not a comment), strings spanningsql()calls, andreset(). No database needed.?and%%inside literals, and one with a-- comment. Both fail on the old code.🤖 Generated with Claude Code