Update sqlite3 driver to properly cast values to column types when quoting
--------------------------------------------------------------------------
Key: JRUBY-3508
URL: http://jira.codehaus.org/browse/JRUBY-3508
Project: JRuby
Issue Type: Bug
Components: ActiveRecord-JDBC
Affects Versions: ActiveRecord-JDBC-0.9.1
Environment: OSX 10.5.6, Java 1.5.0_16, jRuby 1.2.0, ActiveRecord-JDBC
0.9.1
Reporter: Michael Rykov
Fix For: ActiveRecord-JDBC-0.9.1
Attachments: jdbc_sqlite3.rb
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:
{code}
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
{code}
--
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