Skip to content

Fix ArrayResultSet after-last cursor state - #3142

Open
fallintoplace wants to merge 1 commit into
ClickHouse:mainfrom
fallintoplace:fix-array-result-set-after-last
Open

fallintoplace wants to merge 1 commit into
ClickHouse:mainfrom
fallintoplace:fix-array-result-set-after-last

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary

What

  • Move a non-empty ArrayResultSet to after-last when next() returns false.

Why

  • The cursor stayed on the last row after exhaustion.
  • isAfterLast(), isLast(), getRow(), and previous() could report the wrong state.

Implementation

  • Set pos to length on non-empty exhaustion.
  • Keep empty arrays before-first.
  • Add regression coverage for the cursor state and moving back to the last row.

Closes: #3143

@CLAassistant

CLAassistant commented Sep 18, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@fallintoplace
fallintoplace force-pushed the fix-array-result-set-after-last branch from 0ee63e3 to 98d38c8 Compare September 18, 2026 21:56
@Override
public boolean next() throws SQLException {
if (pos + 1 >= length || length == 0) {
if (length > 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the problem not only for nonEmpty arrays.

@chernser chernser left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct for all cases - documentation says that next() should progress unconditionally. And when next() returns false - result set should be in state AfterLast

Moves the cursor forward one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.
When a call to the next method returns false, the cursor is positioned after the last row. Any invocation of a ResultSet method which requires a current row will result in a SQLException being thrown. If the result set type is TYPE_FORWARD_ONLY, it is vendor specified whether their JDBC driver implementation will return false or throw an SQLException on a subsequent call to next.

@chernser

Copy link
Copy Markdown
Contributor

@fallintoplace

Thank you for the contribution!

@fallintoplace
fallintoplace force-pushed the fix-array-result-set-after-last branch from 98d38c8 to 132d511 Compare September 18, 2026 23:39
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.

[jdbc-v2] Fix ArrayResultSet after-last cursor state

3 participants