Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by PrincessofPERL (Initiate)
on Jun 17, 2014 at 18:37 UTC ( #1090189=note: print w/ replies, xml ) Need Help??


in reply to Re: 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

Hi Merijn, Thanks for your reply. The version of PERL that I have to work with is perl5 (revision 5 version 10 subversion 1) configuration: ActivePerl Build 1007 291969:Compiled at Jan 27 2010 14:12:21 . . There is now some error in referencing the hashref to print to output

Use of uninitialized value in concatenation (.) or string at .. line 5 +5.
Here is my revised code
use warnings; use strict; use DBI; # Create connection string to database point.csv my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { f_ext => ".csv/r", f_encoding => "utf-8", }); my $sth = $dbh->prepare ("select * from point where ID_DEVTYP like 'IN +TELI%' AND ID_POINT like 'AUTO%'"); $sth->execute; # Create AFS CSV with Columns open (DAT_OUTPUT,">AFS.csv"); print DAT_OUTPUT "RECORD,SUBSCRIPT,ID_SUBSTN,CO_SUBSTN,AREA_SUBSTN,ID_ +DEVTYP,ID_DEVICE,NAME_DEVICE,AREA_DEVICE,ID_MEAS,ID_POINT,SITE_POINT, +AREA_POINT\n"; # Cycle through SQL results on ROW basis and print to AFS CSV file while (my $row = $sth->fetchrow_hashref) { print DAT_OUTPUT "$row->{RECORD},$row->{SUBSCRIPT},$row->{ID_SUB +STN},$row->{CO_SUBSTN},$row->{AREA_SUBSTN},$row->{ID_DEVTYP},$row->{I +D_DEVICE},$row->{NAME_DEVICE},$row->{AREA_DEVICE},$row->{ID_MEAS},$ro +w->{ID_POINT},$row->{SITE_POINT},$row->{AREA_POINT}\n"; } # Close file close DAT_OUTPUT;


Comment on Re^2: DBD::CSV::st execute failed. No such file or directory at C:/Perl64/lib/DBD/File.pm line 565
Select or Download Code
Re^3: DBD::CSV::st execute failed. No such file or directory at C:/Perl64/lib/DBD/File.pm line 565
by poj (Priest) on Jun 17, 2014 at 20:26 UTC
    Because you have SELECT * .. the column names in the hash are probably lower case. You can add a print join " ", keys %$row line to check this. To fix it I would define the column names in the SELECT and use fetchrow_array like this
    #!perl use warnings; use strict; use DBI; my @col = qw(RECORD SUBSCRIPT ID_SUBSTN CO_SUBSTN AREA_SUBSTN ID_DEVTYP ID_DEVICE NAME_DEVICE AREA_DEVICE ID_MEAS ID_POINT SITE_POINT AREA_POINT); my $cols = join ",",@col; # Create connection string to database point.csv my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { f_ext => ".csv/r", f_encoding => "utf-8", }); my $sth = $dbh->prepare ("SELECT $cols FROM point WHERE ID_DEVTYP LIKE 'INTELI%' AND ID_POINT LIKE 'AUTO%'"); $sth->execute; # Create AFS CSV with Columns open DAT_OUTPUT,'>','AFS.csv' or die "Could not open AFS.csv : $!"; print DAT_OUTPUT $cols."\n"; # Cycle through SQL results on ROW basis and print to AFS CSV file while (my @row = $sth->fetchrow_array) { print DAT_OUTPUT (join ",",@row)."\n"; } # Close file close DAT_OUTPUT;
    poj
      Thank you for your response. Here is a Challenge Your code works in v5.10.1 Binary build 1007 291969 but not Binary build 1006 291086 My former code worked in Build 1006 but not 1007. point.csv does exist.. in the same directory Here is my error message.. still peculiar to a file open issue. The File.pm is ~2009 on the 1007 build and ~2008 on the 1006 build.
      C:\....>afs_filter.pl Execution ERROR: Cannot open point: No such file or directory at C:/P +erl64/lib/DBD/File.pm line 579. . DBD::CSV::st fetchrow_array failed: Attempt to fetch row without a pre +ceeding execute() call or from a non-SELECT statement [for Statement +"SELECT RECORD,SUBSCRIPT,ID_SUBSTN,CO_SUBSTN,AREA_SUBSTN,ID_D EVTYP,ID_DEVICE,NAME_DEVICE,AREA_DEVICE,ID_MEAS,ID_POINT,SITE_POINT,AR +EA_POINT FROM point WHERE ID_DEVTYP LIKE 'INTELI%' AND ID_POINT LIKE + 'AUTO%'"] at C:\....afs_filter.pl line 53.
      Any ideas? Thanks
        It is extremely rare that the "binary build" matters ; Its the module versions that matter; upgrade; see what you use with Devel::VersionDump
Re^3: DBD::CSV::st execute failed. No such file or directory at C:/Perl64/lib/DBD/File.pm line 565
by Tux (Monsignor) on Jun 18, 2014 at 06:19 UTC

    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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1090189]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2014-09-22 14:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (196 votes), past polls