Hi,
I'm fairly new to Ruby. I touched some Perl, looked at Python, but the
elegance and clarity of the code in the doc's/tutorials of Ruby
attracted me (I'm no expert-programmer at all so this is very
subjective!).
I can declare some parameters in a SQL-statement with ?-marks and I
can pass the appropriate value(s) with the method execute(). This is
easy when the sql-code is like
···
***
select *
from bla
where
year = ?
***
How do I pass values when my sql-code is something like
***
select *
from bla
where
year IN ?
***
Is this possible? Do I have to pass an array of integers? (I guess not
because it doesn't work...) I've been googling alot to find any help,
in vain -- I'm clueless.
Many thanks in advance!
Kind regards,
David
David Jacobs said:
How do I pass values when my sql-code is something like
***
select *
from bla
where
year IN ?
***
Is this possible? Do I have to pass an array of integers? (I guess not
because it doesn't work...) I've been googling alot to find any help,
in vain -- I'm clueless.
I don't think passing in an array will work (in all cases).
But you might try this (warning: untested code):
sql = "select * from bla where year in (" +
values.collect{'?'}.join(',') +
")";
db.select_all(sql, values) do |row|
# process row
end
···
--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)