diff options
author | James Moger <james.moger@gitblit.com> | 2015-04-22 17:26:41 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2015-04-22 17:26:41 -0400 |
commit | cf315fa1172cd8ffc11a5a3f3f833303d79db25b (patch) | |
tree | 6b428970c1e060e22c1073193129b0a2ffa72c34 /src | |
parent | 8ac32ab5469d3da41104f91a1c08616a1e1928fb (diff) | |
download | iciql-cf315fa1172cd8ffc11a5a3f3f833303d79db25b.tar.gz iciql-cf315fa1172cd8ffc11a5a3f3f833303d79db25b.zip |
Gracefully handle SQLite's pre-closed ResultSets for queries with 0 returned rows
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/iciql/Db.java | 13 | ||||
-rw-r--r-- | src/main/java/com/iciql/Query.java | 35 |
2 files changed, 30 insertions, 18 deletions
diff --git a/src/main/java/com/iciql/Db.java b/src/main/java/com/iciql/Db.java index 7413c8f..4b55150 100644 --- a/src/main/java/com/iciql/Db.java +++ b/src/main/java/com/iciql/Db.java @@ -414,11 +414,14 @@ public class Db implements AutoCloseable { List<T> result = new ArrayList<T>(); TableDefinition<T> def = (TableDefinition<T>) define(modelClass); try { - int[] columns = def.mapColumns(wildcardSelect, rs); - while (rs.next()) { - T item = Utils.newObject(modelClass); - def.readRow(dialect, item, rs, columns); - result.add(item); + // SQLite returns pre-closed ResultSets for query results with 0 rows + if (!rs.isClosed()) { + int[] columns = def.mapColumns(wildcardSelect, rs); + while (rs.next()) { + T item = Utils.newObject(modelClass); + def.readRow(dialect, item, rs, columns); + result.add(item); + } } } catch (SQLException e) { throw new IciqlException(e); diff --git a/src/main/java/com/iciql/Query.java b/src/main/java/com/iciql/Query.java index 946a460..1a8cbc7 100644 --- a/src/main/java/com/iciql/Query.java +++ b/src/main/java/com/iciql/Query.java @@ -248,11 +248,14 @@ public class Query<T> { appendFromWhere(stat);
ResultSet rs = stat.executeQuery();
try {
- int[] columns = def.mapColumns(false, rs);
- while (rs.next()) {
- T item = from.newObject();
- def.readRow(db.getDialect(), item, rs, columns);
- result.add(item);
+ // SQLite returns pre-closed ResultSets for query results with 0 rows
+ if (!rs.isClosed()) {
+ int[] columns = def.mapColumns(false, rs);
+ while (rs.next()) {
+ T item = from.newObject();
+ def.readRow(db.getDialect(), item, rs, columns);
+ result.add(item);
+ }
}
} catch (SQLException e) {
throw IciqlException.fromSQL(stat.getSQL(), e);
@@ -401,11 +404,14 @@ public class Query<T> { appendFromWhere(stat);
ResultSet rs = stat.executeQuery();
try {
- int[] columns = def.mapColumns(false, rs);
- while (rs.next()) {
- X row = Utils.newObject(clazz);
- def.readRow(db.getDialect(), row, rs, columns);
- result.add(row);
+ // SQLite returns pre-closed ResultSets for query results with 0 rows
+ if (!rs.isClosed()) {
+ int[] columns = def.mapColumns(false, rs);
+ while (rs.next()) {
+ X row = Utils.newObject(clazz);
+ def.readRow(db.getDialect(), row, rs, columns);
+ result.add(row);
+ }
}
} catch (SQLException e) {
throw IciqlException.fromSQL(stat.getSQL(), e);
@@ -428,9 +434,12 @@ public class Query<T> { db.getDialect().registerAdapter(dta);
}
try {
- while (rs.next()) {
- X value = (X) db.getDialect().deserialize(rs, 1, x.getClass());
- result.add(value);
+ // SQLite returns pre-closed ResultSets for query results with 0 rows
+ if (!rs.isClosed()) {
+ while (rs.next()) {
+ X value = (X) db.getDialect().deserialize(rs, 1, x.getClass());
+ result.add(value);
+ }
}
} catch (Exception e) {
throw IciqlException.fromSQL(stat.getSQL(), e);
|