Repository navigation
Render int and float clause parameters again (regression from #232) - #242
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
The platform SelectDecorators in phpdb-mysql and phpdb-sqlite return the raw int limit and offset from processLimit()/processOffset() when the statement is not prepared. The specification renderer added in php-db#232 accepted only strings and called count() on anything else, so those queries threw a TypeError. Scalar and Stringable parameters are now converted with sprintf('%s'), exactly as vsprintf rendered them, while nested lists still raise the unsupported-parameter-count exception. The SqlParameters type and the Select::processLimit()/processOffset() return types allow scalar values so platform overrides type-check.
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.
Regression
#232 broke unprepared
LIMIT/OFFSETfor the MySQL and SQLite platforms. With either package'sSelectDecorator, rendering an unprepared Select that has an integer limit or offset now throws:Before #232 this rendered
SELECT "t".* FROM "t" LIMIT 10, which is still what->limit('10')gives. The same happens for->offset(5)on its own and for limit plus offset, in bothphpdb-mysqlandphpdb-sqlite.Cause
When the statement is not prepared, the packages'
processLimit()/processOffset()return[$this->limit]/[$this->offset]with the rawint. Before #232 those values went straight tovsprintf(), which accepts any scalar. The renderer that #232 added (flattenParameterList(),formatParameterList(),renderParameter()) accepts only strings and treats anything else as a nested list, so it callscount()on the int.I checked the other
process*()overrides in phpdb-mysql, phpdb-sqlite and phpdb-pgsql, including the MySQL DDL decorators. They all return strings, so limit and offset are the only hooks affected.Fix
AbstractSqlturnsstring|int|float|bool|Stringable|nullparameters into strings withsprintf('%s', …), which matchesvsprintf()'s%soutput exactly, float precision included. Arrays still throwRuntimeException::forUnsupportedParameterCountOf().renderParameter()wraps a scalar in a list instead of using(array). That cast would have turned aStringableobject into an array of its properties.SqlParameterspsalm type gains aSqlParameterValueelement type.Select::processLimit()/processOffset()now declarearray{0: SqlParameterValue}|null, so platform overrides that return the raw value pass analysis.The platform packages are unchanged.
Tests
test/unit/Sql/UnpreparedScalarLimitOffsetTest.php(#[Group('unit')]) usesTestAsset\UnpreparedScalarLimitSelect. That test double extendsSelectand returns the raw limit/offset from its hooks the same way the package decorators do, including MySQL's offset-onlyLIMIT 18446744073709551615. It does not depend on the packages. Data providers cover:combinedbyslotsprintf('%s')These tests fail on
0.6.xwith the TypeError above and pass with this change. The unit suite,mago format --check,mago lintandmago analyzeall exit 0, and every changed line insrc/is covered.