1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
package Tangram::Cursor::Data;
use strict;
use Carp;
sub open
{
my ($type, $storage, $select, $conn) = @_;
confess unless $conn;
bless
{
select => $select,
storage => $storage,
cursor => $storage->sql_cursor(substr($select->{expr}, 1, -1), $conn),
}, $type;
}
sub fetchrow
{
my $self = shift;
my @row = $self->{cursor}->fetchrow;
return () unless @row;
map { $_->{type}->read_data(\@row) } @{$self->{select}{cols}};
}
sub fetchall_arrayref
{
my $self = shift;
my @results;
while (my @row = $self->fetchrow)
{
push @results, [ @row ];
}
return \@results;
}
sub new
{
my $pkg = shift;
return bless [ @_ ] , $pkg;
}
sub DESTROY
{
my $self = shift;
$self->close();
}
sub close
{
my $self = shift;
$self->{cursor}{connection}->disconnect()
unless $self->{cursor}{connection} == $self->{storage}{db};
}
1;
|