Thanks, Jeremy, I will give those a shot.
Steve
On Saturday, 21 July 2018 02:57:26 UTC-4, Jeremy Evans wrote:
>
> On Friday, July 20, 2018 at 11:17:42 AM UTC-7, Steven Schreck wrote:
>>
>>
>> I am using Sequel to connect to an Oracle DB via JRuby. I am using it as
>> a simple data adapter through which I execute raw sql queries and return
>> the data in a hash. The way I'm doing this is:
>> my_hash = db_conn.fetch(sql_query).all
>>
>> If the table being queried has numeric or decimal fields, the data type
>> returned in the hash looks like this:
>> :model_yr=>#<BigDecimal:15d0849,'0.12345E4',1(4)>
>>
>> Is there an easy way to get rid of the BigDecimal exponent and object
>> garbage and just return the value? :model_yr=>1234.5
>>
>
> Call to_f on the value to convert from BigDecimal to Float, if you don't
> mind the possible loss of precision. Make sure you don't do this if
> precision may be important.
>
> In terms of doing this automatically, you would have to override
> Dataset#type_convertor appropriately. Review how the jdbc/oracle adapter
> does that as well as the JDBC documentation, and then do something like:
>
> DB.extend_datasets do
> def type_convertor(map, meta, type, i)
> case type
> when Java::JavaSQL::Types::NUMERIC
> lambda{|r, i| r.getDouble(i)}
> else
> super
> end
> end
> end
>
> Jeremy
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.