projects
/
freeside.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
commissions on package margin, RT#24086
[freeside.git]
/
FS
/
FS
/
Cursor.pm
diff --git
a/FS/FS/Cursor.pm
b/FS/FS/Cursor.pm
index
6d02a16
..
d94151f
100644
(file)
--- a/
FS/FS/Cursor.pm
+++ b/
FS/FS/Cursor.pm
@@
-2,10
+2,11
@@
package FS::Cursor;
use strict;
use vars qw($DEBUG $buffer);
use strict;
use vars qw($DEBUG $buffer);
-use FS::Record qw(dbh);
+use FS::Record;
+use FS::UID qw(myconnect);
use Scalar::Util qw(refaddr);
use Scalar::Util qw(refaddr);
-$DEBUG =
0
;
+$DEBUG =
2
;
# this might become a parameter at some point, but right now, you can
# "local $FS::Cursor::buffer = X;"
# this might become a parameter at some point, but right now, you can
# "local $FS::Cursor::buffer = X;"
@@
-38,11
+39,13
@@
and returns an FS::Cursor object to fetch the rows one at a time.
sub new {
my $class = shift;
my $q = FS::Record::_query(@_); # builds the statement and parameter list
sub new {
my $class = shift;
my $q = FS::Record::_query(@_); # builds the statement and parameter list
+ my $dbh = myconnect();
my $self = {
query => $q,
class => 'FS::' . ($q->{table} || 'Record'),
buffer => [],
my $self = {
query => $q,
class => 'FS::' . ($q->{table} || 'Record'),
buffer => [],
+ dbh => $dbh,
};
bless $self, $class;
};
bless $self, $class;
@@
-55,8
+58,8
@@
sub new {
$self->{id} = sprintf('cursor%08x', refaddr($self));
my $statement = "DECLARE ".$self->{id}." CURSOR FOR ".$q->{statement};
$self->{id} = sprintf('cursor%08x', refaddr($self));
my $statement = "DECLARE ".$self->{id}." CURSOR FOR ".$q->{statement};
- my $sth = dbh->prepare($statement)
- or die dbh->errstr;
+ my $sth =
$
dbh->prepare($statement)
+ or die
$
dbh->errstr;
my $bind = 1;
foreach my $value ( @{ $q->{value} } ) {
my $bind_type = shift @{ $q->{bind_type} };
my $bind = 1;
foreach my $value ( @{ $q->{value} } ) {
my $bind_type = shift @{ $q->{bind_type} };
@@
-65,7
+68,7
@@
sub new {
$sth->execute or die $sth->errstr;
$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;
}
$self;
}
@@
-105,15
+108,12
@@
sub refill {
sub DESTROY {
my $self = shift;
return unless $self->{pid} eq $$;
sub DESTROY {
my $self = shift;
return unless $self->{pid} eq $$;
- dbh->do('CLOSE '. $self->{id}) or die dbh->errstr; # clean-up the cursor in Pg
+ $self->{dbh}->do('CLOSE '. $self->{id})
+ or die $self->{dbh}->errstr; # clean-up the cursor in Pg
+ $self->{dbh}->rollback;
+ $self->{dbh}->disconnect;
}
}
-sub DESTROY {
- my $self = shift;
- my $statement = "CLOSE ".$self->{id};
- dbh->do($statement);
-}
-
=back
=head1 TO DO
=back
=head1 TO DO