roscopeco/ormdroid

Leaky cursors

Closed this issue · 1 comments

Hey Ross,

I plugged up two cursors (c.close() in 4 different places total) that were spamming my logcat.

First, in entity.java:437

  Cursor c = db.rawQuery("select last_insert_rowid();", null);
  if (c.moveToFirst()) {
    Integer i = c.getInt(0);
    setPrimaryKeyValue(o, i);
   __c.close();__
    return i;
  } else {
    __c.close();__
      throw new ORMDroidException(
        "Failed to get last inserted id after INSERT");
  }

Second, in query.java:276

public T execute(SQLiteDatabase db) {
EntityMapping map = Entity.getEntityMappingEnsureSchema(db, mClass);

if (sqlCache1 == null) {
  sqlCache1 = generate(1);
}
String sql = sqlCache1;
Log.v(TAG, sql);
Cursor c = db.rawQuery(sql, null);
if (c.moveToFirst()) {
    T result = map.<T>load(db, c);
    __c.close();__
    return result;
} else {
    __c.close();__
    return null;
}

}

Thanks! Fixed in master.