| Posted on 2009-12-16 07:15:05-08 by dgesiem |
| DBI::DBD::CSV Unable to manage an extra field separator at the end of the file. |
|
Hello,
I used to read some CSV file through a DBI interface.
Those CSV files contains an extra field separator at the end of the line.
With DBI::DBD::CSV 0.35 a "select * from ... " on the table would return all fields including an empty field, corresponding to the extra colomn without exception. Adding the field separator to the csv_eol had no effects, but as no exception was raised it was usable for my purpose.
With the new version, it seems that the csv_eol is not taken into account, and produces an exception whatever is indicated in the csv_eol.
I may have filter the extra field separator, but I would have prefered to work directly with the CSV module, without extra scripts.
May be I am doing thing wrong ? Could you help ?
If not :
I would have suggested that the DBD CSV module includes an option to ignore colomns without field name in the first line.
Here after a sample program that shows the Pb.
#!/usr/local/bin/perl
use DBI ;
DBI->installed_versions;
my $dbh=DBI->connect ( "DBI:CSV:","", "", {
f_dir=>".",
csv_eol=>";\n",
eol=>"\n",
csv_quote_char=>"'",
csv_sep_char=>";"
}
)
or die "pb connect" . $DBI::errstr;
print "********* with ; at end\n";
my $sql_request = $dbh->prepare ("select * from tutu1.csv");
$sql_request->execute() or die "execute sql_request /ko sur la $ptrtable->{traitement} $ptrtable->
+{name} : ".$sql_request->errstr();
while(my @row_array = $sql_request->fetchrow_array()) {
print "(".join(' :::: ',@row_array) . ")\n";
}
The table tutu1.csv :
AIG_ID;NUM_AIG_ZTR;
SW_A_731;0;
SW_A_732;1;
The sample program execution :
Old configuration :
#./toto.pl
Perl : 5.008008 (sun4-solaris)
OS : solaris (2.8)
DBI : 1.602
DBD::mysql : install_driver(mysql) failed: Can't load '/usr/local/lib/perl5/site_perl/5.8.8/
+sun4-solaris/auto/DBD/mysql/mysql.so' for module DBD::mysql: ld.so.1: toto.pl: fatal: libmysqlclie
+nt.so.15: open failed: No such file or directory at /usr/local/lib/perl5/5.8.8/sun4-solaris/DynaLo
+ader.pm line 230.
at (eval 20) line 3
Compilation failed in require at (eval 20) line 3.
Perhaps a required shared library or dll isn't installed where expected
at ./toto.pl line 4
DBD::Sybase : 1.02
DBD::Sponge : 12.010002
DBD::Proxy : install_driver(Proxy) failed: Can't locate RPC/PlClient.pm in @INC
DBD::Pg : 1.49
DBD::Gofer : 0.010103
DBD::File : 0.35
DBD::ExampleP : 12.010007
DBD::DBM : 0.03
DBD::CSV : 0.22
********* with ; at end
(SW_A_731 :::: 0 :::: )
(SW_A_732 :::: 1 :::: )
New configuration :
Perl : 5.008008 (sun4-solaris)
OS : solaris (2.10)
DBI : 1.609
DBD::Sybase : 1.02
DBD::Sponge : 12.010002
DBD::Proxy : install_driver(Proxy) failed: Can't locate RPC/PlClient.pm in @INC
DBD::Gofer : 0.011565
DBD::File : 0.37
DBD::ExampleP : 12.010007
DBD::DBM : 0.03
DBD::CSV : 0.25
********* with ; at end
DBD::CSV::st execute failed: Can't call method "column" on an undefined value at /usr/local/lib/per
+l5/site_perl/5.8.8/SQL/Statement/Term.pm line 190, <GEN0> line 2.
[for Statement "select * from tutu1.csv"] at ./toto.pl line 19.
execute sql_request /ko sur la : Can't call method "column" on an undefined value at /usr/local
+/lib/perl5/site_perl/5.8.8/SQL/Statement/Term.pm line 190, <GEN0> line 2.
Regards |
| Direct Responses: Write a response |