net.sqlcipher.database.SQLiteDatabaseHook Java Examples

The following examples show how to use net.sqlcipher.database.SQLiteDatabaseHook. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatabaseExport.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void export(DatabaseUserConfiguration oldConfiguration,
                    DatabaseUserConfiguration newConfiguration, String oldPassword, String newPassword, String tag,
                    SQLiteDatabaseHook oldHook, SQLiteDatabaseHook newHook) {
    wrapAction(() -> {
        File oldDatabaseFile = context.getDatabasePath(oldConfiguration.databaseName());
        File newDatabaseFile = context.getDatabasePath(newConfiguration.databaseName());


        SQLiteDatabase.loadLibs(context);
        SQLiteDatabase oldDatabase = SQLiteDatabase.openOrCreateDatabase(oldDatabaseFile, oldPassword, null,
                oldHook);
        oldDatabase.rawExecSQL(String.format(
                "ATTACH DATABASE '%s' as alias KEY '%s';", newDatabaseFile.getAbsolutePath(), newPassword));
        if (newHook != null) {
            oldDatabase.rawExecSQL("PRAGMA alias.cipher_page_size = 16384;");
            oldDatabase.rawExecSQL("PRAGMA alias.cipher_memory_security = OFF;");
        }
        oldDatabase.rawExecSQL("SELECT sqlcipher_export('alias');");
        oldDatabase.rawExecSQL("DETACH DATABASE alias;");

        int version = oldDatabase.getVersion();
        SQLiteDatabase newDatabase = SQLiteDatabase.openOrCreateDatabase(newDatabaseFile, newPassword, null,
                newHook);
        newDatabase.setVersion(version);

        newDatabase.close();
        oldDatabase.close();
    }, tag);
}
 
Example #2
Source File: SQLiteDatabaseNative.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
public void __constructor__(String path, char[] password, CursorFactory factory, int flags, SQLiteDatabaseHook hook) {
    db = android.database.sqlite.SQLiteDatabase.openDatabase(path, null, flags);
}