Class DBI::TypeUtil
In: lib/dbi/typeutil.rb
Parent: Object

TypeUtil is a series of utility methods for type management.


Public Class methods

Convert object for driver_name. See register_conversion for a complete explanation of how type conversion is performed.

If the conversion is instructed to cascade, it will go to the special "default" conversion, which is a pre-defined common case (and mutable) ruleset for native types. Note that it will use the result from the first conversion, not what was originally passed. Be sure to leave the object untouched if that is your intent. E.g., if your DBD converts an Integer to String and tells it to cascade, the "default" conversion will get a String and quote it, not an Integer (which has different rules).

Register a conversion for a DBD. This applies to bound parameters for outgoing statements; please look at DBI::Type for result sets.

Conversions are given a driver_name, which is then used to look up the conversion to perform on the object. Please see convert for more information. Driver names are typically provided by the DBD, but may be overridden at any stage temporarily by assigning to the driver_name attribute for the various handles.

A conversion block is normally a case statement that identifies various native ruby types and converts them to string, but ultimately the result type is dependent on low-level driver. The resulting object will be fed to the query as the bound value.

The result of the block is two arguments, the first being the result object, and the second being a cascade flag, which if true instructs convert to run the result through the default conversion as well and use its result. This is advantageous when you just need to convert everything to string, and allow default to properly escape it.

Convenience method to match many SQL named types to DBI::Type classes. If none can be matched, returns DBI::Type::Varchar.