On 11/23/06 1:19 AM, [EMAIL PROTECTED] wrote:
> I was assuming that the "lazy man's approach" of using
> 
>     Rose::DB::Object::Loader->new(
>       db_dsn       => 'dbi:mysql:dbname=dbtest',
> 
> would already work the magic behind the scenes, since using a single
> connection is probably a common case.

The thing is, I'm not sure that's really the common case.  Also, sharing a
single $dbh across all RDBO classes tends to make transactions a bit odd.
(e.g., A commit anywhere is a commit everywhere! :)  The default behavior as
it exists is the "safest," even if it's not the most efficient.

> BTW, are these DB connections closed?

That's what I meant when I wrote this:

>> (In all of the above code, you should think about the eventual destruction
>> of those global objects.)

In the default case, with each object getting its own db, the database
connections are closed when the Rose::DB objects go out of scope (which
usually happens when their parent objects go out of scope).  Example:

    if(...)
    {
      my $p = My::Product->new(id => 123);
      $p->load; # New db object created with new $dbh
      ...do stuff with $p...
    }

    # $p goes out of scope here, and so does $p's db (assuming it wasn't
    # shared with any other objects in the block above)

When in doubt, you can turn on DBI->trace() to see when your DBI $dbh
handles are being created and destroyed.

-John
    



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to