I'm getting an error with DBD::CSV, although it's actually thrown by SQL::Statement:
DBD::CSV::st execute failed:
Execution ERROR: No such column 'PRINT."set"'.
[for Statement "
SELECT id,
gid,
card,
"set",
illus,
num
FROM Print
"] at problem.pl line 41.
SQL::Statement doesn't seem to recognize that "set" means set. Unfortunately, set must be quoted since it's a reserved word and SQL::Statement dies complaining of that fact when set is left unquoted.
Does anyone have any workarounds for this? Has this been fixed in a newer version? Looks like I'll have to first copy the CSV with different field names. Fortunately, the tool on which I am working is only used to import CSV into a "real database".
>perl -le"use SQL::Statement; print SQL::Statement->VERSION"
1.15
>perl -le"use DBD::CSV; print DBD::CSV->VERSION"
0.22
Code and data to reproduce:
673399.pl:
use strict;
use warnings;
use DBI qw( );
use File::Spec::Functions qw( catfile );
{
my $db = '.';
my $dsn = "dbi:CSV:f_dir=$db";
my $user = undef;
my $passwd = undef;
my $dbh = DBI->connect(
$dsn, $user, $passwd,
{
RaiseError => 1,
PrintError => 0,
PrintWarn => 1,
AutoCommit => 1, # No writing, so no need for
+transactions.
FetchHashKeyName => 'NAME_lc',
}
);
for (qw( Print )) {
my $path = catfile($db, "$_.csv");
# Xyz and "Xyz" are erroneously considered different tables.
$dbh->{csv_tables}{ $_ }{file} = $path;
$dbh->{csv_tables}{qq{"$_"}}{file} = $path;
}
my $sth = $dbh->prepare('
SELECT id,
gid,
card,
"set",
illus,
num
FROM Print
');
$sth->execute();
# ...
}
Print.csv:
id,gid,card,set,illus,num
1,1,1,1,"Foo Bar",1
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.