internal package Foswiki::Iterator::DBIterator
internal package Foswiki::Iterator::DBIterator is a Foswiki::Iterator
ClassMethod new($dbh, $select, $values, $process)
Constructs a
Foswiki::DBI::DBIterator object. Parameters are:
- $dbh: the database being used to connect to the actual database (mandatory)
- $select: SQL select clause that is being prepared using the $dbh (mandatory)
- $values: array reference of values being used when executing the statement; this must match the "?" placeholders in the select clause (optional)
- $process: function reference that is called when iterator fetched the next value from the database, see
next() below (optional)
A
DBIterator may be used in its own but is mostly created as part of
Foswiki::DBI::Database::eachRow().
Example use:
my $it = Foswiki::Iterator::DBIterator($dbh, "select * from ... where ...");
while ($it->hasNext) {
my $row = $it->next();
my $firstName = $row->{firstName};
my $middleName = $row->{middleName};
my $lastName = $row->{lastName};
...
}
ObjectMethod hasNext() → $boolean
returns true if the iterator still has values to be returened by
next().
ObjectMethod next() → $row
returns the next row available in the result set of the select statement.
The
$row return value is a hash reference as being created by
DBI::fetchrow_hashref
ObjectMethod count() → $integer
returns the number of rows affected by this iterator
ObjectMethod reset()
resets the iterator to restart the search to the beginning. note that the
select statement (provided to the constructor) will be prepared and executed
once again