mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-03 09:42:22 +00:00
Change LimboStatement.java
to throw exception when the result is null which is the error case
This commit is contained in:
parent
9c3c6271a3
commit
24ead40f88
4 changed files with 33 additions and 9 deletions
|
@ -55,7 +55,11 @@ public class LimboResultSet {
|
|||
}
|
||||
|
||||
lastStepResult = this.statement.step();
|
||||
pastLastRow = lastStepResult == null || lastStepResult.isDone();
|
||||
if (lastStepResult.isRow()) {
|
||||
row++;
|
||||
}
|
||||
|
||||
pastLastRow = lastStepResult.isDone();
|
||||
return !pastLastRow;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,9 +38,13 @@ public class LimboStatement {
|
|||
return resultSet.hasLastStepReturnedRow();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
LimboStepResult step() throws SQLException {
|
||||
return step(this.statementPointer);
|
||||
final LimboStepResult result = step(this.statementPointer);
|
||||
if (result == null) {
|
||||
throw new SQLException("step() returned null, which is only returned when an error occurs");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -44,8 +44,27 @@ public class LimboStepResult {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "LimboStepResult{" +
|
||||
"stepResultId=" + stepResultId +
|
||||
"stepResultName=" + getStepResultName() +
|
||||
", result=" + Arrays.toString(result) +
|
||||
'}';
|
||||
}
|
||||
|
||||
private String getStepResultName() {
|
||||
switch (stepResultId) {
|
||||
case STEP_RESULT_ID_ROW:
|
||||
return "ROW";
|
||||
case STEP_RESULT_ID_IO:
|
||||
return "IO";
|
||||
case STEP_RESULT_ID_DONE:
|
||||
return "DONE";
|
||||
case STEP_RESULT_ID_INTERRUPT:
|
||||
return "INTERRUPT";
|
||||
case STEP_RESULT_ID_BUSY:
|
||||
return "BUSY";
|
||||
case STEP_RESULT_ID_ERROR:
|
||||
return "ERROR";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class JDBC4ResultSetTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Disabled("https://github.com/tursodatabase/limbo/pull/743#issuecomment-2600746904")
|
||||
// @Disabled("https://github.com/tursodatabase/limbo/pull/743#issuecomment-2600746904")
|
||||
void invoking_next_after_the_last_row_should_return_false() throws Exception {
|
||||
stmt.execute("CREATE TABLE users (id INT PRIMARY KEY, username TEXT);");
|
||||
stmt.execute("INSERT INTO users VALUES (1, 'sinwoo');");
|
||||
|
@ -50,11 +50,8 @@ class JDBC4ResultSetTest {
|
|||
stmt.execute("SELECT * FROM users");
|
||||
ResultSet resultSet = stmt.getResultSet();
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
while (resultSet.next()) {
|
||||
if (System.currentTimeMillis() - startTime > 1000) {
|
||||
throw new Exception("Should have finished now");
|
||||
}
|
||||
// run until next() returns false
|
||||
}
|
||||
|
||||
// if the previous call to next() returned false, consecutive call to next() should return false as well
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue