Search in sources :

Example 36 with SQLiteDatabase

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();
        }
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) SQLiteCantOpenDatabaseException(android.database.sqlite.SQLiteCantOpenDatabaseException) JSONException(org.json.JSONException) CertificateEncodingException(java.security.cert.CertificateEncodingException) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) InvalidKeyException(org.whispersystems.libaxolotl.InvalidKeyException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) Pair(android.util.Pair) IdentityKeyPair(org.whispersystems.libaxolotl.IdentityKeyPair)

Example 37 with SQLiteDatabase

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());
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 38 with SQLiteDatabase

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);
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 39 with SQLiteDatabase

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;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 40 with SQLiteDatabase

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);
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1658 Cursor (android.database.Cursor)527 ContentValues (android.content.ContentValues)350 ArrayList (java.util.ArrayList)111 File (java.io.File)65 Test (org.junit.Test)59 SQLiteException (android.database.sqlite.SQLiteException)48 SQLException (android.database.SQLException)44 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)44 Uri (android.net.Uri)44 IOException (java.io.IOException)43 ServiceStatus (com.vodafone360.people.service.ServiceStatus)42 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)38 RemoteException (android.os.RemoteException)36 Pair (android.util.Pair)31 MediumTest (android.test.suitebuilder.annotation.MediumTest)30 Account (android.accounts.Account)29 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)25 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)22 HashMap (java.util.HashMap)21