use of android.database.sqlite.SQLiteDatabase in project Conversations by siacs.
the class DatabaseBackend method getLastMessageReceived.
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) and conversations.mode=0 order by messages.timesent desc limit 1";
String[] args = { account.getUuid() };
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;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
use of android.database.sqlite.SQLiteDatabase in project Conversations by siacs.
the class DatabaseBackend method insertPresenceTemplate.
public void insertPresenceTemplate(PresenceTemplate template) {
SQLiteDatabase db = this.getWritableDatabase();
db.insert(PresenceTemplate.TABELNAME, null, template.getContentValues());
}
use of android.database.sqlite.SQLiteDatabase in project Conversations by siacs.
the class DatabaseBackend method storeSignedPreKey.
public void storeSignedPreKey(Account account, SignedPreKeyRecord record) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(SQLiteAxolotlStore.ID, record.getId());
values.put(SQLiteAxolotlStore.KEY, Base64.encodeToString(record.serialize(), Base64.DEFAULT));
values.put(SQLiteAxolotlStore.ACCOUNT, account.getUuid());
db.insert(SQLiteAxolotlStore.SIGNED_PREKEY_TABLENAME, null, values);
}
use of android.database.sqlite.SQLiteDatabase in project Conversations by siacs.
the class DatabaseBackend method deleteAccount.
public boolean deleteAccount(Account account) {
SQLiteDatabase db = this.getWritableDatabase();
String[] args = { account.getUuid() };
final int rows = db.delete(Account.TABLENAME, Account.UUID + "=?", args);
return rows == 1;
}
use of android.database.sqlite.SQLiteDatabase in project Conversations by siacs.
the class DatabaseBackend method deletePresenceTemplate.
public void deletePresenceTemplate(PresenceTemplate template) {
Log.d(Config.LOGTAG, "deleting presence template with uuid " + template.getUuid());
SQLiteDatabase db = this.getWritableDatabase();
String where = PresenceTemplate.UUID + "=?";
String[] whereArgs = { template.getUuid() };
db.delete(PresenceTemplate.TABELNAME, where, whereArgs);
}
Aggregations