I swear this was working on another 'puter ... so I just made sure I updated DBD::CSV and SQL::Statement (both were already up to date according to 'cpan -i $module'). Perhaps someone can tell me where I'm going wrong. Here's what I have as a pared down example (which was originally in a Template Toolkit plugin). First, the data, which I put in a file called "mytable":

SORTORDER,POSITION,NAME,EMAIL 1,"First Position","Tanktalus","tanktalus -at- gmail.com"
Second, the code:
use DBI; use SQL::Statement; use DBD::CSV; use strict; use warnings; my $dbh; my $csv_dir = '.'; sub _dbh { $dbh ||= DBI->connect(qq{DBI:CSV:f_dir=$csv_dir;csv_eol=\n}, undef +, undef, {RaiseError => 1}); $dbh; } sub getme { #_dbh->{TraceLevel}=10; my $f = _dbh->selectall_arrayref(qq{select name from mytable where + position = ?}, {}, 'First Position'); $f = $f->[0] while ref $f; $f; } sub getme2 { #_dbh->{TraceLevel}=10; my $f = _dbh->selectall_arrayref(qq{select name from mytable where + sortorder = ?}, {}, 1); $f = $f->[0] while ref $f; $f; } print "SQL::Statement's version: ", $SQL::Statement::VERSION, $/; print "DBD::CSV's version: ", $DBD::CSV::VERSION, $/; print getme,$/; print getme2,$/;
Next, the output:
$ perl ./q.pl SQL::Statement's version: 1.15 DBD::CSV's version: 0.22 Use of uninitialized value in print at ./q.pl line 32. Tanktalus
And, finally, the expected output:
$ perl ./q.pl SQL::Statement's version: 1.15 DBD::CSV's version: 0.22 Tanktalus Tanktalus
So, selecting by comparing against the sort order (number) is working fine to pull out a string. But selecting against a string seems to be failing. I've tried a few variations without any luck - using "like ?" and 'F%', not using placeholders, etc. Since getme2 works, I have to assume that I'm at least calling stuff mostly correctly - it can find the CSV file, for example.

As you can tell, I've even tried the tracing, but I can't read a lick of it, so it didn't help me.

Thanks,

Update: Nevermind. I suppose "POSITION" is a keyword that has been (relatively) recently added to SQL::Statement's repertoire or something. Because it's not being parsed as a column header, but as something else. Changing it to "posit" works fine. The one thing I hadn't varied ...


In reply to DBD::CSV oddity? (solved) by Tanktalus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.