Skip to content

Problem with Database version, always 0 after open #73

Closed
@HansSchlegel

Description

@HansSchlegel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions