mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-27 11:54:30 +01:00
Implement totalChanges
This commit is contained in:
@@ -214,6 +214,21 @@ public final class LimboStatement {
|
||||
private native int bindBlob(long statementPointer, int position, byte[] value)
|
||||
throws SQLException;
|
||||
|
||||
/**
|
||||
* Returns total number of changes.
|
||||
*
|
||||
* @throws SQLException If a database access error occurs
|
||||
*/
|
||||
public long totalChanges() throws SQLException {
|
||||
final long result = totalChanges(statementPointer);
|
||||
if (result == -1) {
|
||||
throw new SQLException("Exception while retrieving total number of changes");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private native long totalChanges(long statementPointer) throws SQLException;
|
||||
/**
|
||||
* Checks if the statement is closed.
|
||||
*
|
||||
|
||||
@@ -28,8 +28,6 @@ public class JDBC4Statement implements Statement {
|
||||
private final int resultSetHoldability;
|
||||
|
||||
private int queryTimeoutSeconds;
|
||||
private long updateCount;
|
||||
private boolean exhaustedResults = false;
|
||||
|
||||
private ReentrantLock connectionLock = new ReentrantLock();
|
||||
|
||||
@@ -74,14 +72,14 @@ public class JDBC4Statement implements Statement {
|
||||
|
||||
@Override
|
||||
public int executeUpdate(String sql) throws SQLException {
|
||||
execute(sql);
|
||||
final long previousTotalChanges = statement == null ? 0L : statement.totalChanges();
|
||||
|
||||
execute(sql);
|
||||
requireNonNull(statement, "statement should not be null after running execute method");
|
||||
final LimboResultSet resultSet = statement.getResultSet();
|
||||
resultSet.consumeAll();
|
||||
|
||||
// TODO: return update count;
|
||||
return 0;
|
||||
return (int) (statement.totalChanges() - previousTotalChanges);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -176,7 +174,6 @@ public class JDBC4Statement implements Statement {
|
||||
statement = connection.prepare(sql);
|
||||
final boolean result = statement.execute();
|
||||
updateGeneratedKeys();
|
||||
exhaustedResults = false;
|
||||
|
||||
return result;
|
||||
} finally {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package tech.turso.jdbc4;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
@@ -70,4 +71,30 @@ class JDBC4StatementTest {
|
||||
stmt.close();
|
||||
assertThrows(SQLException.class, () -> stmt.execute("SELECT 1;"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void execute_update_should_return_number_of_inserted_elements() throws Exception {
|
||||
assertThat(stmt.executeUpdate("CREATE TABLE s1 (c1);")).isEqualTo(0);
|
||||
assertThat(stmt.executeUpdate("INSERT INTO s1 VALUES (0);")).isEqualTo(1);
|
||||
assertThat(stmt.executeUpdate("INSERT INTO s1 VALUES (1), (2);")).isEqualTo(2);
|
||||
assertThat(stmt.executeUpdate("INSERT INTO s1 VALUES (3), (4), (5);")).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("Limbo update not yet supported")
|
||||
void execute_update_should_return_number_of_updated_elements() throws Exception {
|
||||
assertThat(stmt.executeUpdate("CREATE TABLE s1 (c1);")).isEqualTo(0);
|
||||
assertThat(stmt.executeUpdate("INSERT INTO s1 VALUES (1), (2), (3);")).isEqualTo(3);
|
||||
|
||||
assertThat(stmt.executeUpdate("UPDATE s1 SET c1 = 0;")).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("Limbo delete has a bug")
|
||||
void execute_update_should_return_number_of_deleted_elements() throws Exception {
|
||||
assertThat(stmt.executeUpdate("CREATE TABLE s1 (c1);")).isEqualTo(0);
|
||||
assertThat(stmt.executeUpdate("INSERT INTO s1 VALUES (1), (2), (3);")).isEqualTo(3);
|
||||
|
||||
assertThat(stmt.executeUpdate("DELETE FROM s1")).isEqualTo(3);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user