Subject: | same select second time returns no data |
While helping on IRC with a problem I found a bug in DBD::CSV.
Attached is simplified version of program that had this problem.
Second time no rows are returned.
--
Alexandr Ciornii, http://chorny.net
Subject: | dbd_csv_bug.pl |
#!/usr/bin/perl
use warnings;
use strict;
use DBI;
require DBD::CSV;
my $csv_file = 'test_data.csv';
unless (-r $csv_file) { die "ERROR:\tCannot read $csv_file:$!\n"; }
my $csv = init_csv($csv_file);
my @courses = get_courses();
print @courses, "\n\n";
my @courses2 = get_courses();
print @courses2, "\n\n";
sub get_courses {
my @names;
my $sth = $csv->prepare("SELECT DISTINCT colnm from golfdata");
$sth->execute;
while (my @row = $sth->fetchrow_array) {
push(@names, $row[0]);
}
$sth->finish();
return @names;
}
sub init_csv {
my $file = shift @_;
my $dbh = DBI->connect("dbi:CSV:f_dir=.;csv_eol=\n;") or die "Cannot connect to CSV files: $DBI::errstr\n";
$dbh->{'csv_tables'}->{'golfdata'} = {'file' => $file}; # Give the CSV (used a table name) a friendly name
$dbh->{RaiseError} = 1;
return $dbh;
}
Subject: | test_data.csv |
colnm
bbb
ccc