RDBI / rdbi

rdbi is an attempt to rewrite the core of Ruby/DBI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#connect and #prepare block form invocation do not always release resources

pilcrow opened this issue · comments

Issue

Two related behaviors. First, when invoked with a block, Database#prepare does not #finish its block-scoped statement handle if the block throws an exception. Second, RDBI::connect does not #disconnect its block-scoped dbh at all.

This is inconsistent with ruby's "Resource Acquisition Is Initialization"/"Scope-Bounded Resource Management" behavior in analogous block-form methods.

Expected behavior

My expectation is that the block-form of these methods should always release any resources they acquire regardless of exceptions thrown in user code, like File::open {BLOCK}. (::connect_cached, however, and a hypothetical #prepare_cached, should not release resources at the end of the block, since their semantics involve a hidden pool of acquired resources.)

How to reproduce

rdbi-0.9.1

See test cases from pull request (coming shortly). Basically:
RDBI.connect(...) {|dbh| my_dbh = dbh; raise "Ka-Blam!"}
assert(! my_dbh.connected?)
and similarly for #prepare.

Sorry to have split this over two issues -- didn't realize pull request would open an issue.

This was resolved under issue #18