Subclassing the Perl DBI, overwriting the database handler in the calling script upon disconnection -
i have problem:
pseudocode:
package a; @isa = qw(dbi); bundle a::db; @isa = qw(dbi::db); sub prepare{ #gets $dbh object, can overwrite upon disconnection #so calling script gets fresh , working dbh, #through $_[0] = $newdbh; } bundle a::st; @isa = qw(dbi::st); sub execute{ #gets $sth object can rescue upon disconnection #before execute, calling script have faulty $dbh } calling script:
use a; $dbh = a->connect; $sth = $dbh->prepare("select 1"); $dbh->disconnect; #i observe in execute function $sth->execute; #disconnect detected, reconnect -> reprepare , execute 1 time again #(is done in module a) = we're , running! is there way impact $dbh object without having phone call $dbh->prepare 1 time again in calling script?
my problem want seamlessly because want prepare database handling in many projects using new database module.
is @ possible?
or maybe create statement handler a::prepare part of ::db bundle well? in turn mean database handler a::connect have statement handler well, when utilize connect object access both prepare , execute. modify $_[0] in a::execute new dbh object, mean after reconnect in a::execute, calling script have valid $dbh. tried lot of ways of doing suspect inner magic of dbi making hard...
subclassing way create class behaves identically class refinements.
your a class (could think of worse identifier?) doesn't seem dbi, , i'm not surprised you're having difficulty expressing want in terms. sounds want a object have dbi connection, not be one.
so perhaps write
package a; utilize strict; utilize warnings; utilize dbi; sub connect { $self = {}; $self->{dbh} = dbi->connect(@_); $self; } where go here i'm not sure, you've described proposed solution rather problem itself
perl dbi
No comments:
Post a Comment