Thread: dbd:pg finish() bug

dbd:pg finish() bug

From
Vivek Khera
Date:
The DBD::Pg driver doesn't properly reset "Active" state when all data
from a handle is fetched, as specified in the DBI docs under the
description of finish().

This program should not report any warnings with the finish() method
commented out.  It however, complains about an active handle during
the destroy.

The sample database is below.

--cut here--
#! /usr/bin/perl
use strict;

use DBI;

&main();

sub main {
  my $dbh = DBI->connect('dbi:Pg:dbname=khera','khera',undef,{PrintError=>1})
    or die "dbi connect failure: ".$DBI::errstr;

  my $sth = $dbh->prepare('select a,b from t1')
    or die $dbh->errstr;

  $sth->execute();
  while (my ($a,$b) = $sth->fetchrow_array()) {
    print "a=$a, b=$b\n";
  }

  print 'active:',$sth->{Active},"\n";
  # finish is not necessary according to DBI...
  $sth->finish();
  print 'active:',$sth->{Active},"\n";

  print "--------\n";

  $dbh->disconnect();
}
--cut here--


CREATE TABLE "t1" (
        "a" integer,
        "b" integer
);
COPY "t1"  FROM stdin;
1       2
2       3
3       4
\.