| DBIx-Connection documentation | Contained in the DBIx-Connection distribution. |
DBIx::QueryCursor - Database cursor handler
use DBIx::QueryCursor;
my $cursor = new DBIx::QueryCursor(
connection => $connection,
sql => "SELECT * FROM emp WHERE ename = ?"
);
my $result_set = $cursor->execute(['Smith']);
if($cursor->fetch()) {
$ename = result_set->{ENAME};
... do some stuff
}
or
use DBIx::Connection;
my $cursor = $connection->query_cursor(
sql => "SELECT * FROM emp WHERE ename = ?"
);
Class that represents database cursor.
Fetch resultset.
Number of rows retrieved since last execution.
Function return list of column from current cursor
Executes statements, takes bind parameters as ARRAY ref, optionaly resul set as reference(HASH, SCALAR, ARRAY) Returns result set.
Returns the cursor itarator, on each iteration database error is checked. For instance sub query returned more then error exception is capture here.
Move cursor to next result. Returns true if a row was fetched or false if no more results exist.
Signals that the cursor will not be used again.
The DBIx::QueryCursor module is free software. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
Adrian Witas, adrian@webapp.strefa.pl
| DBIx-Connection documentation | Contained in the DBIx-Connection distribution. |
package DBIx::QueryCursor; use warnings; use strict; use Abstract::Meta::Class ':all'; use Carp 'confess'; use base 'DBIx::SQLHandler'; use vars qw($VERSION); $VERSION = 0.03;
has '$.result_set';
has '$.rows';
sub columns { my ($self) = @_; \@{$self->sth->{NAME_lc}} }
sub execute { my ($self, $bind_params, $result_set) = @_; $result_set ||= {}; $self->set_result_set($result_set); $self->finish if $self->rows; $self->SUPER::execute(@$bind_params); $self->bind_columns($result_set); $self->set_rows(0); $result_set; }
sub iterator { my ($self) = @_; my $sth = $self->sth; my $dbh = $self->connection->dbh; sub { my $result = $sth->fetch(); $self->set_rows($self->rows + 1); confess $self->error_handler if $dbh->errstr; $result; }; }
sub fetch { my ($self) = @_; my $dbh = $self->connection->dbh; my $has_result = $self->sth->fetch; $self->error_handler if $dbh->errstr; $self->set_rows($self->rows + 1); $has_result ? (wantarray ? @$has_result : $has_result) : (); }
sub finish { my ($self) = @_; $self->sth->finish if $self->sth; } 1; __END__