aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/iciql/Db.java13
-rw-r--r--src/main/java/com/iciql/Query.java35
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);