Oracle driver incorrectly casts the NUMBER data type
----------------------------------------------------
Key: JRUBY-2463
URL: http://jira.codehaus.org/browse/JRUBY-2463
Project: JRuby
Issue Type: Bug
Components: ActiveRecord-JDBC
Affects Versions: JRuby 1.1
Environment: JRuby 1.1.
Windows XP.
Oracle 10g.
activerecord-jdbc-adapter 0.8
Reporter: Matthew Williams
Priority: Critical
Creating a table within Oracle with the following simple syntax and column type:
CREATE TABLE TEST_TABLE
(test_column NUMBER)
TABLESPACE TEST_TABLESPACE;
And store the value "0.076" as an example in the column test_column, it stores
correctly and can be queried with no problem. A describe on the table returns
the data type NUMBER(0,-127) which I believe just means to default the
precision to its maximum range.
Line 82 of activerecord-jdbc-adapter-0.8\lib\jdbc_adapter\jdbc_oracle.rb:
{quote}
{{when /num|dec|real/i : @scale == 0 ? :integer : :decimal}}
{quote}
The above line reads "0" as the precision and assumes it should be cast as an
integer, but that's not necessarily true (as my above test case of storing the
value 0.076). The result of this is a value like 0.076 being returned as "0".
I think the only time a value should be cast to an integer would be when the
column type is explicitly set as an integer and that is handled just fine on
line 81 of the driver (when /int/i : :integer).
So ultimately I believe the @scale == 0 check should be eliminated for those
file types and automatically cast as a float or decimal type (I'm not sure what
the cost of casting it as either of those would be, perhaps someone with better
knowledge of the bit level details of the language could chime in on this).
Right now a simple monkey patch on that file to cast it as a float is my work
around but I think this should be addressed one way or another.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email