Mercurial > hg > monetdb-java
comparison src/main/java/org/monetdb/client/JdbcClient.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 |
---|---|
1085 SQLWarning warn; | 1085 SQLWarning warn; |
1086 long startTime = (showTiming ? System.currentTimeMillis() : 0); | 1086 long startTime = (showTiming ? System.currentTimeMillis() : 0); |
1087 long finishTime = 0; | 1087 long finishTime = 0; |
1088 | 1088 |
1089 // execute the query, let the driver decide what type it is | 1089 // execute the query, let the driver decide what type it is |
1090 int aff = -1; | 1090 long aff = -1; |
1091 boolean nextRslt = stmt.execute(query, Statement.RETURN_GENERATED_KEYS); | 1091 boolean nextRslt = stmt.execute(query, Statement.RETURN_GENERATED_KEYS); |
1092 if (!nextRslt) | 1092 if (!nextRslt) |
1093 aff = stmt.getUpdateCount(); | 1093 aff = stmt.getLargeUpdateCount(); |
1094 do { | 1094 do { |
1095 if (nextRslt) { | 1095 if (nextRslt) { |
1096 // we have a ResultSet, print it | 1096 // we have a ResultSet, print it |
1097 final ResultSet rs = stmt.getResultSet(); | 1097 final ResultSet rs = stmt.getResultSet(); |
1098 | 1098 |
1116 warn = warn.getNextWarning(); | 1116 warn = warn.getNextWarning(); |
1117 } while (warn != null); | 1117 } while (warn != null); |
1118 rs.clearWarnings(); | 1118 rs.clearWarnings(); |
1119 } | 1119 } |
1120 rs.close(); | 1120 rs.close(); |
1121 } else if (aff != -1) { | 1121 } else { |
1122 String timingoutput = ""; | 1122 String timingoutput = ""; |
1123 if (showTiming) { | 1123 if (showTiming) { |
1124 finishTime = System.currentTimeMillis(); | 1124 finishTime = System.currentTimeMillis(); |
1125 timingoutput = ". Elapsed Time: " + (finishTime - startTime) + " ms"; | 1125 timingoutput = ". Elapsed Time: " + (finishTime - startTime) + " ms"; |
1126 startTime = finishTime; | 1126 startTime = finishTime; |
1127 } | 1127 } |
1128 | 1128 |
1129 if (aff == Statement.SUCCESS_NO_INFO) { | 1129 if (aff == -1) { |
1130 out.println("Operation successful" + timingoutput); | 1130 out.println("Operation successful" + timingoutput); |
1131 } else { | 1131 } else { |
1132 // we have an update count | 1132 // we have an update count |
1133 // see if a key was generated | 1133 // see if a key was generated |
1134 final ResultSet rs = stmt.getGeneratedKeys(); | 1134 final ResultSet rs = stmt.getGeneratedKeys(); |
1135 final boolean hasGeneratedKeyData = rs.next(); | 1135 final boolean hasGeneratedKeyData = (rs != null && rs.next()); |
1136 out.println(aff + " affected row" + (aff != 1 ? "s" : "") + | 1136 out.println(aff + " affected row" + (aff != 1 ? "s" : "") + |
1137 (hasGeneratedKeyData ? ", last generated key: " + rs.getString(1) : "") + | 1137 (hasGeneratedKeyData ? ", last generated key: " + rs.getString(1) : "") + |
1138 timingoutput); | 1138 timingoutput); |
1139 rs.close(); | 1139 rs.close(); |
1140 } | 1140 } |
1141 } | 1141 } |
1142 | 1142 |
1143 out.flush(); | 1143 out.flush(); |
1144 } while ((nextRslt = stmt.getMoreResults()) || | 1144 } while ((nextRslt = stmt.getMoreResults()) || |
1145 (aff = stmt.getUpdateCount()) != -1); | 1145 (aff = stmt.getLargeUpdateCount()) != -1); |
1146 | 1146 |
1147 // if there were warnings for this statement show them! | 1147 // if there were warnings for this statement show them! |
1148 warn = stmt.getWarnings(); | 1148 warn = stmt.getWarnings(); |
1149 while (warn != null) { | 1149 while (warn != null) { |
1150 System.err.println("Statement warning: " + warn.getMessage()); | 1150 System.err.println("Statement warning: " + warn.getMessage()); |