
DBD::CSV with column names containing spaces
With a csv file that looks like
Order ID,Product ID,Description
7808,14008,Star Wars Edition 1
7009,15002,Sorry
I am unable to do a select on the Order ID column where the Order ID is 7808
#!/usr/bin/perl
use DBI;
my $dbh = DBI->connect("DBI:CSV:f_dir=.") or die "Can't connet";
$dbh->{csv_tables}->{generic} = { eol => "\n", file => 'generic.csv'};
my $query = qq[SELECT * FROM generic where 'Order ID' == 7808];
my $sth = $dbh->prepare($query);
$sth->execute();
while ( my ($row) = $sth->fetchrow_hashref )
{
last unless ( $row );
foreach my $keyval ( keys %{ $row } )
{
print "$keyval: $row->{$keyval}\n";
}
Quote:
}
$sth->finish;