Quoting is incorrect in DB2 jdbc adapter
----------------------------------------

                 Key: JRUBY-1583
                 URL: http://jira.codehaus.org/browse/JRUBY-1583
             Project: JRuby
          Issue Type: Bug
          Components: ActiveRecord-JDBC
    Affects Versions: JRuby 1.0.2
            Reporter: Ryan Shillington


The code in ActiveRecord-jdbc 0.6 tries to quote integers when running against 
DB2.

When trying to do a find, I get the following error:

{code}
ArgumentError: DB2 SQL Error: SQLCODE=-401, SQLSTATE=42818, SQLERRMC==, 
DRIVER=3.50.152: SELECT * FROM wishes WHERE (wishes.id = '45') 
{code}

Notice that wishes.id = '45' instead of wishes.id = 45.  This seems to stem 
from the column.type not being correctly identified as :primary_key in 
jdbc_db2.rb.  I made the following fix around jdbc_db2.rb:74:

    def quote(value, column = nil) # :nodoc:
      if column && column.type == :primary_key
        return value.to_s
      end
-      if column && (column.type == :decimal) && value
+      if column && (column.type == :decimal || column.type == :integer) && 
value
        return value.to_s
      end
      case value
      when String                

Although that fixed it for now (and for other integer columns), that doesn't 
answer why column.type == :primary_key failed.  

I did notice one other kinda screwy thing - on line 55 you've hard coded 
primary keys to start at 42, which is a funny number to start at.  Why not 1?

Ryan

-- 
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

Reply via email to