I cannot get DBD::CSV & SQL::Statement to work correctly when there is
more than 1 column in the group by.
I have version 1.15 of SQL::Statement and version 0.22 of DBD::CSV.

I wonder if this is a known bug, or I am missing something, because
the docs for SQL::Statement show that it should be supported?

Example:
% cat > testData.csv
1,1,10
1,2,10
1,3,10
2,1,10
2,1,10
2,1,10

% cat > testdbdcsv.pl
#!/usr/bin/perl
use strict;
use warnings;
use DBI;

my $csvdb = DBI->connect( "dbi:CSV:" ) || die "Cannot connect: $DBI::errstr";
$csvdb->{'csv_tables'}->{'log'} = {
                                 'file' => "testData.csv",
                                 'eol'  => "\n",
                                 'col_names' => ["a","b","c"]
                             };
$csvdb->{'RaiseError'} = 1;
$@ = '';
eval {
    my $csth = $csvdb->prepare("SELECT a,b,sum(c) as tot from log
GROUP BY a,b");
    $csth->execute();
    while (my $row = $csth->fetchrow_hashref) {
        print " row: " . join(",",
                              $row->{'a'},
                              $row->{'b'},
                              $row->{'tot'},
                          ) . "\n";

    }
    $csth->finish();
};
if ($@) { warn "SQL database error: $@";}

$csvdb->disconnect;


% perl testdbdcsv.pl
 row: 2,1,40
 row: 1,2,10
 row: 1,3,10


Thanks,
John Krystynak

-- 
Amazon Prime Users - add my search tool to your Firefox search bar!
http://searchaprime.com <-- new URL!

Reply via email to