catch exception when reading message id from database

This commit is contained in:
Daniel Gultsch 2016-01-15 23:46:52 +01:00
parent c5743067ad
commit 943d0391d4

View file

@ -606,15 +606,19 @@ public class DatabaseBackend extends SQLiteOpenHelper {
} }
public Pair<Long, String> getLastMessageReceived(Account account) { public Pair<Long, String> getLastMessageReceived(Account account) {
SQLiteDatabase db = this.getReadableDatabase(); try {
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"; SQLiteDatabase db = this.getReadableDatabase();
String[] args = {account.getUuid()}; 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";
Cursor cursor = db.rawQuery(sql, args); String[] args = {account.getUuid()};
if (cursor.getCount() == 0) { Cursor cursor = db.rawQuery(sql, args);
if (cursor.getCount() == 0) {
return null;
} else {
cursor.moveToFirst();
return new Pair<>(cursor.getLong(0), cursor.getString(1));
}
} catch (Exception e) {
return null; return null;
} else {
cursor.moveToFirst();
return new Pair<>(cursor.getLong(0), cursor.getString(1));
} }
} }