Search code examples
androidsqlcipher

Database migration in sqlcipher


I used sqlcipher 3.* to encrypt my database. It work very well; But now I want to migrate to new database ( Version 2 ).When I change database version, open database do not work and can not open previous database.

myDataBase = SQLiteDatabase.openOrCreateDatabase(DB_PATH,DB_PASS, null);

Exception occur in this line in class SQLiteDatabase

this.dbopen(this.mPath, this.mFlags);

mFlags does not value.

The second problem, is database version. always return 0 . My current sqlcipher's version is 3.3.1-2 that add it from Maven. I add icudt46l.zip to assets folder. and add commons-codec.jar , quava-r09.jar and sqlcipher-javadoc.jar to libs folder.

Thanks


Solution

  • It sounds as if the version of the database is not being set. You can either do this manually with setVersion(…) and getVersion() from your SQLiteDatabase instance, or you would be required to provide a value if you are subclassing SQLiteOpenHelper. We have a test that verifies the onUpgrade(…) function is called once the version number changes with a SQLiteOpenHelper subclass.