On Mon, Jan 16, 2012 at 12:08 PM, Aaron Patterson <[email protected]> wrote: > On Sat, Jan 14, 2012 at 01:26:08PM +1300, Michael Koziarski wrote: >> Most database protocols include type information along with the values >> themselves, the drivers should be able to do introspection and 'magically' >> cast them completely removing our casting from the picture. > > I'm not sure if the pg "over the wire" protocol contains that > information, but I can tell you that libpg doesn't provide functions for > casting to C types (that I can find). > > See PQgetvalue: > > http://www.postgresql.org/docs/6.4/static/libpq-chapter16943.htm
PQftype returns a type id integer that represents the database type. The ruby postgres drivers (pg, postgres, postgres-pr) expose this information via the type or ftype method on the PGresult class. The common database types have fixed type id integers you can statically map to ruby classes (16 -> boolean, 700 and 701 -> float, etc.). You may be correct that libpq lacks a function that casts to C types. But it's fairly simple to cast the C string directly to the desired ruby type using a mapping based on the type id integer. Jeremy -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
