Rules for Positioning the Scrollable Cursor

There are rules that govern the position of the cursor in fetch_orientation options when you are fetching the cursor rows, where cursPos is the cursor position.

See the fetch_orientation

These terms used in rules for positioning the scrollable cursor are:
  • curRowsetStart – the cursor’s current position.

  • new_CurRowsetStart – the new current position of the cursor.

  • total_rows – the total number of rows in the cursor result set.

  • before_first – the row position before the first row of the cursor result set. This variable has a value of 0.

  • after_last – the row position after the last row of the cursor result set. This variable has a value of total_rows + 1.

  • first_row – the position at the first row of the cursor result set. This variable has value of 1.

  • last_row – the position at the last row of the cursor result set. This variable has the same value as total_rows.

  • fetchSize – the number of rows requested for each fetch operation.

RuleDescription
Fetch first

The new_CurRowsetStart always moves to first_row, regardless of the position of CurRowsetStart and the value of fetchSize.

Fetch last
  • If total_rows >= fetchSize, then new_CurRowsetStart = total_rowsfetchSize + 1.

  • If total_rows < fetchSize, then new_CurRowsetStart is on first_row.

Fetch next
  • If CurRowsetStart is before_first, then new_CurRowsetStart is on first_row.

  • Let curPos = (CurRowsetStart + fetchSize),
    • curPos <=total_rows, then new_CurRowsetStart = curPos

    • curPos > total_rows, new_CurRowsetStart is after_last

  • If CurRowsetStart is after_last row, then new_CurRowsetStart remains on after_last.

Fetch prior
  • new_CurRowsetStart is before_first when one of these conditions is true:
    • (CurRowsetStart >= 1) && (CurRowsetStart - fetchSize <=0)

    • CurRowsetStart is before_first

  • Let curPos = CurRowsetStartfetchSize; iff 1 <=curPos <=total_rows, then new_CurRowsetStart = curPos.

  • If (CurRowsetStart is after_last), let curPos = total_rowsfetchSize + 1 new_CurRowsetStart = curPos if curPos > 0 new_CurRowsetStart is before_first if curPos <= 0

Fetch relative
  • If (CurRowsetStart is before_first) && (fetch_offset > 0), then new_CurRowsetStart = fetch_offset.

  • new_CurRowsetStart is before_first if one of these conditions is true:
    • (CurRowsetStart is before_first) and (fetch_offset < 0)

    • (CurRowsetStart is on first_row) and (fetch_offset < 0)

    • (CurRowsetStart is after_last)              and ((CurRowsetStart + fetch_offset + 1) <= 0)

  • If (1 < CurRowsetStart <= total_rows), let curPos = CurRowsetStart + fetch_offset, then:
    • new_CurRowsetStart is on first_row iff              (curPos < 1) and abs (fetch_offset) <= fetchSize

    • new_CurRowsetStart is before first_row iff              (curPos < 1) && (abs (fetch_offset) fetchSize)

    • new_CurRowsetStart = curPos iff (0 < curPos <=total_rows)

    • new_CurRowsetStart is after_last iff curPos > total_rows

  • If (CurRowsetStart is after_last), let curPos = CurRowsetStart + fetch_offset +1, then:

    • new_CurRowsetStart = curPos iff 1 <= curPos <= total_rows

    • new_CurRowsetStart is before_first iff curPos <= 0

    • new_CurRowsetStart is after_last iff curPos > total_rows

Fetch absolute
  • If fetch_offset = 0, new_CurRowsetStart is before_first

  • If fetch_offset > total_rows, new_CurRowsetStart is after_last

  • If 0 < fetch_offset <= total_rows, new_CurRowsetStart = fetch_offset

  • If (fetch_offset < 0) && (abs (fetch_offset) > total_rows),                               let abs_offset = abs (fetch_offset)                  new_CurRowsetStart is before_first iff abs_offset > fetchSize                  new_CurRowsetStart is on first_row iff abs_offset <= fetchSize

  • If (fetch_offset < 0) && (abs (fetch_offset) <= total_rows)                  new_CurRowsetStart = total_rows + fetch_offset + 1