So I'm trying to figure out the best approach, when creating the object TABLE, should I put the database handler in as one of it's attributes in the new method call, and use that or everytime I use a method/sub routine of TABLE should I pass in the database handle as a parameter?
I usually create a module that does the database
connections and a few other housekeeping chores and
then I create modules that are derivitaves of that
one. Example:
package dbObject;
my is_connected=0; # important...
my $dbh=undef;
sub connect {
| connection foo here...
}
sub prepare {
my ($self,$sql) = @_;
if ( ! is_connected)
$self->connect;
$self->{sth} = $dbh->prepare(....);
}
1;
package myTable;
use vars qw / @ISA /;
use dbObject;
@ISA = qw/ dbObject /;
#etc.
1;
and I have variations on that theme that I use. Lately
rather than use
DBI for my database layer I use
Class::DBI::Loader which further encapulates
the databse layer for me using a similar method where I
have a "parent" class instantiate the loader
and the "child" classes inherit it from there.
In fact I'm working on a major project now that uses
that methodology and other than some interesting bugs
I've discovered in the way
Class::DBI::Loader
reacts to certain table names I've not had any problems.
Hope this helps...
UPDATE:Special thanks to GrandFather for pointing out my fat-fingering
Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
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.