[CDBI] Using One Class to connect to multiple instances and more.

Jeff Pelkey pelkey.jeff at gmail.com
Fri Mar 20 22:44:06 GMT 2009


Greetings,

I have been using CDBI for the past two plus years and really like it
simplicity and ease of use, especially in teaching our junior
programmers how to use it.  Up until now we haven't done anything all
that fancy and all the databases we use have been designed and created
by a modern database package like MySQL, Oracle, etc.  I have just
been appointed as the lead developer on a project to start migrating a
portion of our really old COBOL legacy program and the databases are
based on ISAM data files (from what I've been told) and (the database)
cannot be changed at this point until all the COBOL code is gone.  My
problem is that each store will have it's own table (that contains the
same schema), instead of one table that holds the data for all stores.
 This is also duplicated in the fact that we have multiple regions
with stores in each region with the same exact tables for each store.

Don't know if this will help:

 Region3                                 Region4
             Region5
    ...                                     /             \
                         ....
                                   Store1                Store2
                    Store_Detail_Store1      Store_Detail_Store2
              Store_Employees_Store1      Store_Employees_Store2
                         ....                                 ....

My question is this:  What is the best way to create one base to
connect to all the instances and one regular class for each table.
Then I just pass the region_id to the base class and have it connect
to that instance.  Plus access all the tables using a variable that
identifies each stores and connect to each table using that method?
Is this possible?  Or am I babbling incoherently and dragging a
shopping cart with me (Sorry, I have a very dry sense of humor!)

Example:


package Music::Artist;
use strict;
use base 'Music::MusicDB';

##########################################################

our $store_id;

sub get_store_id {
  $store_id = shift;  ## Not sure f the best way to pass this to the
regular class.

}
##########################################################

Music::Artist->table("artist_${store_id}"); Music::Artist->columns(All
=> qw/artistid name popularity/);

1;

I tried this and I get an error stating "Cannot locate object db_Main
on package 'XX::XX'.  I have done a search through the archives and
didn't see that looked like it fit the bill.

Any Ideas or do I just bite the bullet and create a base class for
each instance and a regular class for each store for that table?  It
seems like it should be possible, but I cannot/find how to do this
properly.

Cheers, Jeff.

PS - I guess this is my way of saying I still use CDBI.  ;^}



More information about the ClassDBI mailing list