comparison src/main/java/org/monetdb/jdbc/MonetStatement.java @ 967:5cc071c5c170

Corrected the returned integer values of Statement methods executeUpdate(...), executeLargeUpdate(...), getUpdateCount() and getLargeUpdateCount() and PreparedStatement methods executeUpdate() and executeLargeUpdate(). They returned -2 for DDL statements, which was not in compliance with the JDBC API documentation.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 13 Feb 2025 21:16:20 +0100 (2 months ago)
parents ff075ed5ce81
children
comparison
equal deleted inserted replaced
966:39b74cc688d2 967:5cc071c5c170
500 @Override 500 @Override
501 public int executeUpdate(final String sql) throws SQLException { 501 public int executeUpdate(final String sql) throws SQLException {
502 if (execute(sql) != false) 502 if (execute(sql) != false)
503 throw new SQLException("Statement produced a result set", "M1M17"); 503 throw new SQLException("Statement produced a result set", "M1M17");
504 504
505 return getUpdateCount(); 505 return Math.max(getUpdateCount(), 0);
506 } 506 }
507 507
508 /** 508 /**
509 * Executes the given SQL statement and signals the driver with the 509 * Executes the given SQL statement and signals the driver with the
510 * given flag about whether the auto-generated keys produced by this 510 * given flag about whether the auto-generated keys produced by this
533 533
534 /* MonetDB has no way to disable this, so just do the normal thing ;) */ 534 /* MonetDB has no way to disable this, so just do the normal thing ;) */
535 if (execute(sql) != false) 535 if (execute(sql) != false)
536 throw new SQLException("Statement produced a result set", "M1M17"); 536 throw new SQLException("Statement produced a result set", "M1M17");
537 537
538 return getUpdateCount(); 538 return Math.max(getUpdateCount(), 0);
539 } 539 }
540 540
541 /** 541 /**
542 * Executes the given SQL statement and signals the driver that the 542 * Executes the given SQL statement and signals the driver that the
543 * auto-generated keys indicated in the given array should be made 543 * auto-generated keys indicated in the given array should be made
1131 */ 1131 */
1132 @Override 1132 @Override
1133 public long getLargeUpdateCount() throws SQLException { 1133 public long getLargeUpdateCount() throws SQLException {
1134 if (header != null) { 1134 if (header != null) {
1135 if (header instanceof MonetConnection.UpdateResponse) { 1135 if (header instanceof MonetConnection.UpdateResponse) {
1136 return ((MonetConnection.UpdateResponse)header).count; 1136 final long updCnt = ((MonetConnection.UpdateResponse)header).count;
1137 } else if (header instanceof MonetConnection.SchemaResponse) { 1137 if (updCnt >= 0)
1138 return ((MonetConnection.SchemaResponse)header).state; 1138 return updCnt;
1139 } 1139 }
1140 } 1140 }
1141 return -1; 1141 return -1;
1142 } 1142 }
1143 1143
1317 if (hasResultSet) { 1317 if (hasResultSet) {
1318 e.setNextException( 1318 e.setNextException(
1319 new SQLException("Batch query produced a ResultSet! " + 1319 new SQLException("Batch query produced a ResultSet! " +
1320 "Ignoring and setting update count to value " + EXECUTE_FAILED, "M1M17")); 1320 "Ignoring and setting update count to value " + EXECUTE_FAILED, "M1M17"));
1321 counts[offset] = EXECUTE_FAILED; 1321 counts[offset] = EXECUTE_FAILED;
1322 } else if (count >= 0) { 1322 } else {
1323 counts[offset] = count; 1323 counts[offset] = (count >= 0) ? count : SUCCESS_NO_INFO;
1324 } 1324 }
1325 offset++; 1325 offset++;
1326 } while ((hasResultSet = getMoreResults()) || (count = getLargeUpdateCount()) != -1); 1326 } while ((hasResultSet = getMoreResults()) || (count = getLargeUpdateCount()) != -1);
1327 } catch (SQLException ex) { 1327 } catch (SQLException ex) {
1328 e.setNextException(ex); 1328 e.setNextException(ex);
1356 @Override 1356 @Override
1357 public long executeLargeUpdate(final String sql) throws SQLException { 1357 public long executeLargeUpdate(final String sql) throws SQLException {
1358 if (execute(sql) != false) 1358 if (execute(sql) != false)
1359 throw new SQLException("Statement produced a result set", "M1M17"); 1359 throw new SQLException("Statement produced a result set", "M1M17");
1360 1360
1361 return getLargeUpdateCount(); 1361 return Math.max(getLargeUpdateCount(), 0L);
1362 } 1362 }
1363 1363
1364 /** 1364 /**
1365 * Executes the given SQL statement and signals the driver with the 1365 * Executes the given SQL statement and signals the driver with the
1366 * given flag about whether the auto-generated keys produced by this 1366 * given flag about whether the auto-generated keys produced by this
1398 1398
1399 /* MonetDB has no way to disable this, so just do the normal thing ;) */ 1399 /* MonetDB has no way to disable this, so just do the normal thing ;) */
1400 if (execute(sql) != false) 1400 if (execute(sql) != false)
1401 throw new SQLException("Statement produced a result set", "M1M17"); 1401 throw new SQLException("Statement produced a result set", "M1M17");
1402 1402
1403 return getLargeUpdateCount(); 1403 return Math.max(getLargeUpdateCount(), 0L);
1404 } 1404 }
1405 1405
1406 /** 1406 /**
1407 * Executes the given SQL statement and signals the driver that the 1407 * Executes the given SQL statement and signals the driver that the
1408 * auto-generated keys indicated in the given array should be made 1408 * auto-generated keys indicated in the given array should be made