Tanktalus has asked for the wisdom of the Perl Monks concerning the following question:
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":
Second, the code:SORTORDER,POSITION,NAME,EMAIL 1,"First Position","Tanktalus","tanktalus -at- gmail.com"
Next, the output: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,$/;
And, finally, the expected 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
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.$ perl ./q.pl SQL::Statement's version: 1.15 DBD::CSV's version: 0.22 Tanktalus Tanktalus
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 ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBD::CSV oddity? (solved)
by jZed (Prior) on Mar 20, 2006 at 20:01 UTC |