[ https://issues.apache.org/jira/browse/CALCITE-5443?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17650006#comment-17650006 ]
Julian Hyde edited comment on CALCITE-5443 at 12/20/22 10:18 PM: ----------------------------------------------------------------- I agree that this is a bug, but it took me a while to understand, because multiple results is a JDBC behavior that not many people use. I initially thought you were talking about {{ResultSet.next()}}. For the benefit of people not familiar with JDBC, in your description could you explain the purpose of {{getMoreResults}}, the lifecycle of update count, and why {{getMoreResults}} would change the update count? Your current summary describes the fix, not the problem. I think the following would be a better summary: "After Statement.getMoreResults() has returned false, Statement.getUpdateCount() should return -1" Does this problem apply to both {{getMoreResults()}} and {{getMoreResults(int)}}? was (Author: julianhyde): Javadoc says {quote} Retrieves the current result as an update count; if the result is a ResultSet object or there are no more results, -1 is returned. This method should be called only once per result. {quote} The way I read that, if my statement is a query, {{getUpdateCount}} should always return -1 because a query returns a {{ResultSet}}. > Reset update count when checking for more results > ------------------------------------------------- > > Key: CALCITE-5443 > URL: https://issues.apache.org/jira/browse/CALCITE-5443 > Project: Calcite > Issue Type: Bug > Components: avatica > Reporter: Gregory Hart > Assignee: Gregory Hart > Priority: Major > Time Spent: 10m > Remaining Estimate: 0h > > The JavaDoc for {{java.sql.Statement#getMoreResults(int)}} says there are no > more results when the following is true: > > {code:java} > // stmt is a Statement object ((stmt.getMoreResults(current) == false) && > (stmt.getUpdateCount() == -1)) {code} > In {{{}AvaticaStatement{}}}, {{getMoreResults(int)}} always returns {{false}} > but does not reset the {{{}updateCount{}}}. This could result in an infinite > loop in the JDBC client because the return value is indicating there are > additional results when there are actually none. > > *Steps to reproduce:* > # Execute an INSERT query by calling Statement#execute(String). Verify that > the return value is false indicating it is an update count. > # Call Statement#getMoreResults(). Verify that the return value is false > indicating it is an update count or there are no more results. > # Call Statement#getUpdateCount(). > *Expected results:* > The call to getUpdateCount() returns -1 indicating there are no more results. > *Actual results:* > The call to getUpdateCount() returns the update count for the INSERT query, > which should only have one result. -- This message was sent by Atlassian Jira (v8.20.10#820010)