- my $sth = $self->{fetch};
- $sth->execute or die $sth->errstr;
- my $result = $self->{fetch}->fetchall_arrayref( {} );
- $self->{buffer} = $result;
- scalar @$result;
+ if (driver_name() eq 'Pg') {
+ my $sth = $self->{fetch};
+ $sth->bind_param(1, $self->{position}) if driver_name() eq 'mysql';
+ $sth->execute or die $sth->errstr;
+ my $result = $self->{fetch}->fetchall_arrayref( {} );
+ $self->{buffer} = $result;
+ $self->{position} += $sth->rows;
+ scalar @$result;
+ } # mysql can't be refilled, since everything is buffered from the start
+}
+
+sub DESTROY {
+ my $self = shift;
+ return if driver_name() eq 'mysql';
+
+ return unless $self->{pid} eq $$;
+ $self->{dbh}->do('CLOSE '. $self->{id})
+ or die $self->{dbh}->errstr; # clean-up the cursor in Pg
+ if ($self->{autoclean}) {
+ # the dbh was created just for this cursor, so it has no transaction
+ # state that we care about
+ $self->{dbh}->rollback;
+ }