From: Brian C. <B.C...@po...> - 2003-03-31 14:07:59
|
I was writing some code like this: s = db.prepare("select bar from foo where baz=?") ... (1) s.execute(key) do |sth| result = sth.fetch end Unfortunately, I discovered that it doesn't work like that - the block is simply ignored. It also doesn't work like this: (2) t = s.execute(key) result = t.fetch After some poking around, it turns out that when you run 'execute' on a StatementHandle it returns an empty DBI::Row object. You have to do: (3) s.execute(key) result = s.fetch I think it would be nice to support the block format as in (1), which I think would only need 'yield self if block_given?' in the execute method. I think it would also be nice to return self rather than the empty DBI::Row, so that you can chain execute with other operations: result = s.execute(key).fetch What does anyone else think? It ought to be a simple change (the attached patch is untested though, as I need my app to work with the current API anyway) Regards, Brian. --- dbi.rb.orig Mon Mar 31 15:04:37 2003 +++ dbi.rb Mon Mar 31 15:05:23 2003 @@ -747,6 +747,11 @@ #if @row.nil? @row = DBI::Row.new(column_names,nil) #end + if block_given? + yield self + else + self + end end def finish |