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!
In reply to Deriving a class from DBI. by clueless newbie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |