Re: "Dynamic" database handles?

[prev] [thread] [next] [Date index for 2005/01/23]

From: Perrin Harkins
Subject: Re: "Dynamic" database handles?
Date: 00:50 on 23 Jan 2005
Daniel Collis Puro wrote:

> Well,  I came up with:
> 
> ##########
> 
> package OOPC::DB;
> 
> use base 'Class::DBI';
> 
> our $dbh;
> 
> sub db_Main{
>     return $dbh;
> }
> 
> #CDBI package definitions here.
> 1;
> 
> And then in my CGI::Application module:
> 
> package OOPC::Settings::Manage;
> use strict;
> use warnings;
> use OOPC::DB;
> 
> use base 'CGI::Application';
> 
> sub setup{
>     my $self=shift;
>     my $dbh=$self->param('dbh');
>     $OOPC::DB::dbh=$dbh;
>     $self->start_mode('list_namespaces');
> 
> $self->mode_param($self->param('settings')->{Global}->{run_mode_param});
>     $self->run_modes(
> 		     list_namespaces=>'list_namespaces',
> 		     is_denied=>'is_denied',
> 		     AUTOLOAD=>'list_namespaces'
> 		    );
> }
> 
> 1;

This will probably work, but I agree it doesn't look very nice.  It 
would probably be cleaner to just have an accessor method for getting a 
$dbh, and call that from db_Main:

sub db_Main {
     my $dbh = MyUtil->get_dbh();
     return $dbh;
}

This gets called a lot, so make sure it's fast, and make sure that you 
set all the same parameters in your database handle that Class::DBI 
does, or you will run into trouble.

The other way to deal with this is to simply have a way to get the 
database connection info and set that by calling OOPC::DB->connect(). 
Then you can access that handle from anywhere else by calling 
OOPC::DB->db_Main().  The info does not have to be set at compile-time; 
you just need to set it before accessing the database.

- Perrin

(message missing)

"Dynamic" database handles?
Daniel Collis Puro 23:44 on 22 Jan 2005

Re: "Dynamic" database handles?
Matt S Trout 00:20 on 23 Jan 2005

Re: "Dynamic" database handles?
Daniel Collis Puro 00:39 on 23 Jan 2005

Re: "Dynamic" database handles?
Jason Gessner 00:47 on 23 Jan 2005

Re: "Dynamic" database handles?
Perrin Harkins 01:04 on 23 Jan 2005

Re: "Dynamic" database handles?
William McKee 16:03 on 24 Jan 2005

Re: "Dynamic" database handles?
Dana Hudes 16:17 on 24 Jan 2005

Re: "Dynamic" database handles?
jason 18:59 on 24 Jan 2005

Re: "Dynamic" database handles?
Michael Graham 19:01 on 24 Jan 2005

Re: "Dynamic" database handles?
Perrin Harkins 00:50 on 23 Jan 2005

Re: "Dynamic" database handles?
jason 19:24 on 24 Jan 2005

Re: "Dynamic" database handles?
Michael Graham 21:39 on 24 Jan 2005

Generated at 17:42 on 27 Jan 2005 by mariachi v0.52