AR: quoting integer in string : how to fix?

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.

Anybody has the same problem ?

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

Tony wrote:

name = “dummy”


Posted via http://www.ruby-forum.com/.

Hi Tony,

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

[email protected] wrote:

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

Hi Eize !

Thanks for comming :wink:

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