Tanktalus has asked for the wisdom of the Perl Monks concerning the following question:

Update 2: Nevermind. After deleting a bunch of modules from /usr/lib/perl5/site_perl and reinstalling them, it now works. <sigh>

This has me a bit baffled... I suppose the best way to explain it is an example. Here is my "database", in a file called "MyTable":

COLA,COLB,VALUE foo,bar,1 baz,bar,2
And the code:
#!/usr/bin/perl use strict; use warnings; use DBI; use Data::Dumper; my $dbh = DBI->connect(qq{DBI:CSV:f_dir=.;csv_eol=\n}, undef, undef, { +RaiseError => 1}); my $sth = $dbh->prepare('SELECT VALUE FROM MyTable WHERE COLA = ? AND +COLB = ?'); $sth->execute('baz', 'bar'); my @r = $sth->fetchrow_array(); print Dumper \@r;
If I run this, I get:
$ perl ./csvtest.pl $VAR1 = [];
And yet if I change 'baz' to 'foo', I get:
$ perl ./csvtest.pl $VAR1 = [ '1' ];
In the example, I'm expecting to get a '2', but that's not what I'm getting.

Any clues?

DBD::CSV, Text::CSV_XS, SQL::Statement all seem to be at the latest available...

(Apparently, I use CSV files for databases too much :->)

Update:

$ perl -MDBI -e 'DBI->installed_versions' Perl : 5.008008 (i686-linux-thread-multi) OS : linux (2.6.16-gentoo-r12) DBI : 1.58 DBD::mysql : 4.005 DBD::Sponge : 12.008696 DBD::SQLite : 1.13 DBD::Proxy : 0.2004 DBD::Multiplex : 1.98 DBD::Gofer : 0.009560 DBD::File : 0.35 DBD::ExampleP : 12.009532 DBD::DBM : 0.03 DBD::CSV : 0.22 $ perl -MSQL::Statement -le 'print $SQL::Statement::VERSION' 1.15 $ perl -MText::CSV_XS -le 'print $Text::CSV_XS::VERSION' 0.32
(Not sure what other levels may be pertinent...)

Replies are listed 'Best First'.
Re: Oddity with CSV query
by Corion (Patriarch) on Oct 30, 2007 at 15:38 UTC

    It works for me:

    X:\>perl -MDBI -e "DBI->installed_versions" Perl : 5.008008 (MSWin32-x86-multi-thread) OS : MSWin32 (5.1) DBI : 1.58 DBD::Sponge : 12.008696 DBD::SQLite : 1.13 DBD::Proxy : install_driver(Proxy) failed: Can't locate RPC/PlC +lient.pm in @INC DBD::Gofer : 0.009560 DBD::File : 0.35 DBD::ExampleP : 12.009532 DBD::DBM : 0.03 DBD::CSV : 0.22

    I have two guesses:

    • The last line does not have a newline character and thus doesn't get processed Tested and it prints "2"
    • The last line of a file is never processed

    This is on Windows, with \r\n as line endings, but that should be OK.

Re: Oddity with CSV query
by naikonta (Curate) on Oct 30, 2007 at 16:11 UTC
    It works just fine, out of the box. I remove the newline character from the last line, it prints 2. I convert to \r\n and it still prints 2. I port it to mysql, guess what.... it prints 2.
    $ perl -MDBI -e 'DBI->installed_versions' Perl : 5.008008 (i386-linux-thread-multi) OS : linux (2.6.9-34.elsmp) DBI : 1.53 DBD::mysql : 4.001 DBD::Sponge : 11.10 DBD::SQLite : 1.13 DBD::Proxy : install_driver(Proxy) failed: Can't locate RPC/PlC +lient.pm in @INC DBD::Pg : 1.49 DBD::Mock : 1.34 DBD::InterBase : 0.46 DBD::File : 0.35 DBD::ExampleP : 11.12 DBD::DBM : 0.03

    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!