Skip to content

Problem with Database version, always 0 after open #73

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
HansSchlegel opened this issue Nov 13, 2012 · 1 comment
Closed

Problem with Database version, always 0 after open #73

HansSchlegel opened this issue Nov 13, 2012 · 1 comment

Comments

@HansSchlegel
Copy link

I come from this sample which actually works for me
https://github.com/sqlcipher/sqlcipher-android-tests/blob/master/src/main/java/net/zetetic/tests/MigrationUserVersion.java
Unfortunately I cannot store DB version over a close and reopen. See my sample below.

Hi I use Library v 2

DATABASE_VERSION = 2;
File unencryptedDatabase = mContext.getDatabasePath(DB_NAME);
File encryptedDatabase = mContext.getDatabasePath("encrypted.db");
encryptedDatabase.delete();

    myDataBase = SQLiteDatabase.openOrCreateDatabase(unencryptedDatabase,
            "", null);
    int v = myDataBase.getVersion();
    myDataBase.rawExecSQL("PRAGMA user_version = "+ DATABASE_VERSION);
    v = myDataBase.getVersion(); // v = 2
    myDataBase.setVersion(DATABASE_VERSION);
    myDataBase.rawExecSQL(String.format(
            "ATTACH DATABASE '%s' AS encrypted KEY '%s'",
            encryptedDatabase.getAbsolutePath(), DATABASE_PASSWORD1
                    + DATABASE_PASSWORD2));
    myDataBase.rawExecSQL("select sqlcipher_export('encrypted')");
    myDataBase.rawExecSQL("DETACH DATABASE encrypted");
    myDataBase.close();
    myDataBase = SQLiteDatabase.openOrCreateDatabase(encryptedDatabase,
            DATABASE_PASSWORD1 + DATABASE_PASSWORD2, null);
    v = myDataBase.getVersion(); //v = 0!

thanks Hans

@developernotes
Copy link
Member

Hi HansSchlegel,

The sqlcipher_export function does not migrate the user_version from a database. If you want to persist the user_version across an export, you will need to capture it from the old database and set it on the new database. You can use the getVersion() and setVersion(...) functions to perform this.

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