Skip to content

PRAGMA cipher_migrate fails with openDatabase #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MufriA opened this issue Jan 5, 2014 · 1 comment
Closed

PRAGMA cipher_migrate fails with openDatabase #115

MufriA opened this issue Jan 5, 2014 · 1 comment

Comments

@MufriA
Copy link

MufriA commented Jan 5, 2014

With latest 3.0.1 release, openDatabase fails to migrate whereas openOrCreateDatabase have no issues.

Failure is at setLocale with encrypted or corrupted file error message.

//no issues
db = SQLiteDatabase.openOrCreateDatabase(path, password, null, hook);

//always fails
db = SQLiteDatabase.openDatabase(path, password, null, SQLiteDatabase.OPEN_READWRITE, hook);

MigrateDatabaseHook hook = new AlwaysMigrateDatabaseHook(password);

public static class MigrateDatabaseHook implements SQLiteDatabaseHook {

        private String mPassword;
        MigrateDatabaseHook(String password) {
            mPassword = password;
        }

        @Override
        public void preKey(final SQLiteDatabase sqLiteDatabase) {
            sqLiteDatabase.execSQL(String.format("PRAGMA key = '%s'", mPassword));
            android.database.Cursor c = sqLiteDatabase.rawQuery("PRAGMA cipher_migrate", null);
            tryCloseCursor(c);
        }

        @Override
        public void postKey(final SQLiteDatabase sqLiteDatabase) {
        }
}            
@developernotes
Copy link
Member

Hello MufriA,

You should execute a PRAGMA cipher_migrate in the SQLiteDatabaseHook::postKey function instead. Also, you should check the result code from the the cipher_migrate command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants