Skip to content

Add scrollable cursor support to StatementOptions - #2

Closed
fdcastel wants to merge 2 commits into
mainfrom
issue-25
Closed

Add scrollable cursor support to StatementOptions#2
fdcastel wants to merge 2 commits into
mainfrom
issue-25

Conversation

@fdcastel

Copy link
Copy Markdown
Owner

Add scrollable cursor support to StatementOptions

Fixes asfernandes#25

Summary

Statement now supports opening scrollable cursors via a new CursorType option in StatementOptions. Previously, cursors were always opened with flag 0 (forward-only), which meant the scrollable fetch methods (fetchPrior, fetchFirst, fetchLast, fetchAbsolute, fetchRelative) would silently fail even though they were already exposed in the API.

Changes

Statement.h

  • New CursorType enum with FORWARD_ONLY (default) and SCROLLABLE values.
  • StatementOptions gains getCursorType() / setCursorType() with fluent API.
  • Statement stores a cursorFlags member, initialized from StatementOptions in the constructor. The move constructor transfers it.

Statement.cpp

  • Constructor: when CursorType::SCROLLABLE is set, stores IStatement::CURSOR_TYPE_SCROLLABLE in cursorFlags.
  • execute(): passes cursorFlags (instead of hard-coded 0) to openCursor().

src/test/ScrollableCursor.cpp (new)

Seven test cases:

  • Default cursor type is FORWARD_ONLY
  • Scrollable cursor supports fetchFirst
  • Scrollable cursor supports fetchLast
  • Scrollable cursor supports fetchPrior
  • Scrollable cursor supports fetchAbsolute
  • Scrollable cursor supports fetchRelative
  • Forward-only cursor works correctly with default options

Usage

// Scrollable cursor
Statement select{attachment, transaction, "select col from t order by col",
    StatementOptions().setCursorType(CursorType::SCROLLABLE)};
select.execute(transaction);
select.fetchLast();     // jump to last row
select.fetchFirst();    // jump back to first row
select.fetchAbsolute(3); // jump to row 3
select.fetchRelative(-1); // move back one row
// Forward-only cursor (default — unchanged behavior)
Statement select{attachment, transaction, "select col from t"};
select.execute(transaction);
while (select.fetchNext()) { /* ... */ }

Backward Compatibility

This is a non-breaking, additive change. The default cursor type is FORWARD_ONLY, preserving existing behavior. No existing API signatures are modified.

Add CursorType enum (FORWARD_ONLY, SCROLLABLE) and expose it through
StatementOptions::setCursorType(). When SCROLLABLE is set, openCursor()
passes IStatement::CURSOR_TYPE_SCROLLABLE so that fetchPrior, fetchFirst,
fetchLast, fetchAbsolute and fetchRelative work correctly.

The default remains FORWARD_ONLY, preserving existing behavior.

Fixes asfernandes#25
@fdcastel fdcastel closed this Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No Scrollable Cursor Support

1 participant