http://www.perlmonks.org?node_id=1090258


in reply to Re^2: DBD::CSV::st execute failed. No such file or directory at C:/Perl64/lib/DBD/File.pm line 565
in thread DBD::CSV::st execute failed. No such file or directory at C:/Perl64/lib/DBD/File.pm line 565

f_ext was added in DBI-1.608 and DBD::CSV-0.25, so that should work. f_encoding however was added in DBI-1.611, so that will not.

You did not mention the version of SQL::Statement, which is the SQL parser for DBD::CSV and essential for almost any statements more complicated than select foo from bar;. You use LIKE.

If you want to use literal key names, you can almost never rely on its casing the way you do. You should tell DBI explicitly to return your key names in upper case or lower case when using fetchrow_hashref. Better yet, do not rely on this at all

The case insensitiveness for table names should work as of DBD::CSV-0.25, so you should be safe there too.

Use a CSV module to output your data!

use warnings; use strict; use DBI; use Text::CSV_XS; # Create connection string to database point.csv my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { # CSV specific attributes f_ext => ".csv/r", f_encoding => "utf-8", # DBI attributes RaiseError => 1, PrintError => 1, ChopBlanks => 1, ShowErrorStatement => 1, FetchHashKeyName => "NAME_uc", # You want uc (I prefer lc) }); my $sth = $dbh->prepare ("select * from point where ID_DEVTYP like 'IN +TELI%' AND ID_POINT like 'AUTO%'"); $sth->execute; my @columns = @{$sth->{NAME_uc}}; # Create AFS CSV with Columns my $csv = Text::CSV_XS->new ({ binary => 1, eol => "\r\n" }); open my $fh, ">", "AFS.csv" or die "AFS.csv: $!"; $csv->print ($fh, \@columns); # Cycle through SQL results on ROW basis and print to AFS CSV file while (my $row = $sth->fetchrow_hashref) { $csv->print ($fh, [ @{$row}{@columns} ]); } # Close file close $fh;

With Text::CSV_XS-1.07 you can even simplify that to:

use Text::CSV_XS qw( csv ); : : my $sth = $dbh->prepare ("select * from point where ID_DEVTYP like 'IN +TELI%' AND ID_POINT like 'AUTO%'"); $sth->execute; csv (out => "AFS.csv", in => sub { $sth->fetchrow_hashref });

Enjoy, Have FUN! H.Merijn
  • Comment on Re^3: DBD::CSV::st execute failed. No such file or directory at C:/Perl64/lib/DBD/File.pm line 565
  • Select or Download Code