Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
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
In e37a2b6 in ar-jdbc.