# \[Sybase Adaptor\] find\_by\_xxx does not work correctly

**URL:** <https://www.ruby-forum.com/t/sybase-adaptor-find-by-xxx-does-not-work-correctly/90965>\
**Category:** Rails\
**Created:** [April 3, 2007, 1:01pm UTC](https://www.ruby-forum.com/t/sybase-adaptor-find-by-xxx-does-not-work-correctly/90965 "2007-04-03T13:01:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 3, 2007, 1:01pm UTC](https://www.ruby-forum.com/t/sybase-adaptor-find-by-xxx-does-not-work-correctly/90965/1 "2007-04-03T13:01:15Z")

</div>

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
