# AR: quoting integer in string : how to fix?

**URL:** <https://www.ruby-forum.com/t/ar-quoting-integer-in-string-how-to-fix/69325>\
**Category:** Rails\
**Created:** [September 20, 2006, 10:17am UTC](https://www.ruby-forum.com/t/ar-quoting-integer-in-string-how-to-fix/69325 "2006-09-20T10:17:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@tony](https://www.ruby-forum.com/u/tony)\
**Post date:** [September 20, 2006, 10:17am UTC](https://www.ruby-forum.com/t/ar-quoting-integer-in-string-how-to-fix/69325/1 "2006-09-20T10:17:17Z")

</div>

Hello.

I have a table like this :

id : primary key (numeric(9,0) identity for me)  
name : string  
value : string  
rank : integer

Now I insert this record :  
name = “dummy”  
val = “12345”  
rank = 34

I can insert, update and delete it.

If I want to search based on value, I would like to use the  
so-easy-and-cute  
find\_all\_by\_val method as in :

find\_all\_by\_val(“12345”)

But this gives me a SQL request invalid :  
SELECT \* FROM dummy\_table WHERE val = 12345

Numbers in string are quoted as integer  
If I change quote method, I could have  
SELECT \* FROM dummy\_table WHERE val = “12345”

But now, I have the same problem with rank :

find\_all\_by\_rank(“12345”)

gives me SELECT \* FROM dummy\_table WHERE rank = “12345”

Is there a magic implementation of the quote method in the adapter that  
could deal with integer and string in the right way ?

Tony

PS : I’m using a Sybase ASE server. I can’t put number between quotes  
like in MySQL requests.

---

<div class="post-metadata">

**Author:** ![tony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@tony](https://www.ruby-forum.com/u/tony)\
**Post date:** [September 21, 2006, 8:45am UTC](https://www.ruby-forum.com/t/ar-quoting-integer-in-string-how-to-fix/69325/2 "2006-09-21T08:45:26Z")

</div>

Anybody has the same problem ?

It’s a pitty to have find(id.to\_i) rather than just find(id) …

---

<div class="post-metadata">

**Author:** ![tony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@tony](https://www.ruby-forum.com/u/tony)\
**Post date:** [September 21, 2006, 11:39am UTC](https://www.ruby-forum.com/t/ar-quoting-integer-in-string-how-to-fix/69325/3 "2006-09-21T11:39:16Z")

</div>

Tony wrote:

> name = “dummy”
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Hi Tony,

Try using find(:all, :conditions =\> “rank = ?”, intString)

---

<div class="post-metadata">

**Author:** ![tony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@tony](https://www.ruby-forum.com/u/tony)\
**Post date:** [September 21, 2006, 4:01pm UTC](https://www.ruby-forum.com/t/ar-quoting-integer-in-string-how-to-fix/69325/4 "2006-09-21T16:01:25Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Try using find(:all, :conditions =\> “rank = ?”, intString)

Hi Eize !

Thanks for comming 😉

What is intString ? You mean a string containing an integer like “1234”  
?  
If this is what you mean, it does not work either. The find\_all\_by\_rank  
generate the same find(:all,…) that you write.

For insert or update, rails use a hash with the fields names and types,  
and pass to the quote method the value and the type of the field. But  
for select, the field type is not searched. So quote is called only with  
the value … And I could not guess when to return integer and when to  
return string.

From now, I change all my find method having integer with a call to  
String.to\_i and my Adapter always return quoted string. Not really easy  
to use at all.

Tony
