Search in sources :

Example 21 with SQLiteDatabase

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

the class MessagingDatabase method removeFromDocument.

protected <D extends Document<I>, I> void removeFromDocument(long messageId, String column, I object, Class<D> clazz) throws IOException {
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    database.beginTransaction();
    try {
        D document = getDocument(database, messageId, column, clazz);
        Iterator<I> iterator = document.getList().iterator();
        while (iterator.hasNext()) {
            I item = iterator.next();
            if (item.equals(object)) {
                iterator.remove();
                break;
            }
        }
        setDocument(database, messageId, column, document);
        database.setTransactionSuccessful();
    } finally {
        database.endTransaction();
    }
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 22 with SQLiteDatabase

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

the class MmsDatabase method insertMediaMessage.

private long insertMediaMessage(@Nullable String body, @NonNull List<Attachment> attachments, @NonNull ContentValues contentValues, @Nullable SmsDatabase.InsertListener insertListener) throws MmsException {
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    AttachmentDatabase partsDatabase = DatabaseFactory.getAttachmentDatabase(context);
    contentValues.put(BODY, body);
    contentValues.put(PART_COUNT, attachments.size());
    db.beginTransaction();
    try {
        long messageId = db.insert(TABLE_NAME, null, contentValues);
        partsDatabase.insertAttachmentsForMessage(messageId, attachments);
        db.setTransactionSuccessful();
        return messageId;
    } finally {
        db.endTransaction();
        if (insertListener != null) {
            insertListener.onComplete();
        }
        notifyConversationListeners(contentValues.getAsLong(THREAD_ID));
        DatabaseFactory.getThreadDatabase(context).update(contentValues.getAsLong(THREAD_ID), true);
    }
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 23 with SQLiteDatabase

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

the class MmsDatabase method delete.

public boolean delete(long messageId) {
    long threadId = getThreadIdForMessage(messageId);
    AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context);
    attachmentDatabase.deleteAttachmentsForMessage(messageId);
    GroupReceiptDatabase groupReceiptDatabase = DatabaseFactory.getGroupReceiptDatabase(context);
    groupReceiptDatabase.deleteRowsForMessage(messageId);
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    database.delete(TABLE_NAME, ID_WHERE, new String[] { messageId + "" });
    boolean threadDeleted = DatabaseFactory.getThreadDatabase(context).update(threadId, false);
    notifyConversationListeners(threadId);
    return threadDeleted;
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 24 with SQLiteDatabase

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

the class MmsDatabase method updateMessageBodyAndType.

private Pair<Long, Long> updateMessageBodyAndType(long messageId, String body, long maskOff, long maskOn) {
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    db.execSQL("UPDATE " + TABLE_NAME + " SET " + BODY + " = ?, " + MESSAGE_BOX + " = (" + MESSAGE_BOX + " & " + (Types.TOTAL_MASK - maskOff) + " | " + maskOn + ") " + "WHERE " + ID + " = ?", new String[] { body, messageId + "" });
    long threadId = getThreadIdForMessage(messageId);
    DatabaseFactory.getThreadDatabase(context).update(threadId, true);
    notifyConversationListeners(threadId);
    notifyConversationListListeners();
    return new Pair<>(messageId, threadId);
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) Pair(android.util.Pair)

Example 25 with SQLiteDatabase

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

the class MmsDatabase method deleteAllThreads.

public void deleteAllThreads() {
    DatabaseFactory.getAttachmentDatabase(context).deleteAllAttachments();
    DatabaseFactory.getGroupReceiptDatabase(context).deleteAllRows();
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    database.delete(TABLE_NAME, null, null);
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

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