diff --git a/java/com/almworks/sqlite4java/SQLiteStatement.java b/java/com/almworks/sqlite4java/SQLiteStatement.java index a7cb2ed..3c5051f 100644 --- a/java/com/almworks/sqlite4java/SQLiteStatement.java +++ b/java/com/almworks/sqlite4java/SQLiteStatement.java @@ -211,8 +211,7 @@ public SQLiteStatement reset(boolean clearBindings) throws SQLiteException { if (myStepped) { if (fineLogging) Internal.logFine(this, "resetting"); - int rc = _SQLiteSwigged.sqlite3_reset(handle); - myController.throwResult(rc, "reset()", this); + _SQLiteSwigged.sqlite3_reset(handle); } myHasRow = false; myStepped = false; diff --git a/test/com/almworks/sqlite4java/ReuseStatementIssue67Tests.java b/test/com/almworks/sqlite4java/ReuseStatementIssue67Tests.java new file mode 100644 index 0000000..1e6d1d9 --- /dev/null +++ b/test/com/almworks/sqlite4java/ReuseStatementIssue67Tests.java @@ -0,0 +1,42 @@ +package com.almworks.sqlite4java; + +import java.util.logging.Level; +import java.util.logging.Logger; + +public class ReuseStatementIssue67Tests extends SQLiteConnectionFixture { + public void testTest() throws SQLiteException { + Logger.getLogger("com.almworks.sqlite4java").setLevel(Level.OFF); + SQLiteConnection connection = fileDb().open(); + connection.exec("create table TBL (id unique, val integer)"); + + SQLiteStatement st = connection.prepare("insert into TBL values (?,?)", false); + + int id = 0; + while (id != 4) { + try { + st.bind(1, id); + st.bind(2, id*id); + st.step(); + st.reset(true); + } catch (SQLiteException ex) { + st.cancel(); + st.clearBindings(); + st.reset(true); + id++; + } + } + checkTable(connection, 0, 0, 1, 1, 2, 4, 3, 9); + } + + private void checkTable(SQLiteConnection connection, int ... expected) throws SQLiteException { + int idx = 0; + SQLiteStatement st; + st = connection.prepare("select * from TBL"); + while (st.step()) { + assertTrue("idx >= expected.length" + idx + " " + expected.length, idx < expected.length); + for (int i = 0; i < st.columnCount(); i++) { + assertEquals(st.columnInt(i), expected[idx++]); + } + } + } +}