Not an error: Could not open the database in read/write mode

I have implemented Cipher(SQLCipher version 4.2.0) in my previous Sqlite3 db helper class, I have a old db data and i am trying to export old db file data to new db file, when i am opening db I’m getting error like-- not an error: Could not open the database in read/write mode.
but CURD operations are working fine with newly created db file.
SQLiteDatabase sqlDB = mDbHelper.getWritableDatabase(“abc”);
SQLiteDatabase sqlDB = mDbHelper.getReadableDatabase(“abc”);

here is my code :
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(oldDb.getPath(), “”, null);
db.rawExecSQL(String.format(“ATTACH DATABASE ‘%s’ AS encrypted KEY ‘%s’;”,
newDb.getAbsolutePath(), “abc”));
db.rawExecSQL(“SELECT sqlcipher_export(‘encrypted’)”);
db.rawExecSQL(“DETACH DATABASE encrypted;”);
int version = db.getVersion();

Please help me out :slightly_frowning_face:
Thanks in advance.

Hi @JyothiSri,

At what line of the code does the exception occur? Are you using the android-database-sqlcipher library, or sqlcipher-android library? We have an example import scenario within the android-database-sqlcipher test suite here, and another import example using sqlcipher-android here which you might try running and comparing with your application.

As an aside, the latest version of SQLCipher is 4.5.4 (though this shouldn’t be related to your issue). You would need to set the database version from the old version to the new database; your code is reading and writing the same value on the old database.

Thanks for the reply.
I am getting the error at this line–>SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(oldDb.getPath(), “”, null);
And I am using net.sqlcipher.database.SQLiteDatabase;
And one more thing is latest versions are not supporting to my application.
Is there any wrong step I did, same as above example I’m trying to openOrCreating old db with empty password here only I’m getting the error.

Hi @JyothiSri,

A few follow-up questions:

  • Where does oldDb.getPath() evaluate to?
  • Is it old database file within the databases directory of the application?
  • Have you tried oldDb.getAbsolutePath() instead?
  • What are your results of running the import example but using your source database instead?

In what way is 4.5.4 not supported in your application?

I am getting a old db path with getAbsolutePath() but I’m getting warning msg i.e “old db path is not found”,
After i used source database I’m getting java.lang.IllegalStateException: database not open. first time it is working perfectly. if it is running 2nd time I,m getting above IllegalStateException.

Hi @JyothiSri,

If the old database path does not exist, you will not be able to migrate it. You will need to debug your application further to determine whether the database file exists, then construct a path to it for your conversion process.