Search in sources :

Example 71 with SQLiteDatabase

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

the class MediaDatabase method getGalleryMediaForThread.

public Cursor getGalleryMediaForThread(long threadId) {
    SQLiteDatabase database = databaseHelper.getReadableDatabase();
    Cursor cursor = database.rawQuery(GALLERY_MEDIA_QUERY, new String[] { threadId + "" });
    setNotifyConverationListeners(cursor, threadId);
    return cursor;
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) Cursor(android.database.Cursor)

Example 72 with SQLiteDatabase

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

the class MessagingDatabase method setMismatchedIdentity.

public void setMismatchedIdentity(long messageId, final Address address, final IdentityKey identityKey) {
    List<IdentityKeyMismatch> items = new ArrayList<IdentityKeyMismatch>() {

        {
            add(new IdentityKeyMismatch(address, identityKey));
        }
    };
    IdentityKeyMismatchList document = new IdentityKeyMismatchList(items);
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    database.beginTransaction();
    try {
        setDocument(database, messageId, MISMATCHED_IDENTITIES, document);
        database.setTransactionSuccessful();
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
    } finally {
        database.endTransaction();
    }
}
Also used : IdentityKeyMismatchList(org.thoughtcrime.securesms.database.documents.IdentityKeyMismatchList) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) ArrayList(java.util.ArrayList) IdentityKeyMismatch(org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch) IOException(java.io.IOException)

Example 73 with SQLiteDatabase

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

the class MessagingDatabase method addToDocument.

protected <T extends Document<I>, I> void addToDocument(long messageId, String column, List<I> objects, Class<T> clazz) throws IOException {
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    database.beginTransaction();
    try {
        T document = getDocument(database, messageId, column, clazz);
        document.getList().addAll(objects);
        setDocument(database, messageId, column, document);
        database.setTransactionSuccessful();
    } finally {
        database.endTransaction();
    }
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 74 with SQLiteDatabase

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

the class MmsDatabase method updateMailboxBitmask.

private void updateMailboxBitmask(long id, long maskOff, long maskOn, Optional<Long> threadId) {
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    db.execSQL("UPDATE " + TABLE_NAME + " SET " + MESSAGE_BOX + " = (" + MESSAGE_BOX + " & " + (Types.TOTAL_MASK - maskOff) + " | " + maskOn + " )" + " WHERE " + ID + " = ?", new String[] { id + "" });
    if (threadId.isPresent()) {
        DatabaseFactory.getThreadDatabase(context).update(threadId.get(), false);
    }
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 75 with SQLiteDatabase

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

the class MmsDatabase method deleteMessagesInThreadBeforeDate.

/*package*/
void deleteMessagesInThreadBeforeDate(long threadId, long date) {
    Cursor cursor = null;
    try {
        SQLiteDatabase db = databaseHelper.getReadableDatabase();
        String where = THREAD_ID + " = ? AND (CASE (" + MESSAGE_BOX + " & " + Types.BASE_TYPE_MASK + ") ";
        for (long outgoingType : Types.OUTGOING_MESSAGE_TYPES) {
            where += " WHEN " + outgoingType + " THEN " + DATE_SENT + " < " + date;
        }
        where += (" ELSE " + DATE_RECEIVED + " < " + date + " END)");
        Log.w("MmsDatabase", "Executing trim query: " + where);
        cursor = db.query(TABLE_NAME, new String[] { ID }, where, new String[] { threadId + "" }, null, null, null);
        while (cursor != null && cursor.moveToNext()) {
            Log.w("MmsDatabase", "Trimming: " + cursor.getLong(0));
            delete(cursor.getLong(0));
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) Cursor(android.database.Cursor)

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