Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inheriting DBI problem

Status
Not open for further replies.

Corwinsw

Programmer
Sep 28, 2005
117
BG
Hi, somebody tried inheriting DBI?
Code:
package Test::TMYDBI;

our @ISA    = qw(DBI);
use base 'DBI';

sub execute {
        my($this) = shift;
        print "test";
        return $this->SUPER::execute();
}
I get the following error:
Code:
DBI subclasses 'Test::TMYDBI::db' and ::st are not setup, RootClass ignored at scripts/ttestdbi.pl line 9code]


Corwin
 
Oh my goodness. I need to read the manuals more carefully...

Code:
By default $dbh = DBI->connect(...) returns a $dbh blessed into the DBI::db class. And the $dbh->prepare method returns an $sth blessed into the DBI::st class (actually it simply changes the last four characters of the calling handle class to be ::st).

The leading 'DBI' is known as the 'root class' and the extra '::db' or '::st' are the 'handle type suffixes'. If you want to subclass the DBI you'll need to put your overriding methods into the appropriate classes. For example, if you want to use a root class of MySubDBI and override the do(), prepare() and execute() methods, then your do() and prepare() methods should be in the MySubDBI::db class and the execute() method should be in the MySubDBI::st class.

Corwin
 
Nice to see you solved it yourself.
And doubly nice that you posted the solution.
[thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top