Skip to content
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

Support array binding for custom types #2357

Closed
wants to merge 2 commits into from
Closed

Conversation

lkm
Copy link

@lkm lkm commented Apr 14, 2016

At present you are only able to have string and integer arrays as a binding parameter. If you needed any custom parsing of variables using the Type::convertToDatabaseValue method that needs to be executed manually on the array before, this also meant that the binding type could not be overridden, in my case of implementing binary guid \PDO::PARAM_LOB; needed to be set before sqlite would accept it.

This PR should hopefully take care of that by testing whether the incoming param is an array and then extract it into separate params.

E.g. ->setParameter("array", $arrayOfIds, CustomType::CUSTOMTYPE)
@robo220
Copy link

robo220 commented Apr 22, 2016

Any update on when we could merge this? I'm having the same issue.

@deeky666
Copy link
Member

@lkm I'm sorry but I don't quite get the issue. Please also provide a testcase (that also might clear things up). Otherwise we can't merge.

@lkm
Copy link
Author

lkm commented May 16, 2016

Sorry @deeky666, I was going to provide a test, it somehow slipped my mind. Hopefully this casts some light on what the change is doing. I assume this would be an issue for any type (even the bundled ones), that requires a different PDO binding param type (for instance Binary)

array(
"SELECT * FROM Foo WHERE foo IN (?)",
array(array('oof', 'rab')),
array('customReverseType'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuse me but I still don't get the binding type here. We only have limited types that we map to PDO types, and this one is not supported... How should we map that one to the driver? Or am I missing something here?

Copy link
Author

@lkm lkm May 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CustomReverseType isn't a binding type, but a custom type that extends Doctrine\DBAL\Types\Type and is added using Type::addType('customReverseType', 'Namespace\To\Types\CustomReverseType');.
It's PDO binding type is retrieved by calling getBindingType() this happens in Doctrine\DBAL\Connection->getBindingInfo().

This is especially important if you both rely on a binding type of PARAM_LOB and have implemented convertToDatabaseValue, I'm using it like this:

...
 ->setParameter("id", array(binary1, binary2, binaryN), CustomBinaryType::CUSTOMBINARYTYPE);

@lkm
Copy link
Author

lkm commented Jun 7, 2016

@deeky666 Have you had time to look at this?

Base automatically changed from master to 4.0.x January 22, 2021 07:43
@morozov
Copy link
Member

morozov commented Oct 26, 2021

Closing as stale.

@morozov morozov closed this Oct 26, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants