>
> Your code blurb below is warning about subroutine redefinition
> because what
> appears to be an attempt at a function prototype is actually a function
> definition. I generally don't use function prototypes in Perl.
>
> Your code blurb below is failing because you are not exporting
> your CSAdmin
> package. You may want to do something like this in your package...
>
> require Exporter;
> our @ISA = qw(Exporter);
> our @EXPORT = qw(GetDBHandle someotherfunction yetanotherfunction etc)

Have tried this:

require Exporter;
my @ISA = qw(Exporter);
my @EXPORT = qw(GetDBHandle);


but still getting
Undefined subroutine &main::GetDBHandle called at testcsadmin.pl line 7.

The offending line being:

my $dbh = GetDBHandle('SMS');

I'm sure I'm just missing something obvious here but as yet no joy.

>
> Something else to think about is what level of abstraction you want to
> achieve. In some code I did, I decided I didn't want to have to mess with
> any of the DBI stuff, so I buried all of it a package, much like you are
> doing. However, I didn't even want to touch the database handle.
> So, I made
> wrapper routines inside the package and made the database handle private.
> This resulted in calls like this in my top-level script...
>
> connect_to_my_sales_dbase($username, $password) || die.
> my query_string = "SELECT * FROM sales_figures...";
> my %recs = query_sales($query_string);
>
> I made the package handle all of the dbase manipulation particulars. The
> most my top-level script needed to know was the wrapper names and how to
> write a few SQL query or ddl strings.
>
> The package itself must "use DBI" and whatever DBD you need.
>

I have thought about this and wondered whether to keep the dbh hidden. My
worry was then I wouldn't know exactly what was happening with different
handles. I am using SQL Server 2000 and there is an issue with multiple
statements per connection which I thought might make things confusing also.
The other advantage with explicitly declaring my dbh and passing it back and
forth is that it amkes the migration process from existing code with the db
stuff in the main easier as it doesn't matter if I mix it up.

I will try abstracting it more when I have had time to experiment a bit
more.

If it is easy to pass the dbh back to main and use it like this then that
will be great but I can't get on to the interesting bit as I am stuck on the
exporting! Time for a coffee...

Thanks
Mark


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to