Search in sources :

Example 1 with SQLiteStatement

use of net.sqlcipher.database.SQLiteStatement in project requery by requery.

the class SqlCipherStatement method execute.

@Override
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
    SQLiteStatement statement = null;
    try {
        statement = connection.getDatabase().compileStatement(sql);
        if (autoGeneratedKeys == RETURN_GENERATED_KEYS) {
            long rowId = statement.executeInsert();
            insertResult = new SingleResultSet(this, rowId);
            return true;
        } else {
            statement.execute();
        }
    } catch (SQLiteException e) {
        SqlCipherConnection.throwSQLException(e);
    } finally {
        if (statement != null) {
            statement.close();
        }
    }
    return false;
}
Also used : SQLiteStatement(net.sqlcipher.database.SQLiteStatement) SingleResultSet(io.requery.android.sqlite.SingleResultSet) SQLiteException(net.sqlcipher.database.SQLiteException)

Example 2 with SQLiteStatement

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

the class SmsMigrator method migrateConversation.

private static void migrateConversation(Context context, SmsMigrationProgressListener listener, ProgressDescription progress, long theirThreadId, long ourThreadId) {
    SmsDatabase ourSmsDatabase = DatabaseFactory.getSmsDatabase(context);
    Cursor cursor = 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();
        SQLiteStatement statement = ourSmsDatabase.createInsertStatement(transaction);
        while (cursor != null && cursor.moveToNext()) {
            int typeColumn = cursor.getColumnIndex(SmsDatabase.TYPE);
            if (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);
        DatabaseFactory.getThreadDatabase(context).update(ourThreadId, true);
        DatabaseFactory.getThreadDatabase(context).notifyConversationListeners(ourThreadId);
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) SQLiteStatement(net.sqlcipher.database.SQLiteStatement) Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException) Uri(android.net.Uri)

Example 3 with SQLiteStatement

use of net.sqlcipher.database.SQLiteStatement in project requery by requery.

the class SqlCipherStatement method executeUpdate.

@Override
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
    SQLiteStatement statement = null;
    try {
        statement = connection.getDatabase().compileStatement(sql);
        if (autoGeneratedKeys == RETURN_GENERATED_KEYS) {
            long rowId = statement.executeInsert();
            insertResult = new SingleResultSet(this, rowId);
            return 1;
        } else {
            return updateCount = statement.executeUpdateDelete();
        }
    } catch (SQLiteException e) {
        SqlCipherConnection.throwSQLException(e);
    } finally {
        if (statement != null) {
            statement.close();
        }
    }
    return 0;
}
Also used : SQLiteStatement(net.sqlcipher.database.SQLiteStatement) SingleResultSet(io.requery.android.sqlite.SingleResultSet) SQLiteException(net.sqlcipher.database.SQLiteException)

Example 4 with SQLiteStatement

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

the class PlaintextBackupImporter method importPlaintextFromSd.

public static void importPlaintextFromSd(Context context) throws NoExternalStorageException, IOException {
    Log.w("PlaintextBackupImporter", "importPlaintext()");
    SmsDatabase db = DatabaseFactory.getSmsDatabase(context);
    SQLiteDatabase transaction = db.beginTransaction();
    try {
        ThreadDatabase threads = DatabaseFactory.getThreadDatabase(context);
        XmlBackup backup = new XmlBackup(getPlaintextExportFile().getAbsolutePath());
        Set<Long> modifiedThreads = new HashSet<>();
        XmlBackup.XmlBackupItem item;
        while ((item = backup.getNext()) != null) {
            Recipient recipient = Recipient.from(context, Address.fromExternal(context, item.getAddress()), false);
            long threadId = threads.getThreadIdFor(recipient);
            SQLiteStatement statement = db.createInsertStatement(transaction);
            if (item.getAddress() == null || item.getAddress().equals("null"))
                continue;
            if (!isAppropriateTypeForImport(item.getType()))
                continue;
            addStringToStatement(statement, 1, item.getAddress());
            addNullToStatement(statement, 2);
            addLongToStatement(statement, 3, item.getDate());
            addLongToStatement(statement, 4, item.getDate());
            addLongToStatement(statement, 5, item.getProtocol());
            addLongToStatement(statement, 6, item.getRead());
            addLongToStatement(statement, 7, item.getStatus());
            addTranslatedTypeToStatement(statement, 8, item.getType());
            addNullToStatement(statement, 9);
            addStringToStatement(statement, 10, item.getSubject());
            addStringToStatement(statement, 11, item.getBody());
            addStringToStatement(statement, 12, item.getServiceCenter());
            addLongToStatement(statement, 13, threadId);
            modifiedThreads.add(threadId);
            statement.execute();
        }
        for (long threadId : modifiedThreads) {
            threads.update(threadId, true);
        }
        Log.w("PlaintextBackupImporter", "Exited loop");
    } catch (XmlPullParserException e) {
        Log.w("PlaintextBackupImporter", e);
        throw new IOException("XML Parsing error!");
    } finally {
        db.endTransaction(transaction);
    }
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) IOException(java.io.IOException) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) SQLiteStatement(net.sqlcipher.database.SQLiteStatement) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) HashSet(java.util.HashSet)

Aggregations

SQLiteStatement (net.sqlcipher.database.SQLiteStatement)4 SingleResultSet (io.requery.android.sqlite.SingleResultSet)2 SQLiteDatabase (net.sqlcipher.database.SQLiteDatabase)2 SQLiteException (net.sqlcipher.database.SQLiteException)2 Cursor (android.database.Cursor)1 SQLiteException (android.database.sqlite.SQLiteException)1 Uri (android.net.Uri)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1