Skip to content

Commit b0b978a

Browse files
committed
Fixed incorrect getUpdateCount after getMoreResults
1 parent ef3707a commit b0b978a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

jdbc/src/main/java/tech/ydb/jdbc/impl/BaseYdbStatement.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,13 @@ public int getResultSetConcurrency() {
297297
protected static class ResultState {
298298
private final List<YdbResultSet> results;
299299
private int resultSetIndex;
300-
private final int updateCount;
301300

302301
private ResultState() {
303302
results = null;
304303
resultSetIndex = -1;
305-
updateCount = -1;
306304
}
307305

308306
private ResultState(List<YdbResultSet> list) {
309-
updateCount = (list == null || list.isEmpty()) ? 1 : -1; // TODO: Get update count?
310307
results = list;
311308
resultSetIndex = 0;
312309
}
@@ -315,8 +312,9 @@ public boolean hasResultSets() {
315312
return results != null && !results.isEmpty();
316313
}
317314

315+
// TODO: YDB doesn't return the count of affected rows, so we use little hach to return always 1
318316
public int getUpdateCount() {
319-
return updateCount;
317+
return (results != null && results.isEmpty() && resultSetIndex == 0) ? 1 : -1;
320318
}
321319

322320
public YdbResultSet getCurrentResultSet() throws SQLException {
@@ -336,6 +334,7 @@ public YdbResultSet getResultSet(int index) throws SQLException {
336334

337335
public boolean getMoreResults(int current) throws SQLException {
338336
if (results == null || results.isEmpty()) {
337+
resultSetIndex = -1; // reset updateCount
339338
return false;
340339
}
341340

jdbc/src/test/java/tech/ydb/jdbc/impl/YdbStatementImplTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,13 @@ public void getUpdateCount() throws SQLException {
378378

379379
statement.execute(TEST_UPSERT1_SQL);
380380
Assertions.assertEquals(1, statement.getUpdateCount());
381+
Assertions.assertFalse(statement.getMoreResults());
382+
Assertions.assertEquals(-1, statement.getUpdateCount());
381383

382384
statement.execute(TEST_UPSERT1_SQL + ";\n" + TEST_UPSERT2_SQL + ";");
383385
Assertions.assertEquals(1, statement.getUpdateCount()); // just a single statement
386+
Assertions.assertFalse(statement.getMoreResults());
387+
Assertions.assertEquals(-1, statement.getUpdateCount());
384388

385389
statement.execute("select 2 + 2");
386390
Assertions.assertEquals(-1, statement.getUpdateCount());

0 commit comments

Comments
 (0)