I've worked with the DBI some, but I'm now starting to experiment with DBD::CSV. I'm
trying to read a table without
column headers, letting CSV create the column names for me. If I understand the
documentation correctly, an empty array
reference should cause the driver to name the columns for me. When I do that, I get
an error:
Execution ERROR: Couldn't find column names!.
If I go ahead and assign the column names, it seems to work fine. I'm wondering if I
have misunderstood the DBD::CSV
documentation, or if I've just a remedial Perl problem (like, do I know what an array
ref is?).
Thanks for any help.
Jeff
Here's my details:
=============================
ActivePerl Build 631 (5.6)
DBD::CSV 0.2002
SQL::Statement 1.005
DBI 1.32
=============================
#!d:/perl/bin/perl -w
#
# Test for experimenting with DBD::CSV
use strict;
require DBI;
my $DBS_FILE = '\\\\\\\\server\\\\subdir\\\\tabledir';
my $DBS_DRIVER = "DBI:CSV:f_dir=$DBS_FILE";
my ($dbh) = DBI->connect("$DBS_DRIVER;csv_sep_char=\\;"
. ";csv_eol=\012" );
my (@list) = $dbh->func('list_tables');
foreach (@list)
{
print "$_\n";
$dbh->{'csv_tables'}->{$_} = { 'col_names' => ["A", "B", "C"] };
# Above statement works, but the one below doesn't
# $dbh->{'csv_tables'}->{$_} = { 'col_names' => [] };
my ($querry) = "SELECT * FROM $_";
my ($sth) = $dbh->prepare( $querry );
$sth->execute();
while (my $row = $sth->fetchrow_hashref)
{
foreach my $key (sort (keys %$row))
{
print "$key: $row->{$key}\n";
}
}
$sth->finish();
}
$dbh->disconnect();