NAME

SQL::DB::Cursor - SQL::DB database cursor

SYNOPSIS

use SQL::DB::Cursor;

my $cursor = SQL::DB::Cursor->new(
    sth => $sth,
);

while (my $row = $cursor->next) {
    print $row->column(), $row->some_other_column;
}

# Or if you want you can get everything at once:
my @rows = $cursor->all;

DESCRIPTION

SQL::DB::Cursor is a class for traversing over records retrieved from a DBI statement handle. Note that this is a Perl-side cursor, completely unrelated to any database-side cursors you might have.

The objects returned by the 'next' and 'all' methods are simple ARRAY(ref) based objects with one accessor/modifer method per column. Method names are column names but with any spaces replaced by a '_'.

CONSTRUCTOR

new(sth => $sth)

Returns a new cursor object. $sth must be a DBI statement handle that has already been 'executed'.

ATTRIBUTES

sth -> DBI::st

The DBI statement handle. Read-only.

class -> Str

The class name into which retrieved rows are 'blessed'. This is automatically calculated based on the retrieved column names. Read-only.

METHODS

BUILD

Internal method.

next -> $row

Returns the next row from the statement handle as an object. Returns undef when there is no more data.

all -> @rows

Returns all remaining rows from the statement handle as a list of objects. Returns the empty list if no data is available.

finish

Calls finish() on the DBI statement handle and internally records that there is no more data to be retrieved. This method is automatically called when the cursor object goes out of scope, so be aware you cannot use the passed-in statement handle again.

SEE ALSO

DBI, SQL::DB

AUTHOR

Mark Lawrence <nomad@null.net>

COPYRIGHT AND LICENSE

Copyright (C) 2007-2011 Mark Lawrence <nomad@null.net>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.