|
From: Gabriel E. <ga...@de...> - 2003-02-13 22:09:45
|
I need to double check this, but I think in Perl DBI I can not only do the
equivalent of this:
sql = %Q{
SELECT *
FROM bar, baz
WHERE bar.bar_val = ?
AND bar.bar_id = baz.baz_id
}
foo = 72
dbh.select_one(sql, foo)
but this also:
sql = %Q{
SELECT *
FROM bar, baz
WHERE bar.bar_val = ?
AND bar.bar_id = ?
}
foo = 72
sql_expr = 'baz.baz_id'
dbh.select_one(sql, foo, sql_expr)
It seems that Ruby DBI doesn't support anything for ? replacement but
constant values for quoting. It doesn't support table or field
identifiers, or bits of sql code.
I am at a loss for how to test whether something is a value or a
[field|table|bit of aql code], but some possibilities would be an abstract
class to inherit from if you wanted to pass a non-value, like sql_expr =
DBI::NonVal.new('baz.baz_id'), so we can do kind_of? on it. Or we could
use perhaps a new character for the substitution for this case.
I realize we can already just #{} in the strings for whatever we want to
replace ahead of time, but sometimes it would be nice to have this type of
substitution in automatic query generation scenarios.
--Gabriel
|