Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResultSet.isBeforeFirst returns true if result set is empty #807

Closed
gabrieleciech opened this issue May 27, 2024 · 4 comments
Closed

ResultSet.isBeforeFirst returns true if result set is empty #807

gabrieleciech opened this issue May 27, 2024 · 4 comments

Comments

@gabrieleciech
Copy link

I have recently upgraded my driver from jaybird 4.0.9 to 5.0.4 and I found a different behaviour for the ResultSet.isBeforeFirst method call when the result set is empty.

In version 4.0.9 the method correctly returns false if the query has no rows in the result set, instead in version 5.0.4 it returns true. In this way we no longer have the possibility of understanding whether a result set is empty or not.

It seems that this change was made while developing support for server-side scrolling in #693, by changing the initialization value of the variable isBeforeFirst in FbStatementFetcher

As a test query you can use:

SELECT 1 as myvar 
FROM rdb$database 
WHERE 1=0

and you get a different result executing the following code by changing the driver

var conn = DriverManager.getConnection(url, user, pass);
var stmt = conn.createStatement();
var query = "SELECT 1 as myvar FROM rdb$database WHERE 1=0"

ResultSet rs = stmt.executeQuery(strSQL);
if(!rs.isBeforeFirst()) {
    System.out.println("Result set is empty");
} else {
    System.out.println("Result set with records");
}
@mrotteveel
Copy link
Member

Thanks for reporting. I'll need to double check why I changed this. I guess I did it for consistency with the scrollable fetch, but the JDBC specification indeed says it should report false when the result set is empty.

@mrotteveel
Copy link
Member

To be front-ported to Jaybird 6 as well.

@mrotteveel
Copy link
Member

The value of isAfterLast() also incorrectly reported true for an empty result set after calling next()

@mrotteveel
Copy link
Member

Behaviour in Jaybird 4 was inconsistent and depended on the result set type and concurrency.

mrotteveel added a commit that referenced this issue Jun 8, 2024
mrotteveel added a commit that referenced this issue Jun 8, 2024
ResultSet.isBeforeFirst()/isAfterLast() should always report false for an empty result set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants