Perl DBI and postgres

From: david(dot)best(at)sympatico(dot)ca
To: pgsql-general(at)postgresql(dot)org
Subject: Perl DBI and postgres
Date: 2005-07-28 14:05:23
Message-ID: 53350.205.210.232.62.1122559523.squirrel@www.cakeorations.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

This is probably just a general DBI question but I get the following
errors when I run my code:

DBD::Pg::st fetchrow_array failed: no statement executing at ./snap.pl
line 110.
DBD::Pg::st fetchrow_array failed: no statement executing at ./snap.pl
line 110.

Line 110 is a disconnect statement:

$target_dbh->disconnect();

I have multiple functions which access a target database, take the
information and put it back into a repository. They all follow this
format, the database handlers are passed in, statement handlers are
created and closed at the end of the function.

sub free_space {

my $err=0;
my ($repo_dbh, $target_dbh, $snap_id) = @_;
my $target_sth = $target_dbh->prepare(
q{ SELECT columns
FROM the table }) or "Can't prepare statement:
$DBI::errstr";
$target_sth->execute() or die $DBI::errstr;

while (my ($data) = $target_sth->fetchrow_array()) {
eval {
$repo_sth = $repo_dbh->prepare("INSERT into thetable
(columns)
VALUES (?, '$data')");
$repo_sth->execute($snap_id) or die $DBI::errstr;
};
}
# check for errors.. If there are any rollback
if ( $@ ) {
$err = 1;
}

$repo_sth->finish();
$target_sth->finish();

return $err;
}

The main function just opens connections to the repository and target
database and closes them at the end with disconnects and that is where the
error is occuring.

Any ideas?

Browse pgsql-general by date

  From Date Subject
Next Message Jaime Casanova 2005-07-28 14:19:02 Re: Trigger ad mutli database
Previous Message germ germ 2005-07-28 14:04:54 Re: problem inserting with sequence