Repository navigation
Bind Select parameters in placeholder order for positional drivers - #237
Open
simon-mundy wants to merge 1 commit into
Open
simon-mundy wants to merge 1 commit into
simon-mundy wants to merge 1 commit into
Conversation
processSelect() resolved the FROM table before the columns and the quantifier after them, so a FROM sub-select's parameters were bound ahead of column and quantifier parameters that appear earlier in the SQL. Positional drivers bind getPositionalArray() in insertion order, so values landed on the wrong placeholders. The columns and the FROM table now bind into their own containers and are appended after the quantifier in text order. Processing order is unchanged, so parameter names and SQL text are identical.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Problem
With a positional driver (
?placeholders, e.g. Mysqli, or PgSql's$#which is numbered in text order), aSelectcould bind values to the wrong placeholders.ParameterContainer::getPositionalArray()returns values in insertion order, butSelectdid not always insert them in the order the placeholders appear in the SQL:Cause
Select::processSelect()resolves the FROM table (including a FROM sub-select) before the columns and join columns, and the quantifier after them. All three bound straight into the shared container.Fix
In
processSelect()the FROM table and the columns (including join columns and column sub-selects) bind into their own temporaryParameterContainers. After the quantifier is processed, the column parameters and then the table parameters are appended to the real container, keeping each parameter's type (errata) and maximum length.Processing order is unchanged, so parameter names, sub-select numbering and SQL text are byte-identical to before. Named drivers bind the same names and values; only the container's iteration order changes, now following the SQL text. No
process*()signatures change.Every other clause was checked and already binds in text order: Select joins (sub-select table then
ON), where, group, having, order, limit/offset and combine; Update (table, joins, set, where); Insert (values, and Insert from select); Delete; Combine.Tests
New
test/unit/Sql/SelectParameterOrderTest.php(#[Group('unit')]):getPositionalArray().LIMITinside a FROM sub-select keepsTYPE_INTEGER).The out-of-order cases fail on
0.6.xand pass with this change. The unit suite passes,mago format --check,mago lintandmago analyzeare clean, and the changed code has full line coverage.Platform packages
None needed. php-db/phpdb-mysql and php-db/phpdb-sqlite override only
processLimit()/processOffset(), which already bind in text order. php-db/phpdb-pgsql has no SQL decorators. All three inherit the fixedprocessSelect().