-
-
Notifications
You must be signed in to change notification settings - Fork 37
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 Query result typing #771
Comments
Type Information is stored in
$price = (new Query($db))->select(['price'])->from('product')->scalar(); To get typed values you need to cast the values after retrieving from DB $pricePhpType = $tableSchema->getColumn('price')->phpTypecast($price); |
@Tigrov that way has several drawbacks:
|
Depends of how do you use this. E.g. |
If question about |
@Tigrov no, it's about ability to get typed data without ActiveRecord and manual type juggling. |
Could you show an example how you suggest to solve this? |
Overall it's a good suggestion, worth to try. Something like this (new Query($db))->select(['price'])->from('product')->withTypecast()->scalar(); |
@Tigrov yes, I was planning
Maybe it's better to extract typecasting from ColumnSchema so that ActiveQuery and raw Query could share typecasting code, but have separate metadata collectors, but not sure If this will work fine. |
We plan to support non-PDO drivers as well and this feature might not fit this plan... |
You are right, some features differences seems to be inevitable, like support of async query execution. |
Adding |
@terabytesoftw there is already one |
If do this, it should be done for all supported DBMS And can be done after solving the issue #737 |
Currently
Code like this
will return
So currently in Yii3 and Yii2 to get typed data you have to extensively map values and manually control returned types.
Other way is to use
PDOStatement::getColumnMeta
which returns rather fine type information:Moreover, there is
[pgsql:oid] => <some int>
that refers to type information stored inpg_type
table (SELECT * FROM pg_type WHERE oid = <some int>
), so in theory it's possible to correctly typecast any possible type.Main catch seems to be that it should be optional.
P.S. I can try to make pull request.
The text was updated successfully, but these errors were encountered: