[求助]DBD::Pg的奇怪错误
作数据插入的,用生成的SQL语句直接走pgadmin可以,但走DBI就报错。
Error executing SQL statement! at readSampLst.pl line 117, <$io> line 2.
(in cleanup) dbd_st_destroy called twice!, <$io> line 2.
DBI st handle 0x83b7404 has uncleared implementors data, <$io> line 2.
dbih_clearcom (sth 0x83b7404, com 0x83c38e8, imp DBD::Pg::st):
FLAGS 0x180113: COMSET IMPSET Warn PrintError PrintWarn
ERR 0
ERRSTR ''
PARENT DBI::db=HASH(0x83b7320)
KIDS 0 (0 Active)
NUM_OF_FIELDS -1
NUM_OF_PARAMS 0
程序:
#!/usr/bin/perl -w
use strict;
use warnings;
use Text::CSV_XS;
use Text::ParseWords;
use IO::Handle;
use DBI qw(:sql_types);
use DBD::Pg qw(:pg_types);
use constant ANNOTFILE =>'Sample_list.csv';
my $fileHead=`head -n 1 @{[ANNOTFILE]}`;
chomp $fileHead;
my @headArray=parse_line(',', 0, $fileHead);
my $tmp=0; # Keep this for tmp use !
for ( @headArray ) {
++$tmp;
print "$tmp : [$_] -> [\L$_]\n";
}
my %attr = (
RaiseError => 0,
PrintError => 1,
AutoCommit => 0
);
my $dbName='micarray';
my $DBI_DSN="dbi:Pg:dbname=$dbName";
my $dbh = DBI->connect($DBI_DSN, '', '',\%attr)
or die "Can't connect to database: $DBI::errstr\n";
my $csv = Text::CSV_XS->new ({
binary => 1,
});
open my $io, "<", ANNOTFILE;
my %DataLine;
my $count=0;
$csv->getline($io); # Skip the head.
while (my $row = $csv->getline($io)) {
my @fields = @$row;
++$count;
%DataLine=();
for (my $i=0; $i<=$#headArray; $i++) {
if ($fields[$i] ne '') {
$DataLine{$headArray[$i]}=$fields[$i];
}
}
$DataLine{DevelopmentalStagePO} = substr ( $DataLine{DevelopmentalStagePO}, 3);
$DataLine{PlantStructurePO} = substr ( $DataLine{PlantStructurePO}, 3);
my @dbKeys=map {lc $_} keys %DataLine;
mergeSQL (\@dbKeys,[values %DataLine]);
}
$dbh->commit();
$dbh->disconnect()
or warn "Disconnection failed: $DBI::errstr\n";
sub mergeSQL {
die 'ERROR: No \@keys and \@values specified !',"\n" if @_<2;
my ($refkeys,$refvals)=@_;
my $tableName='experi';
@$refvals = map{$dbh->quote($_)} @$refvals;
my $sql = "INSERT INTO $tableName ("
. join(", ", @$refkeys)
. ") VALUES ("
. join(", ", @$refvals)
. ")";
print STDERR "$sql\n";
my $query = $dbh->prepare($sql);
$query->execute or die("\nError executing SQL statement! $DBI::errstr");
}
|