[Dbix-class] using DBIx::Class::CDBICompat

Matt S Trout dbix-class at trout.me.uk
Tue May 22 16:59:59 GMT 2007


On Mon, May 21, 2007 at 05:19:05PM -0400, John Goulah wrote:
> I've read the cpan info on DBIx::Class::CDBICompat, but cant seem to get an
> actual working example going.  In particular I want the sth_to_objects
> method, which I believe is in the ImaDBI component. I'm perhaps complicating
> things further by loading the  ResultSetManager component so that I can
> execute and return a result set in my object.  I've tried making CDBICompat
> the base class, and also loading as a component.

Please next time ask on the list how to achieve your original aim first,
if you find yourself loading CDBICOmpat for anything other than its original
purpose you've started off down a rat hole and what you're attempting to
implement is almost certainly the wrong solution.
 
> So I have a function like:
> 
> sub get_some_data : ResultSet {
>    my ($self) = @_;
>    my $dbh = $self->result_source->schema->storage->dbh;
> 
>    my $sth = $dbh->prepare("select * from sometable");
>    $sth->execute();
> 
>    ##### this doesn't work, how do I  use this method?
>    return $self->sth_to_objects($sth);

You don't. That's a method on a resultset object, and the CDBICompat stuff
won't show up there - which is a good thing, since sth_to_objects it pretty
horrible since it's a COMPATIBILITY LAYER feature, not a DBIC feature.

How about

    my @results;
    while (my $hr = $sth->fetchrow_hashref) {
      push(@results,
        $self->result_class->inflate_result(
          $self->result_source, $hr, {}
        )
      );
    }
    return @results;

?
     
> }

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director    Want a managed development or deployment platform?
 Shadowcat Systems Ltd.  Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/             http://www.shadowcatsystems.co.uk/ 



More information about the Dbix-class mailing list