Hello, included is a patch that adds the function set_internal_handle().
From the POD:
"set_internal_handle" $rc = $sth->set_internal_handle( $sth2 );
Makes a statement handle internally point to the same structures as
another statement handle. In essence, both statement handles become
one and can be used interchangeably. This is useful for subclassing
DBI. For example:
sub execute { my $sth = shift; ... if (! $rc = $sth->SUPER::execute) { my $dbh = DBI->connect(...); my $sth2 = $dbh->prepare( $sql ); $rc = $sth2->SUPER::execute; $sth->set_internal_handle( $sth2 ); } return $rc; }
In the above example, from the point of view of the caller nothing
out of the ordinary happened. Simply doing:
$sth = $sth2;
will not work as $sth will get its scope localized. Once the sub-
classed "execute" returns, $sth will revert to its pre-execute
state. "set_internal_handle" properly handles this issue.
Note that since "set_internal_handle" makes two statement handles
point to the same internal structures, the following:
$sth->set_internal_handle( $sth2 ); $sth2->finish;
also finishes $sth.
=======
There is one potential problem that I haven't yet dug into. When using DBD::ExampleP, I get "DBI handle 0x185a248 cleared whilst still active" when I 'finish' or kill $sth or $sth2 after $sth->set_internal_handle( $sth2 ).
This doesn't happen on DBD::Sybase, on which I did most of my testing.
The patch was tested under Perl v5.8.1-RC3 built for darwin-thread-multi-2level (default under OSX 10.3.4).
Henri
set_internal_handle.patch
Description: Binary data