Jonathan Leffler > DBD-Informix-2005.02 > examples/fetchscroll.pl

Download:
DBD-Informix-2005.02.tar.gz

Annotate this POD

CPAN RT

New  3
Open  3
View Bugs
Report a bug
Source   Latest Release: DBD-Informix-2007.0226

"Scroll cursors"

        $sth->setattr(SQL_STMT_CURSOR_ATTR, SQL_CURSOR_SCROLL);
        $sth->execute([@vals]);

The $sth->execute method is the familiar function, but the $sth->setattr function (which is modelled after the ODBC function SQLStmtSetAttr()) is new. If the DBMS being accessed by the driver does not support scroll cursors (determined via $dbh->getinfo(...)) or the driver has not implemented the interface to the feature, then you will get a default implementation (emulation) of scroll cursors shown above. When $sth->setattr() is called, it ensures that $sth->execute creates a scroll cursor for the statement, which must be one that returns values ($sth->{NUM_OF_FIELDS} > 0).

    $row = $sth->fetchrow_scroll_arrayref($move, $offset);
    @row = $sth->fetchrow_scroll_array($move, $offset);
        $ref = $sth->fetchrow_scroll_hashref($move, $offset);

These methods can be used to fetch rows of data via a statement that was executed with $sth->execute_scroll. (Optionally: if the $move is 'next', then the fetchrow_scroll_* methods map to the corresponding regular fetchrow_* method;any $move other than 'next' is rejected.) The acceptable values of $move are:

    'next'      == equivalent to 'relative' +1
    'prev'      == equivalent to 'relative' -1
    'current'   == equivalent to 'relative'  0
    'first'     == equivalent to 'absolute'  1
    'last'      == equivalent to 'absolute'  N (N = total rows)
    'relative'  == equivalent to 'absolute'  C + $offset (C = current)
    'absolute'

The value of $offset is only relevant for 'relative' and 'absolute'; it is ignored for other $move values, but should be set to zero. For $move of 'absolute', the value of $offset should be a positive (non-negative) number, and it should be smaller than the number of rows in the result set. For $move of 'relative', the value of $offset can be positive or negative or zero and the magnitude should be smaller than the number of rows in the result set.

Previously fetched rows are cached (possibly in the server, possibly in the client). When a row is to be fetched, if it is already in the cache, it is returned from the cache. If it is not already in the cache, then the row is fetched from the database (caching result rows as necessary). If the row turns out not to exist, then 'undef' is returned. Fetches before the first row return undef; fetches after the last row return undef. The current position is then one space out of range, and an appropriate relative fetch (or an absolute fetch) is needed to collect values again.