Skip to content

Commit

Permalink
GROOVY-11469: Empty execute method in groovy.sql.Sql
Browse files Browse the repository at this point in the history
  • Loading branch information
paulk-asert committed Sep 5, 2024
1 parent 6e6f304 commit a2e8460
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
Original file line number Diff line number Diff line change
Expand Up @@ -2512,7 +2512,32 @@ public boolean execute(String sql, List<Object> params) throws SQLException {
* @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);
}
}

/**
Expand Down

0 comments on commit a2e8460

Please sign in to comment.