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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.