Hi,
I want to create a 'Database' class which is a layer on top of Win32::OLE and also uses some other packages (see example).
Goal is to modify the behaviour of some methods, while all other Win32::OLE database-methods will be inherited and used as if Win32::OLE was called directory.
I don't exactly know how to do it.
I guess I lack knowledge of polymorphism/inheritance, bu do not have the time to learn that now. please help!
Thanx in advance
Rgds,
John
package Database;
use 5.008;
use strict;
use warnings;
use Win32::OLE::Variant; # For timestamp readings
use Win32::ADO qw/CheckDBErrors/; # For ADO errorchecking
use base 'Win32::OLE'; # Inherit from 'Win32::OLE'
our $VERSION = '0.01';
# Local functions
sub _dbconnect {
# Create database connection
my $conn = CreateObject Win32::OLE "ADODB.Connection" || die "Crea
+teObject: $!";
$conn->Open("<some DSN to a MSSQL database>");
return $conn;
}
# Constructor
sub new {
my $class = shift;
( bless {}, $class )->_init( {@_} );
}
sub _init($) {
my ($self, $args) = @_;
$self->{_dbh} = _dbconnect();
$self;
}
# This method should replace the Win32::OLE 'Execute' method and add e
+rrorchecking to it. (doesn't work now!)
sub Execute {
my ($self, $sql) = shift;
my $rs = $self->{_dbh}->Execute($sql);
my @dberrors = ();
CheckDBErrors($self->{_dbh}, \@dberrors) or croak "SQL Failed at ",
+ __LINE__, "\n", @dberrors;
return ($rs);
}
1;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.