[Dbix-class] Class::DBI vs DBIx and CDBICompat

Matt S Trout dbix-class at trout.me.uk
Mon Jun 26 19:21:40 CEST 2006

Steven Mackenzie wrote:
> Matt S Trout wrote:
>> Steven Mackenzie wrote:
>>> I stumbled upon this piece of documentation:
>>> http://search.cpan.org/~jrobinson/DBIx-Class-0.06003/lib/DBIx/Class/CDBICompat.pm
>>> Which suggests that I can start using DBIx::Class simply my making this
>>> change to my Class::DBI code:
>>> # In DBBase.pm
>>> #use base qw( Class::DBI ); # currently using 3.0.6 from ActiveState ppm.
>>> use base qw/DBIx::Class/; # currently 0.6000 from ActiveState pmm__PACKAGE__->load_components( qw/CDBICompat Core DB/ );
>>> However, I get this error at startup:
>>> Can't locate object method "set_db" via package "DBBase" at
>>> C:\xyz\InitDatabase.pm line 33.
>>> In my application I make the call to the Class::DBI method set_db via my
>>> DBBase.pm module, like this:
>>>  DBBase->set_db
>>>  (
>>>    'Main',
>>>    $dsn, # passed in by caller
>>>    $username,
>>>    $password,
>>>    {RaiseError => 1,
>>>     AutoCommit => 0, # Don't autocommit transactions
>>>     unicode => 1}
>>>  );
>>> How can I set the DBIx::Class DB connection?
>> Why can't you just call ->connection ?
> Because I thought that the Compat API was complete, and I don't know the
> DBIx::Class API.

The compat API is sufficiently complete to pass the Class::DBI test suite. 
->connection is also a Class::DBI method; set_db is part of the underlying 
Ima::DBI API, which CDBICompat does not emulate in full (hence being called 
CDBICompat, not ImaDBICompat :)

> I've tried replacing the DBBase->set_db() call with  a call to
> DBBase->connection(), but then I get this error the first time I try to
> use one of my CDBI classes:
> Can't call method "storage" on an undefined value at
> C:/Perl/site/lib/DBIx/Class/ResultSource.pm line 411.
> Has this every come up before? I didn't find anything in the mailing
> list archive ...

Without seeing more of your code I can't easily debug; my best guess would be 
you're calling that after the class tree's loaded rather than in the DBBase.pm 
file during use base.

      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +

More information about the Dbix-class mailing list