Forum: Ruby on Rails [Sybase Adaptor] find_by_xxx does not work correctly.

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
90beb7adc5c234f38a3992a7825fa64a?d=identicon&s=25 (Guest)
on 2007-04-03 13:01
(Received via mailing list)

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


    279       def quote(value, column = nil)
    280         return value.quoted_id if value.respond_to?
    282         case value
    283           when String
    284             if column && column.type == :binary &&
    286             elsif @numconvert && force_numeric?(column) &&
value =~ /^[+-]?[0-9]+$/o <-- here
    287               value
    288             else
    289               "'#{quote_string(value)}'"
    290             end


    302       def force_numeric?(column)
    303         (column.nil? || [:integer, :float, :decimal].include?
    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
This topic is locked and can not be replied to.