package io.vertx.ext.jdbc.impl.actions;
import io.vertx.core.Vertx;
import io.vertx.core.impl.ContextInternal;
import io.vertx.core.json.JsonArray;
import io.vertx.ext.sql.SQLOptions;
import java.sql.*;
import java.sql.ResultSet;
public class JDBCQuery extends AbstractJDBCAction<io.vertx.ext.sql.ResultSet> {
private final String sql;
private final JsonArray in;
public JDBCQuery(Vertx vertx, JDBCStatementHelper helper, SQLOptions options, ContextInternal ctx, String sql, JsonArray in) {
super(vertx, helper, options, ctx);
this.sql = sql;
this.in = in;
}
@Override
public io.vertx.ext.sql.ResultSet execute(Connection conn) throws SQLException {
try (PreparedStatement statement = conn.prepareStatement(sql)) {
applyStatementOptions(statement);
helper.fillStatement(statement, in);
boolean retResult = statement.execute();
io.vertx.ext.sql.ResultSet resultSet = null;
if (retResult) {
io.vertx.ext.sql.ResultSet ref = null;
while (retResult) {
try (ResultSet rs = statement.getResultSet()) {
if (ref == null) {
resultSet = helper.asList(rs);
ref = resultSet;
} else {
ref.setNext(helper.asList(rs));
ref = ref.getNext();
}
}
retResult = statement.getMoreResults();
}
}
return resultSet;
}
}
@Override
protected String name() {
return "query";
}
}