Method: DBI::BaseStatement#fetch_scroll

Defined in:
lib/dbi/base_classes/statement.rb

#fetch_scroll(direction, offset) ⇒ Object

fetch_scroll is provided with a direction and offset and works similar to how seek() is used on files.

The constants available for direction are as follows:

  • SQL_FETCH_NEXT: fetch the next result.

  • SQL_FETCH_LAST: fetch the last result, period.

  • SQL_FETCH_RELATIVE: fetch the result at the offset.

Other constants can be used, but if this method is not supplied by the driver, they will result in a raise of DBI::NotSupportedError.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/dbi/base_classes/statement.rb', line 100

def fetch_scroll(direction, offset)
    case direction
    when SQL_FETCH_NEXT
        return fetch
    when SQL_FETCH_LAST
        last_row = nil
        while (row=fetch) != nil
            last_row = row
        end
        return last_row
    when SQL_FETCH_RELATIVE
        raise NotSupportedError if offset <= 0
        row = nil
        offset.times { row = fetch; break if row.nil? }
        return row
    else
        raise NotSupportedError
    end
end