reset statement instead of recreating it when executing preparedstatement batch

This commit is contained in:
Duckulus 2025-11-19 23:47:15 +01:00
parent 66213612b8
commit 7e89772326
4 changed files with 33 additions and 9 deletions

View file

@ -20,7 +20,7 @@ public final class TursoStatement {
private final String sql;
private final long statementPointer;
private final TursoResultSet resultSet;
private TursoResultSet resultSet;
private boolean closed;
@ -290,6 +290,17 @@ public final class TursoStatement {
private native int parameterCount(long statementPointer) throws SQLException;
/** Resets this statement so it's ready for re-execution */
public void reset() throws SQLException {
final int result = reset(statementPointer);
if (result == -1) {
throw new SQLException("Exception while resetting statement");
}
this.resultSet = TursoResultSet.of(this);
}
private native int reset(long statementPointer) throws SQLException;
/**
* Checks if the statement is closed.
*

View file

@ -22,7 +22,7 @@ import tech.turso.core.TursoResultSet;
public final class JDBC4PreparedStatement extends JDBC4Statement implements PreparedStatement {
private final String sql;
private JDBC4ResultSet resultSet;
private final JDBC4ResultSet resultSet;
private final int paramCount;
private Object[] currentBatchParams;
@ -44,11 +44,6 @@ public final class JDBC4PreparedStatement extends JDBC4Statement implements Prep
this.currentBatchParams = new Object[paramCount];
}
private void reprepareStatement() throws SQLException {
this.statement = connection.prepare(sql);
this.resultSet = new JDBC4ResultSet(this.statement.getResultSet());
}
@Override
public ResultSet executeQuery() throws SQLException {
// TODO: check bindings etc
@ -362,8 +357,7 @@ public final class JDBC4PreparedStatement extends JDBC4Statement implements Prep
}
for (int i = 0; i < batchQueryParams.size(); i++) {
try {
// TODO: do this without creating a new statement because this has unnecessary overhead
reprepareStatement();
statement.reset();
execute(batchQueryParams.get(i));
updateCounts[i] = getUpdateCount();
} catch (SQLException e) {