summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2014-03-25 21:27:40 -0700
committerIvan Kohler <ivan@freeside.biz>2014-03-25 21:27:40 -0700
commit90dd1d7c7a1b1d0c57c05a696f936df6247d98e3 (patch)
treebd4f53e229fa26914bd37cb74270fcc5241cd6d1 /FS
parent4289ed53f86f18d6107339db5b7cee38f64533c0 (diff)
close cursors on DESTROY, RT#26262
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Cursor.pm17
1 files changed, 10 insertions, 7 deletions
diff --git a/FS/FS/Cursor.pm b/FS/FS/Cursor.pm
index f3bc1e23d..24ebf5864 100644
--- a/FS/FS/Cursor.pm
+++ b/FS/FS/Cursor.pm
@@ -2,12 +2,11 @@ package FS::Cursor;
use strict;
use vars qw($DEBUG $buffer);
-use base qw( Exporter );
-use FS::Record qw(qsearch dbdef dbh);
-use Data::Dumper;
+use FS::Record qw(dbh);
use Scalar::Util qw(refaddr);
$DEBUG = 0;
+
# this might become a parameter at some point, but right now, you can
# "local $FS::Cursor::buffer = X;"
$buffer = 200;
@@ -53,9 +52,8 @@ sub new {
$self->{id} = sprintf('cursor%08x', refaddr($self));
my $statement = "DECLARE ".$self->{id}." CURSOR FOR ".$q->{statement};
- my $dbh = dbh;
- my $sth = $dbh->prepare($statement)
- or die $dbh->errstr;
+ my $sth = dbh->prepare($statement)
+ or die dbh->errstr;
my $bind = 0;
foreach my $value ( @{ $q->{value} } ) {
my $bind_type = shift @{ $q->{bind_type} };
@@ -64,7 +62,7 @@ sub new {
$sth->execute or die $sth->errstr;
- $self->{fetch} = $dbh->prepare("FETCH FORWARD $buffer FROM ".$self->{id});
+ $self->{fetch} = dbh->prepare("FETCH FORWARD $buffer FROM ".$self->{id});
$self;
}
@@ -101,6 +99,11 @@ sub refill {
scalar @$result;
}
+sub DESTROY {
+ my $self = shift;
+ dbh->do('CLOSE '. $self->{id}) or die dbh->errstr; # clean-up the cursor in Pg
+}
+
=back
=head1 TO DO