-
-
Notifications
You must be signed in to change notification settings - Fork 23
Prototype support for bindValue/bindParam on PDOStatement #265
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
Conversation
|
This looks great. we need more testcoverage, especially in
for the error cases. expected error messages need to be put into |
|
While adding tests, it seems like it's finding bind calls from previous pdo statements, so the code isn't entirely correct. It needs to stop once it hits |
|
For inspiration, a few real world examples can be taken from |
|
I think I fixed it. I manually constructed |
| $args = $bindCall->getArgs(); | ||
| if (\count($args) >= 2) { | ||
| $keyType = $scope->getType($args[0]->value); | ||
| if ($keyType instanceof ConstantIntegerType || $keyType instanceof ConstantStringType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this check here, or could we just feed everything into $parameterKeys and resolveParameters later on would decide which types are supported and which not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's constrained by the constructor, so phpstan complained.
staabm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i love it
| $stmt = $pdo->prepare($query); | ||
| $stmt->bindValue(':email', '%|'.$string.'|%'); | ||
| $stmt->execute(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can/should cover a case where some params are bound via bindValue or bindParam and others are given to execute at the same time.. I guess this is supported in pdo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the pdo code, and it seemed like if you pass into execute, it empties any of the previously bound variables. I may have misunderstood though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be cool if you could run a small example on your own and verify the thesis.
if its right, we might even create a PHPStan-Rule which errors on bindValue/.. calls, when parameters are passed to execute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's the case:
$st = Container::Database()->prepare( 'SELECT * FROM Apps WHERE AppID = :a OR AppID = :b' );
$st->bindValue( ':a', 123 );
$st->execute( [ ':b' => 456 ] ); // SQLSTATE[HY093]: Invalid parameter numberThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thx
I think this adds the right pieces.
refs #199