[Ruby-informix-misc] shortcut for prepare + execute
Gerardo Santana Gómez Garrido
gerardo.santana at gmail.com
Sat Mar 29 23:47:56 EDT 2008
Hello everybody,
There in CVS a shorcut to declare + open + iterate a cursor,
contributed by Reid Morrison: Database#each and Database#each_hash.
Here's an example:
query = "select * from sysusers"
Informix.connect(dbname) do |db|
db.each(query) { |row| puts row.join('|') } # do something with row
end
Now I'm thinking of adding another shortcut, for prepare + execute.
Right now, we have to do this:
query = "update test set field = ? where id = ?"
Informix.connect(dbname) do |db|
db.prepare(query) { |st| st.execute(field, id) }
end
The proposal is to do something like this.
query = "update test set field = ? where id = ?"
Informix.connect(dbname) do |db|
db.execute(query, field, id) # prepare + execute in a single step
end
Even though Database#execute is already an alias for immediate, I
don't see any problem giving Database#execute this new behavior,
because any previous script that used Database#execute thinking of it
as Database#immediate, will still work:
db.execute("create table test(id serial, desc varchar(30))")
will still do the same. The drawback is that those scripts will lack
whatever the optimization Informix does for EXEC SQL immediate versus
EXEC SQL PREPARE + EXEC SQL EXECUTE.
Anybody?
--
Gerardo Santana
More information about the Ruby-informix-misc
mailing list