Skip to content

Commit

Permalink
Gracefully handle SQLite's pre-closed ResultSets for queries with 0 r…
Browse files Browse the repository at this point in the history
…eturned rows
  • Loading branch information
gitblit committed Apr 22, 2015
1 parent 8ac32ab commit cf315fa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
13 changes: 8 additions & 5 deletions src/main/java/com/iciql/Db.java
Expand Up @@ -414,11 +414,14 @@ public <T> List<T> buildObjects(Class<? extends T> modelClass, boolean wildcardS
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);
Expand Down
35 changes: 22 additions & 13 deletions src/main/java/com/iciql/Query.java
Expand Up @@ -248,11 +248,14 @@ private List<T> select(boolean distinct) {
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);
Expand Down Expand Up @@ -401,11 +404,14 @@ private <X> List<X> select(Class<X> clazz, X x, boolean distinct) {
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);
Expand All @@ -428,9 +434,12 @@ private <X> List<X> selectSimple(X x, boolean distinct) {
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);
Expand Down

0 comments on commit cf315fa

Please sign in to comment.