in reply to Problem creating a singleton wrapper around DBI

Your immediate problem is that DBI::connect() returns a DBI::db object, not a DBI object, so your subclass does not inherit from the right class.

You don't need inheritance for this to work though. Take out all of the @ISA code and change the last few lines of new() to:

# Connect return DBI->connect( $datasource, $dbuser, $dbpass );

If you do that, the caching will still work as long as all of your code calls the instance() method. (If it were my code, I would rename new() to connect() or something similar to make it more clear that this is a singleton factory.)

Replies are listed 'Best First'.
Re^2: Problem creating a singleton wrapper around DBI
by brian_d_foy (Abbot) on Aug 23, 2005 at 03:56 UTC

    Before you return the object, you have to store it in the singleton holder:

    $oneTrueSelf = DBI->connect ( $datasource, $dbuser, $dbpass ); # some error checking to ensure you have an object ... return $oneTrueSelf;

    If you run into other problems, check out how Apache::DBI does it.

    --
    brian d foy <brian@stonehenge.com>

      Good followup, thanks.

      I've updated the code to test for errors as you suggest, and work as directed.

      All is well now.

      Steve
      --