On Thu, Apr 19, 2007 at 10:35:16AM -0400, John Siracusa wrote:
> On 4/18/07, Bill Moseley <[EMAIL PROTECTED]> wrote:
> > This works fine in my base class:
> >
> >     sub init_db { our $DBH =|| App::RDB->new }
> >
> > I've got the same $dbh for the life of the program.
> >
> > But, I'd like to try using DBI->connect_cached directly.
> 
> What's your goal?  Do you still want just one $dbh for the life of the 
> program?

Yes.  But, also one that supports pinging the database and creating a
new handle if the connection is dropped.


> 
> >     sub init_db {
> >         ...
> >         my $dbh = DBI->connect_cached( @params );
> >         return App::RDB->new( dbh => $dbh );
> >     }
> >
> > Where @params does not change between calls.  I then get a new $dbh.
> > for new RDBO objects.
> >
> > So, I'm not seeing how to correctly do this.
> 
> Shouldn't DBI->connect_cached return the same $dbh every time it's
> called?  If so, then in the code above you're returning a new App::RDB
> object each time, but all those App::RDB objects are sharing a single
> $dbh.  Is that not what you want?

DBI->connect_cached should, but I assume what's happening is RDBO is
issuing a disconnect forcing a new handle to be created.


> 
> Here's another variant:
> 
>     our $DB;
> 
>     sub init_db
>     {
>       return $DB  if($DB);
>       ...
>       my $dbh = DBI->connect_cached(@params);
>       return $DB = App::RDB->new(dbh => $dbh);
>     }

No, I don't think that's it.  What if the $dbh connection is lost?
DBI->connect_cached will create a new connection in that case.

-- 
Bill Moseley
[EMAIL PROTECTED]


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to