-
Notifications
You must be signed in to change notification settings - Fork 72
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
No access to field types for a query result #99
Comments
I'd be in favor of an API that exposes all of the column info available from the C API. Maybe something like |
Towards trilogy-libraries#99, this exposes additional field data on the query result via a `Result#columns` method. We were already using this data in the C extension to determine how to cast the column values. We now add a pointer to the `column_info` struct onto the result and then lazily add the values to the `Result` instance when called. This method could eventually replace the `#fields` method which at the moment only includes the column name. Co-authored-by: Daniel Colson <[email protected]> Co-authored-by: Charlotte Wen <[email protected]>
Towards trilogy-libraries#99, this exposes additional field data on the query result via a `Result#columns` method. We were already using this data in the C extension to determine how to cast the column values. We now add a pointer to the `column_info` struct onto the result and then lazily add the values to the `Result` instance when called. This method could eventually replace the `#fields` method which at the moment only includes the column name. Co-authored-by: Daniel Colson <[email protected]> Co-authored-by: Charlotte Wen <[email protected]>
Towards trilogy-libraries#99, this exposes additional field data on the query result via a `Result#columns` method. We were already using this data in the C extension to determine how to cast the column values. We now add a pointer to the `column_info` struct onto the result and then lazily add the values to the `Result` instance when called. This method could eventually replace the `#fields` method which at the moment only includes the column name. Co-authored-by: Daniel Colson <[email protected]> Co-authored-by: Charlotte Wen <[email protected]>
Towards trilogy-libraries#99, this exposes additional field data on the query result via a `Result#columns` method. We were already using this data in the C extension to determine how to cast the column values. We now add a pointer to the `column_info` struct onto the result and then lazily add the values to the `Result` instance when called. This method could eventually replace the `#fields` method which at the moment only includes the column name. Co-authored-by: Daniel Colson <[email protected]> Co-authored-by: Charlotte Wen <[email protected]>
In
mysql2
, a result has afield_types
method to get access to the field types of the result. Trilogy doesn't seem to provide any way to get access to these in the Ruby layer. The C driver does provide it, but it's not exposed in Ruby.The Ruby driver does use it for casting purposes, so it's internally available. See also:
trilogy/contrib/ruby/ext/trilogy-ruby/cext.c
Lines 738 to 742 in 640f990
There the data is read into
column_info
but that data is ephemeral for the result object and not included in the final result.We were looking to move to Trilogy, but we do need access to this field type information in some way or another. From purely that perspective, it doesn't have to be compatible 1:1 with how
mysql2
works, as long as it's available in some way.I'm happy to contribute a PR to add this, but I don't really know what the preferred way of adding this would be. Should it be for example to
column_info
and then lazily create entries in afield_types
method? Or should we buildfield_types
directly likefields
is built (although often it won't really be needed, as is clear since it's not present yet and already extensively used with Rails).Or should there be a totally different function than
field_types
that returns the types not as strings likemysql2
does, but with integer constants + any of the additional flags / size attributes etc. for the type? If there's any preference with how to make this available, I'm also able to start a PR for that then.The text was updated successfully, but these errors were encountered: