You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2024/09/05 00:12:42 UTC
(groovy) branch GROOVY_4_0_X updated: GROOVY-11469: Empty execute method in groovy.sql.Sql
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
new da9f9b9cf8 GROOVY-11469: Empty execute method in groovy.sql.Sql
da9f9b9cf8 is described below
commit da9f9b9cf8375ffce9523caa0d8b2e6c411c483a
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Sep 5 10:12:21 2024 +1000
GROOVY-11469: Empty execute method in groovy.sql.Sql
---
.../groovy-sql/src/main/java/groovy/sql/Sql.java | 27 +++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java b/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
index ee16ac3366..7f9c21384d 100644
--- a/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
+++ b/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
@@ -2513,7 +2513,32 @@ public class Sql implements AutoCloseable {
* @since 2.3.2
*/
public void execute(String sql, List<Object> params, @ClosureParams(value=FromString.class, options={"boolean,java.util.List<groovy.sql.GroovyRowResult>", "boolean,int"}) Closure resultClosure) throws SQLException {
-
+ Connection connection = createConnection();
+ PreparedStatement statement = null;
+ try {
+ statement = getPreparedStatement(connection, sql, params);
+ boolean isResultSet = statement.execute();
+ int updateCount = statement.getUpdateCount();
+ while(isResultSet || updateCount != -1) {
+ if (resultClosure.getMaximumNumberOfParameters() != 2) {
+ throw new SQLException("Incorrect number of parameters for resultClosure");
+ }
+ if (isResultSet) {
+ ResultSet resultSet = statement.getResultSet();
+ List<GroovyRowResult> rowResult = resultSet == null ? null : asList(sql, resultSet);
+ resultClosure.call(isResultSet, rowResult);
+ } else {
+ resultClosure.call(isResultSet, updateCount);
+ }
+ isResultSet = statement.getMoreResults();
+ updateCount = statement.getUpdateCount();
+ }
+ } catch (SQLException e) {
+ LOG.warning("Failed to execute: " + sql + " because: " + e.getMessage());
+ throw e;
+ } finally {
+ closeResources(connection, statement);
+ }
}
/**