Search in sources :

Example 11 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.

the class ThreadDatabase method getThreadIdFor.

public long getThreadIdFor(Recipient recipient, int distributionType) {
    SQLiteDatabase db = databaseHelper.getReadableDatabase();
    String where = ADDRESS + " = ?";
    String[] recipientsArg = new String[] { recipient.getAddress().serialize() };
    Cursor cursor = null;
    try {
        cursor = db.query(TABLE_NAME, new String[] { ID }, where, recipientsArg, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            return cursor.getLong(cursor.getColumnIndexOrThrow(ID));
        } else {
            return createThreadForRecipient(recipient.getAddress(), recipient.isGroupRecipient(), distributionType);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) Cursor(android.database.Cursor) MergeCursor(android.database.MergeCursor)

Example 12 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.

the class ThreadDatabase method getConversationList.

private Cursor getConversationList(String archived) {
    SQLiteDatabase db = databaseHelper.getReadableDatabase();
    String query = createQuery(ARCHIVED + " = ? AND " + MESSAGE_COUNT + " != 0", 0);
    Cursor cursor = db.rawQuery(query, new String[] { archived });
    setNotifyConverationListListeners(cursor);
    return cursor;
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) Cursor(android.database.Cursor) MergeCursor(android.database.MergeCursor)

Example 13 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.

the class ThreadDatabase method getRecentConversationList.

public Cursor getRecentConversationList(int limit) {
    SQLiteDatabase db = databaseHelper.getReadableDatabase();
    String query = createQuery(MESSAGE_COUNT + " != 0", limit);
    return db.rawQuery(query, null);
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 14 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.

the class ThreadDatabase method updateThread.

private void updateThread(long threadId, long count, String body, @Nullable Uri attachment, long date, int status, int deliveryReceiptCount, long type, boolean unarchive, long expiresIn, int readReceiptCount) {
    ContentValues contentValues = new ContentValues(7);
    contentValues.put(DATE, date - date % 1000);
    contentValues.put(MESSAGE_COUNT, count);
    contentValues.put(SNIPPET, body);
    contentValues.put(SNIPPET_URI, attachment == null ? null : attachment.toString());
    contentValues.put(SNIPPET_TYPE, type);
    contentValues.put(STATUS, status);
    contentValues.put(DELIVERY_RECEIPT_COUNT, deliveryReceiptCount);
    contentValues.put(READ_RECEIPT_COUNT, readReceiptCount);
    contentValues.put(EXPIRES_IN, expiresIn);
    if (unarchive) {
        contentValues.put(ARCHIVED, 0);
    }
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    db.update(TABLE_NAME, contentValues, ID + " = ?", new String[] { threadId + "" });
    notifyConversationListListeners();
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 15 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.

the class ThreadDatabase method getLastSeenAndHasSent.

public Pair<Long, Boolean> getLastSeenAndHasSent(long threadId) {
    SQLiteDatabase db = databaseHelper.getReadableDatabase();
    Cursor cursor = db.query(TABLE_NAME, new String[] { LAST_SEEN, HAS_SENT }, ID_WHERE, new String[] { String.valueOf(threadId) }, null, null, null);
    try {
        if (cursor != null && cursor.moveToFirst()) {
            return new Pair<>(cursor.getLong(0), cursor.getLong(1) == 1);
        }
        return new Pair<>(-1L, false);
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) Cursor(android.database.Cursor) MergeCursor(android.database.MergeCursor) Pair(org.whispersystems.libsignal.util.Pair)

Aggregations

SQLiteDatabase (net.sqlcipher.database.SQLiteDatabase)124 Cursor (android.database.Cursor)37 ContentValues (android.content.ContentValues)32 IOException (java.io.IOException)15 LinkedList (java.util.LinkedList)12 NonNull (android.support.annotation.NonNull)7 MergeCursor (android.database.MergeCursor)6 Nullable (android.support.annotation.Nullable)6 Pair (android.util.Pair)6 File (java.io.File)5 SQLiteConstraintException (net.sqlcipher.database.SQLiteConstraintException)5 FileNotFoundException (java.io.FileNotFoundException)4 StreamCorruptedException (java.io.StreamCorruptedException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 AudioClipTable (org.storymaker.app.model.AudioClipTable)4 AuthTable (org.storymaker.app.model.AuthTable)4 JobTable (org.storymaker.app.model.JobTable)4 LessonTable (org.storymaker.app.model.LessonTable)4 MediaTable (org.storymaker.app.model.MediaTable)4 ProjectTable (org.storymaker.app.model.ProjectTable)4