kubo / ruby-oci8

Ruby-oci8 - Oracle interface for ruby
Other
169 stars 75 forks source link

Integers being converted to BigDecimal vs Number #33

Closed jadon1979 closed 11 years ago

jadon1979 commented 11 years ago

I have a table with a column named "display_order". This Number type is being converted within oci8 upon fetch and/or fetch_hash.

display_order 123 becomes "123.0"

kubo commented 11 years ago

That's because Oracle number is not an integer. http://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832

If the "display_order" column contains integer values only, you need to declare the column type as INTEGER or NUMBER(38). (INTEGER is an alias of NUMBER(38))

jadon1979 commented 11 years ago

I was afraid you would say that.

kubo commented 11 years ago

What is your request?

If the column type is NUMBER(38), ruby-oci8 get the values as Integer because ruby-oci8 knows that the data type has no decimal parts.

If you want to explicitly get the column values as integer, use OCI8::Cursor#define.

If you want to get all NUMBER columns as Integer, set OCI8::BindType::Mapping[:number] = OCI8::BindType::Integer in advance. All decimal parts are ignored instead.

If you want to get the NUMBER value as Integer (when it doesn't have decimal parts) or Float (others), set OCI8::BindType::Mapping[:number] = OCI8::BindType::BasicNumberType in advance. If a column value has decimal parts and its precision is over 15, it is rounded to fit to the precision of Float.

jadon1979 commented 11 years ago

I managed it with define. Thanks.

tallenaz commented 8 years ago

Can we fix this in the display?

kubo commented 8 years ago

@tallenaz

  1. Could you open a new issue? Your issue looks unrelated to this one.
  2. Could you explain more details? I cannot imagine what you requested.
tallenaz commented 7 years ago

Sorry for the noise @kubo, I'll open a new issue if necessary.