[Dbix-class] Problem getting data from resultset

Kenneth S Mclane ksmclane at us.ibm.com
Mon Jul 9 20:31:36 GMT 2012


Patrick Meidl <patrick at pantheon.at> wrote on 07/09/2012 03:12:07 PM:

> Subject:
> 
> Re: [Dbix-class] Problem getting data from resultset
> 
> On Mon, Jul 09 2012, John Romkey <romkey at romkey.com> wrote:
> 
> > On Jul 9, 2012, at 12:27 PM, Kenneth S Mclane wrote:
> > >         while (my @data = $sr->next) { 
> > 
> > The problem is this line of code.
> 
> that's correct. this expression will always evaluate to TRUE, so the
> loop won't finish and your code will croak after scalar($st->all)
> iterations.
> 
> > Try:
> > 
> > while( my $data_scalar = $sr->next )  {
> >       my @data = $data_scalar->all;
> 
> that's wrong, though. DBIx::Class::Resultset->next already returns your
> result row, so the code should be:
> 
> while (my $data = $sr->next) {
>     # call accessors on your Accountv object
>     ...
> }
> 
> HTH
> 
>     patrick
That did the trick Patrick, thank you. It seems I was way over 
complicating it. Here is the working code for posterity:

while ( my $data = $sr->next )  { 
                foreach my $field (@fields) {
                        my $val = $data;
                        foreach my $method (split(/\./, $field)) {
                                $val = $val->$method;
                        }
                $ws->write($row, $col, $val);
                $col++;
                }
        $col=0;
        $row++;
        }
Now I am going to see if I can switch back to my regular rs, but not on 
this one. I like the idea of walking down to the relationship accessor so 
it is truly just one function that handles whatever you throw at it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120709/a873fea7/attachment.htm


More information about the DBIx-Class mailing list