jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • JRuby
  • JRUBY-3508

Update sqlite3 driver to properly cast values to column types when quoting

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    OSX 10.5.6, Java 1.5.0_16, jRuby 1.2.0, ActiveRecord-JDBC 0.9.1
  • Patch Submitted:
    Yes

Description

I discovered this bug via Rails while trying the good 'ol "#{id}-#{description}" trick. In short, a URL like this http://localhost/objects/18-Lorem-Ipsum should be equivalent to this http://localhost/objects/18 if the ID column is an integer in the DB
More info here: http://www.jroller.com/obie/entry/seo_optimization_of_urls_in

In both MRI and MySQL JDBC, the ID is cast to an integer before going into the query. On SQLite, I was getting errors like
"Couldn't find ModelObject with ID=18-Lorem-Ipsum" due to lack of that cast.

I fixed it locally by changing the quote method in activerecord-jdbc-adapter-0.9.1/lib/jdbc_adapter/jdbc_sqlite3.rb to the following:

def quote(value, column = nil) # :nodoc:
  return value.quoted_id if value.respond_to?(:quoted_id)

  case value
  when String
    if column && column.type == :binary
      "'#{quote_string(column.class.string_to_binary(value))}'"
    elsif column && [:integer, :float].include?(column.type)
      value = column.type == :integer ? value.to_i : value.to_f
      value.to_s
    else
      "'#{quote_string(value)}'"
    end
  else super
  end
end
  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. File
    jdbc_sqlite3.rb
    18/Mar/09 4:21 AM
    10 kB
    Michael Rykov

Activity

  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Nick Sieger added a comment - 01/Oct/09 2:44 PM

In e37a2b6 in ar-jdbc.

Show
Nick Sieger added a comment - 01/Oct/09 2:44 PM In e37a2b6 in ar-jdbc.

People

  • Assignee:
    Unassigned
    Reporter:
    Michael Rykov
Vote (0)
Watch (0)

Dates

  • Created:
    18/Mar/09 4:21 AM
    Updated:
    27/Oct/09 1:49 PM
    Resolved:
    01/Oct/09 2:44 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.