Hi
Please advice me about the following problem.
-
Problem
find_by_xxx method does not work correctly the following caes with
sybase adaptor. -
How to reproducible
model :users
t.column :code, :string <-- :string column
t.column :last_name, :string
t.column :first_name,:string
User.find(1)
=> #<User:0x2abe232a68e8 @attributes={“code”=>“1”, “id”=>“1”,
“first_name”=>“hiroyuki”, “last_name”=>“sato”}>
code data only include number
User.find_by_code(“1”)
ActiveRecord::StatementInvalid: RuntimeError: SQL Command Failed for
User Load: SELECT * FROM users WHERE (users.[code] = 1)
This SQL should be quote like this
SELECT * FROM users WHERE (users.[code] = “1”)
- probelm source
sybase_adapter.rb
279 def quote(value, column = nil)
280 return value.quoted_id if value.respond_to?
(:quoted_id)
281
282 case value
283 when String
284 if column && column.type == :binary &&
column.class.respond_to?(:string_to_binary)
285
“#{quote_string(column.class.string_to_binary(value))}”
286 elsif @numconvert && force_numeric?(column) &&
value =~ /^[±]?[0-9]+$/o <-- here
287 value
288 else
289 “’#{quote_string(value)}’”
290 end
sybase_adapter.rb
302 def force_numeric?(column)
303 (column.nil? || [:integer, :float, :decimal].include?
(column.type))
304 end
I think force_numeric? method should be return false
Any idea?
- environment
ActiveRecord 1.15.3
Thank you for your advice.
– hiroyuki sato