[Dbix-class] Problem getting data from resultset

Kenneth S Mclane ksmclane at us.ibm.com
Thu Jul 5 18:27:46 GMT 2012


I had it working earlier and went down so many rabbit holes I lost track 
of what I had working. I came up with the same solution as Rob just 
suggested to get my headers, and am using that list to get the data, as 
soon as I remember the syntax I used.

        my $wb = 
Spreadsheet::WriteExcel->new('/opt/catalyst/dbms/lib/dbms/output/output.xls');
        my $ws = $wb->add_worksheet('Output');
        my $col = 0; my $row = 0;
        my @fields = qw/ department.department_code account_code 
account_name account_policy compliance.percent_compliant 
metrics.num_servers metrics.num_subsystems progress.percent_complete /;
>This part works, I get my header row.
        foreach my $field (@fields) {
                $ws->write($row, $col, $field);

                $col++;
        }
        $col=0;
        $row++;
>This doesn't, I get an error that it can't locate the method, I tried 
"$ws->write($row, $col, $data->{$field)};" and I get no errors but no 
data. I also tried removing the arrow, but then it thinks I have an 
undeclared hash.
        foreach my $data ($sr->all) {
                foreach my $field (@fields) {
                        $ws->write($row, $col, $data->$field);

                        $col++;
                } 
                $row++;
                $col=0;
        }

Len Jaffe <lenjaffe at jaffesystems.com> wrote on 07/05/2012 12:59:15 PM:

> From:
> 
> Len Jaffe <lenjaffe at jaffesystems.com>
> 
> To:
> 
> "DBIx::Class user and developer list" <dbix-class at lists.scsys.co.uk>
> 
> Date:
> 
> 07/05/2012 01:03 PM
> 
> Subject:
> 
> Re: [Dbix-class] Problem getting data from resultset
> 
> 

> On Thu, Jul 5, 2012 at 1:53 PM, Kenneth S Mclane <ksmclane at us.ibm.com> 
wrote:
> Yes, I can get the data that way, but I have to specify each column 
> by name that way and I am trying to get this to be a bit more re-
> usable. I need to be able to use this on many different pages, 
> supplying a function that doesn't need to be embedded and custom 
> hard coded for each query. I am looking to be able to first, grab 
> the names of the columns so I can write the header row, then write 
> the data, save the file and offer it up to the browser to be saved. 
> I can't find a way to get a list of the field names from the result 
> set, that would work as I could then store them in vars and then 
> loop through using the column names to get the values for each cell. 
> 
> How are you specifying the names of the columns to the query?
> 
> -- 
> lenjaffe at jaffesystems.com   614-404-4214             
www.volunteerable.net
> Proprietor: http://www.theycomewithcheese.com/ - An Homage to Fromage
> Greenbar: Grubmaster: 2012-2009, Grub Asst: 2008, Trained: 2007.
> 
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: 
http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120705/074bd3dd/attachment.htm


More information about the DBIx-Class mailing list