aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/persistance
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2016-04-05 23:24:49 +0200
committerlookshe <github@lookshe.org>2016-04-05 23:24:49 +0200
commitd6a076e11281d4c3fb6b9504fe99d799b04ebbbb (patch)
tree7cbbe209ed0a883bcf29389d91979974444447c1 /src/main/java/eu/siacs/conversations/persistance
parentbfb3cb844578d06fad9aade3a7576ee44d785f70 (diff)
parent5eedce91f9d92e5139f13fddb57314570f42b9ad (diff)
Merge tag '1.11.3' into trz/rebase
Diffstat (limited to 'src/main/java/eu/siacs/conversations/persistance')
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
index e400095d..e8acd400 100644
--- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
@@ -525,8 +525,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
Cursor cursor = db.query(Conversation.TABLENAME, null,
Conversation.ACCOUNT + "=? AND (" + Conversation.CONTACTJID
+ " like ? OR " + Conversation.CONTACTJID + "=?)", selectionArgs, null, null, null);
- if (cursor.getCount() == 0)
+ if (cursor.getCount() == 0) {
+ cursor.close();
return null;
+ }
cursor.moveToFirst();
Conversation conversation = Conversation.fromCursor(cursor);
cursor.close();
@@ -576,12 +578,15 @@ public class DatabaseBackend extends SQLiteOpenHelper {
try {
cursor.moveToFirst();
int count = cursor.getInt(0);
- cursor.close();
return (count > 0);
} catch (SQLiteCantOpenDatabaseException e) {
return true; // better safe than sorry
} catch (RuntimeException e) {
return true; // better safe than sorry
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
}
@@ -643,11 +648,12 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
public Pair<Long, String> getLastMessageReceived(Account account) {
+ Cursor cursor = null;
try {
SQLiteDatabase db = this.getReadableDatabase();
String sql = "select messages.timeSent,messages.serverMsgId from accounts join conversations on accounts.uuid=conversations.accountUuid join messages on conversations.uuid=messages.conversationUuid where accounts.uuid=? and (messages.status=0 or messages.carbon=1 or messages.serverMsgId not null) order by messages.timesent desc limit 1";
String[] args = {account.getUuid()};
- Cursor cursor = db.rawQuery(sql, args);
+ cursor = db.rawQuery(sql, args);
if (cursor.getCount() == 0) {
return null;
} else {
@@ -656,6 +662,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
} catch (Exception e) {
return null;
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
}