Skip to content

Add scrollable cursor support to StatementOptions#28

Merged
asfernandes merged 2 commits intoasfernandes:mainfrom
fdcastel:issue-25
Feb 19, 2026
Merged

Add scrollable cursor support to StatementOptions#28
asfernandes merged 2 commits intoasfernandes:mainfrom
fdcastel:issue-25

Conversation

@fdcastel
Copy link
Contributor

Add scrollable cursor support to StatementOptions

Fixes #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
Copy link
Contributor Author

Just pushed a new commit with the requested fixes. 👍🏻

@asfernandes asfernandes merged commit 2469207 into asfernandes:main Feb 19, 2026
4 checks passed
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

2 participants

Comments