clueless newbie has asked for the wisdom of the Perl Monks concerning the following question:
Greetings!
I need to create a derived class (call it myDBI) using DBI as the base class so I can override a few methods in the example "do". (Okay, assume, just for fun, that I wish to log the sql statement.) I've tried:
package myDBI; use strict; use warnings; use DBI; our @ISA=("DBI"); use strict; use warnings; our $AUTOLOAD; sub AUTOLOAD { warn "$AUTOLOAD\n"; }; sub connect { ### @_ my $class=shift; my $self=DBI->connect(@_); bless $self; return $self; }; # connect sub do { my $self=shift; ### @_ $_[0]=~ s{\bdbi\b}{zdbi}i; ### @_ $self->SUPER::do(@_); }; # do 1;
Using the following for a test
#! use lib '.'; use DBI; use myDBI; use strict; use warnings; my $sql_s=<<'__EOCreate__'; CREATE TABLE dbi (JFF integer) __EOCreate__ my $Database_s='test.db'; my (%dbh_h,%sth_h); { # Connect to DBI and create a table $dbh_h{DBI}=DBI->connect("DBI:SQLite:$Database_s","","",{Raise +Error=>1,PrintError=>1,AutoCommit=>1,LongReadLen=>1024*1024}) or die "Can't connect to 'DBI:SQLite:$Database_s'!"; ### %dbh_h $dbh_h{DBI}->do($sql_s) or die $dbh_h{DBI}->errstr; { # Disconnect from the database $sth_h{$_}->finish() for (keys %sth_h); $dbh_h{$_}->commit() for (keys %dbh_h); $dbh_h{$_}->disconnect() for (keys %dbh_h); }; }; %dbh_h=(); %sth_h=(); { # Connect to myDBI and create a table $dbh_h{myDBI}=myDBI->connect("DBI:SQLite:$Database_s","","",{R +aiseError=>1,PrintError=>1,AutoCommit=>1,LongReadLen=>1024*1024}) or die "Can't connect to 'DBI:SQLite:$Database_s'!"; ### %dbh_h $dbh_h{myDBI}->do($sql_s) or die $dbh_h{myDBI}->errstr; { # Disconnect from the database $sth_h{$_}->finish() for (keys %sth_h); $dbh_h{$_}->commit() for (keys %dbh_h); $dbh_h{$_}->disconnect() for (keys %dbh_h); }; };
I get
C:\Code\Objects>perl Example_02.pl commit ineffective with AutoCommit enabled at Example_02.pl line 24. commit ineffective with AutoCommit at Example_02.pl line 24. Can't locate auto/myDBI/SUPER/do.al in @INC (@INC contains: . C:/Perl/ +site/lib C:/Perl/lib) at myDBI.pm line 29 myDBI::DESTROY
So how do I create a derived class from DBI?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Deriving a class from DBI.
by ikegami (Patriarch) on Mar 23, 2010 at 17:24 UTC | |
by clueless newbie (Curate) on Mar 23, 2010 at 18:14 UTC | |
by ikegami (Patriarch) on Mar 23, 2010 at 20:32 UTC | |
by clueless newbie (Curate) on Mar 24, 2010 at 12:13 UTC | |
|
Re: Deriving a class from DBI.
by Corion (Patriarch) on Mar 23, 2010 at 17:04 UTC | |
by clueless newbie (Curate) on Mar 23, 2010 at 18:18 UTC | |
|
Re: Deriving a class from DBI.
by mje (Curate) on Mar 23, 2010 at 17:19 UTC | |
by clueless newbie (Curate) on Mar 23, 2010 at 18:10 UTC | |
|
Re: Deriving a class from DBI.
by moritz (Cardinal) on Mar 23, 2010 at 19:35 UTC | |
|
Re: Deriving a class from DBI.
by merlyn (Sage) on Mar 24, 2010 at 02:16 UTC | |
by clueless newbie (Curate) on Mar 24, 2010 at 12:17 UTC |