New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent parameter indexes passed to the logging middleware #5525
Comments
In my understanding, the positions of parameters bound via As far as I can tell, there is no clear standard on the keys and the order of elements of The only documentation I could find is about the query builder (#4421, #4422): dbal/docs/en/reference/query-builder.rst Lines 47 to 48 in 84328cd
Which on its own is odd: in the same codebase one would have to use 1-based positions in 1-based parameter keys when passed to Lines 10 to 14 in 9babd9e
|
If you're talking about the parameters passed as an array to |
I extended the demo https://3v4l.org/Zm6rN - PDO accepts only 1-based positional params, 0-based throws immediately. SQLite3 allows 0-based, but the result is wrong. So it seems the "standard" for the native drivers for positional params is 1-based only. I do not argue 0-based is much more natural in php world and I do even like it more, as only 0-based array can meet the definition php list. In atk4/data https://github.com/atk4/data/blob/f4ebf2b94f36f0657faf9b1c58ca17e6c604767c/src/Persistence/Sql/Expression.php#L627 we use So the only issue here is: dbal/src/Schema/SqliteSchemaManager.php Line 207 in 2aec3f8
pass the params into |
Personally, I find the
If we could get rid of it on the driver level, we could hugely improve the API for binding parameters from the type safety standpoint but the remaining API would require writing more code (which isn't a huge concern). But then the user-facing wrapper-level methods like function (Statement $stmt) use ($foo, $bar): void {
$stmt->bindParam(1, $foo);
$stmt->bindParam(2, $bar);
} |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug Report
Summary
Correct me if this is intended and documented somewhere, otherwise it seems like a bug to me.
Current behaviour
The issue is bind params are strictly 1-based [1] [2], ie. always starting with index 1, not 0.
But in some places like
dbal/src/Schema/SqliteSchemaManager.php
Line 207 in 2aec3f8
Quick demo https://3v4l.org/s8hef shows the conversion must happen somewhere in the DBAL, as 0-based params are not accepted by SQLite natively.
I noticed this issue when using
Doctrine\DBAL\Logging\SQLLogger::startQuery()
which receives the passed params to DBAL, ie. params starting with index 0.How to reproduce
Can some DBAL connection query method like:
and notice what params are passed to
Doctrine\DBAL\Logging\SQLLogger::startQuery()
. Currently, the params start with0
which is wrong as such params are not valid.Expected behaviour
I expect
Doctrine\DBAL\Logging\SQLLogger::startQuery()
to always return params that are valid and can be used to reproduce the logged query /w and /wo DBAL.I propose DBAL to never accept 0-based params so no transformation is needed. This seems to be already the case with
mysqli
driver.[1] https://www.php.net/manual/en/pdostatement.bindparam.php
[2] https://www.php.net/manual/en/sqlite3stmt.bindparam.php
The text was updated successfully, but these errors were encountered: