cielavenir

Extending Ruby DBI

Aug 31st, 2012
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.46 KB | None | 0 0
  1. module DBI
  2.     class << self
  3.         def connect_transaction(driver_url, user=nil, auth=nil, params=nil, &block)
  4.             x=connect(driver_url, user, auth, params)
  5.             begin
  6.                 x.transaction(&block)
  7.             ensure
  8.                 x.disconnect
  9.             end
  10.         end
  11.     end
  12.     class DatabaseHandle
  13.         def execute_immediate(stmt,*bindvars,&block)
  14.             sth=execute(stmt,*bindvars)
  15.             ret=0
  16.             begin
  17.                 if block then ret=sth.map(&block).count end
  18.             ensure
  19.                 sth.finish
  20.             end
  21.             ret
  22.         end
  23.     end
  24. end
Advertisement
Add Comment
Please, Sign In to add comment