-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Expose the underlying statement in DBAL statements #3534
Comments
While it's technically possible to introduce Any objections @doctrine/doctrinecore? |
no objections |
Giving access to the underlying statement is acceptable in my opinion, but the API needs to be marked as risky for usage, since the return type is |
@Ocramius my suggestion is to have implementation-specific methods, not part of the interface. Then, the return type is not mixed. Then, using it in a type-safe way would imply a check that your statement is a I don't think |
Linking #5037 as an example of the same requirement implemented for connections. |
Note that with the split of Statement and Result in the DBAL 3.x API, we would need this on the Result object (accessing |
I'd like to add my $0.02 if I may, being able to access the I empathise with Ocramius when he says "the I imagine this would involve implementing Totally understand that this is an edge-case and could be done differently by me, I just wanted to offer an opinion as an end-user of the library. Thanks Doctrine team! |
What we do have now is |
@derrabus when migrating to DBAL 3, I had to migrate to this. But this definitely made the code less good:
In my case, I needed the Having |
Would it be possible to create portable versions of both methods on DBAL's result class? Before I expose the internal state of our result object (and that's what the native result is), I'd like to try that path first. |
Well, I'm not sure other drivers would have the equivalent feature (I never investigated it). And it would require making the array shape returned for the meta portable (and to be honest, I'm not even 100% sure that it is fully portable between PDO drivers) |
It would, however like @stof mentioned I would either lose the benefits of I need My current workaround is... absolutely shameful, I'm using reflection to access private properties on the two result objects. Being able to get the |
It would require making the information you extract from that array shape portable, yes.
Do you think we could build a portable abstraction of a multi-rowset result?
Is that a problem? A driver that doesn't support it could either throw or return a multi-rowset result with only a single rowset.
And absolutely brittle because it would break the moment a middleware is used that decorates results or we decide to rename private properties in a new release, or… or… or.
Yes, but it's a leaky abstraction. Let's avoid that if we can find a better way. |
Looking quickly, here is what I found for the column meta API:
So for the field name and field type of the result, we could add them in the abstraction. |
Note that even DoctrineBundle needed special handling for MSSQL when explaining a query in the profiler because of this multi-rowsets. Having an escape-hatch for the result API would be consistent with the one we have for the connection one. |
I opened #5980 about introducing the DBAL abstraction for metadata about result columns. This would solve one use case that currently requires accessing the underlying statement. |
@yesdevnull |
Definitely, just depends if it's worth the extra effort for such a small use case. From reading Ocramius' comment "Unless this is a cross-platform feature, this should not land in DBAL", I wasn't sure how likely it would be for multi-rowset specific handling to land in Doctrine. I am happy to offer any assistance I can, particularly around
100%, I'm not justifying my workaround in any way. It's for an infrequently used feature in a project I'm working on, so I can sort of justify the reflection hack. I wouldn't normally condone this unless absolutely necessary.
Right you are, thanks for pointing that out. I had been looking at the |
Feature Request
Summary
The DBAL Statement object exposes the API for the common abstraction. But the different platforms may have additional features, which can be useful when you know that you are writing code targetting them.
As DBAL 2.x uses inheritance for PDOStatement, this is actually already possible for PDO-based drivers (not for others). As DBAL 3.x moves to composition, we are loosing that possibility. It would be great to add methods in the different Statement implementations returning the underlying statement. This method would not be part of the interface, as its return type would depend on the implementation being used.
For instance, PDO has a
PDOStatement::getColumnMeta
method to get some info about the type and name of the column in the result, which is very useful when you need to know the name of columns even when the result set is empty. #2176 is asking to bring this particular case to the common abstraction, but being able to escape the abstraction when you know that you use PDO is a good solution in the meantime.The text was updated successfully, but these errors were encountered: