Handle SQlite Sqlcipher database upgrade on database update


#1

Hello team, I have an sqlcipher encrypted sqlite db. Now I have added new records to tables in the db and I rolled out update on playstore.

The problem I have is that the updated db is not reflecting after users update the app.

Please how do I handle database upgrades/updates with sqlite/sqlcipher??


#2

Hello @Uche01 - I’m not sure that we have enough information here. Can you explain what you are trying to do, and how you are trying to do it (e.g. are you trying to use onUpgrade, replace the entire database with a new copy from assets on install, selectively insert new records into a local application database, etc)?


#3

Yes, I’m trying to replace the database with entirely new one.
As I said I have an existing sqlite db. I later made changes to the db by adding new records to some tables. Now when I update my app, I need to see the newer updated database. However the database did not change after I installed the update to my phone.

What do I need to do so that the changes in the db reflects in the app after update?

Thank you for your response


#4

Hi @Uche01

Can you share what client library you are using to interface with SQLCipher? Without that it will be more difficult for us to provide you with specific advice for your given scenario.

For example, in SQLCipher for Android, a common pattern is to extend the SQLiteOpenHelper class which provides an mechanism for directly tracking the current version of the database schema via the PRAGMA user_version, and provides onCreate(...) and onUpgrade(...) facilities for you to hook into. We provide a sample scenario within our test suite here to give you a feel for what I am referring to.


#5

I’m using SqliteOpenHelper library. I extended the class and overrode OnCreate and OnUpgrade methods. However these methods have nothing in them.


#6

Hi @Uche01

You will have to provide your own implementation within both onCreate(...) and onUpgrade(...), the database connection is provided within those callbacks. Typically, you will create your current database schema within onCreate, whereas the onUpgrade function will be called when you first access your database and the user_version stored within the file is less than current version number provided to the constructor of SQLiteOpenHelper allowing you to perform schema/data migrations for the client database.


#7

Thanks. I fixed the problem…


#8

Hi @Uche01

Excellent, we are happy to hear you resolve the issue!