Search in sources :

Example 1 with SQLiteStatement

use of net.zetetic.database.sqlcipher.SQLiteStatement in project Signal-Android by WhisperSystems.

the class SmsMigrator method migrateConversation.

private static void migrateConversation(Context context, SmsMigrationProgressListener listener, ProgressDescription progress, long theirThreadId, long ourThreadId) {
    MessageDatabase ourSmsDatabase = SignalDatabase.sms();
    Cursor cursor = null;
    SQLiteStatement statement = null;
    try {
        Uri uri = Uri.parse("content://sms/conversations/" + theirThreadId);
        try {
            cursor = context.getContentResolver().query(uri, null, null, null, null);
        } catch (SQLiteException e) {
            // / Work around for weird sony-specific (?) bug: #4309
            Log.w(TAG, e);
            return;
        }
        SQLiteDatabase transaction = ourSmsDatabase.beginTransaction();
        statement = ourSmsDatabase.createInsertStatement(transaction);
        while (cursor != null && cursor.moveToNext()) {
            int addressColumn = cursor.getColumnIndexOrThrow(SystemColumns.ADDRESS);
            int typeColumn = cursor.getColumnIndex(SmsDatabase.TYPE);
            if (!cursor.isNull(addressColumn) && (cursor.isNull(typeColumn) || isAppropriateTypeForMigration(cursor, typeColumn))) {
                getContentValuesForRow(context, cursor, ourThreadId, statement);
                statement.execute();
            }
            listener.progressUpdate(new ProgressDescription(progress, cursor.getCount(), cursor.getPosition()));
        }
        ourSmsDatabase.endTransaction(transaction);
        SignalDatabase.threads().update(ourThreadId, true);
        SignalDatabase.threads().setLastScrolled(ourThreadId, 0);
        SignalDatabase.threads().notifyConversationListeners(ourThreadId);
    } finally {
        if (statement != null)
            statement.close();
        if (cursor != null)
            cursor.close();
    }
}
Also used : SQLiteStatement(net.zetetic.database.sqlcipher.SQLiteStatement) Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException) Uri(android.net.Uri)

Aggregations

Cursor (android.database.Cursor)1 SQLiteException (android.database.sqlite.SQLiteException)1 Uri (android.net.Uri)1 SQLiteStatement (net.zetetic.database.sqlcipher.SQLiteStatement)1