Removed explicit escaping for pgsql driver in FilterPartial#maybeSpecifyEscapeChar. Fixes #941 #968
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.
As mentioned in the issue #941, my previous PR #927 causes the following error when using multiple partial filters in combination with Postgres:
SQLSTATE[HY093]: Invalid parameter number: parameter was not definedBefore opening this PR, I investigated on why this may be happening, since from my previous tests (see attachment in PR #927), Postgres supports
ESCAPEand the query result is the same with or without specifying it.I've not been able to exactly identify the problem, but I managed to figure out it has something to do with the
\char specifically.In fact, if FilterPartials#maybeSpecifyEscapeChar was to be modified as follows, the
Invalid parameter number errorwould not happen:Basically, this code (so the code currently implemented, not modified if not for the ß char) would work just fine by just replacing
ESCAPE '\'withESCAPE 'ß'(I usedßas an example since it wouldn't collide with other special-meaning chars such as*, but it could be any char).I guess this indicates that the problem does not live in the
maybeSpecifyEscapeCharor in the package itself, but I suspect it resides in some Eloquent parsing.On that regard, even if not related to the parsing of queries, I found a place in the Eloquent source (
vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php function substituteBindingsIntoRawSql), where expressions like\'are treated with special behaviors (tweaking that function, in fact, allowed me to parse the missing parameter in theddRawSqlwhile debuging).So my vague guess is that a similar behavior is influencing the parsing of the query when encountering
ESCAPE '\'.The proposed fix is really simple, I just removed
pgsqlfrom the drivers to explicitly escape, since the query results with or withoutESCAPEare the same for that driver (see testing in PR#927 attachment)In addition, in the
maybeSpecifyEscapeCharphpdoc, I also added'mariadb'as a possible value for the$driverparam, since L11 introduced that driver.After all the changes I updated the tests and, since the
composer.jsonof this package specify"illuminate/database": "^10.0|^11.0", but mariadb is a valid driver only in v11, I used the following condition to run the mariadb test only if the driver is supported (skipped with relevant message otherwise):This fix solves #941, allowing Postgres users to update the dependency and access the new features.
Hope this helps!