On Wed, 2 Jun 2010 12:40:11 -0400, "Matthäus Kiem via RT"
<bug-DBD-CSV@rt.cpan.org> wrote:
Show quoted text> Thx, I tried know with a simpler example and it worked as expected.
> But with the example which I used in the first place I don't find the error.
> Could you say me where the error is?
Take back that last reply. I lost a space.
If you *create* your files with *open* instead of "create table", and
do not add the ".csv" extension" yourself, it looks as if it cannot
find the table. If you do add the csv extension on file creation, all
works fine (and a space was lost in the previous code)
--8<--- rt58039.pl
#!/pro/bin/perl
use strict;
use warnings;
use autodie;
use 5.012;
use Cwd;
use File::Spec::Functions;
use DBI;
my $dir = "rt58039";
-d $dir or mkdir $dir, 0777;
my @leftovers = glob "$dir/*";
@leftovers and unlink @leftovers;
my $file1 = catfile ($dir, "test_1.csv"); # with test_1.csv and test_2.csv it
my $file2 = catfile ($dir, "test_2.csv");
open my $fh, ">", $file1 or die $!;
say $fh "id,name";
say $fh "1,Brown";
say $fh "2,Smith";
say $fh "5,Green";
close $fh;
open $fh, ">", $file2 or die $!;
say $fh "id,city";
say $fh "1,Greenville";
say $fh "2,Watertown";
say $fh "8,Springville";
close $fh;
my $dbh = DBI->connect ("dbi:CSV:", undef, undef, {
RaiseError => 1,
PrintError => 1,
f_dir => $dir,
f_ext => ".csv",
});
my $table_1 = "test_1";
my $table_2 = "test_2";
eval {
my $sth_old = $dbh->prepare (
"SELECT a.id, a.name, b.city " .
"FROM $table_1 AS a NATURAL JOIN $table_2 AS b"
);
$sth_old->execute ();
my $table = "new";
$dbh->do ("DROP TABLE IF EXISTS $table");
$dbh->do ("CREATE TABLE $table (id INT, name CHAR (64), city CHAR (64))");
my $sth_new = $dbh->prepare (
"INSERT INTO $table (id, name, city) VALUES (?, ?, ?)");
say "id,name,city";
while (my $hash_ref = $sth_old->fetchrow_hashref ()) {
state $count = 1;
say $count++, ",", $hash_ref->{"a.name"}, ",", $hash_ref->{"b.city"};
$sth_new->execute ($count++, $hash_ref->{"a.name"}, $hash_ref->{"b.city"});
}
};
$@ and warn $@;
$dbh->disconnect ();
-->8---
=>
$ perl rt58039.pl
id,name,city
1,Brown,Greenville
3,Smith,Watertown
It might be a problem in DBD::File from DBI. We'll look into that and
add some tests to verify. Meanwhile I will close this bug somewhere
this week, as it is neither a DBD::CSV nor a SQL::Statement bug.
Thanks for sending the original report though. I'll mould it into
something simpler (not involving joins and as).
--
H.Merijn Brand
http://tux.nl Perl Monger
http://amsterdam.pm.org/
using 5.00307 through 5.12 and porting perl5.13.x on HP-UX 10.20, 11.00,
11.11, 11.23, and 11.31, OpenSuSE 10.3, 11.0, and 11.1, AIX 5.2 and 5.3.
http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/
http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/