# Handle SQlite Sqlcipher database upgrade on database update

**URL:** <https://discuss.zetetic.net/t/handle-sqlite-sqlcipher-database-upgrade-on-database-update/3317>\
**Category:** Uncategorized\
**Created:** [December 26, 2018, 11:44am UTC](https://discuss.zetetic.net/t/handle-sqlite-sqlcipher-database-upgrade-on-database-update/3317 "2018-12-26T11:44:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uche01](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@Uche01](https://discuss.zetetic.net/u/Uche01)\
**Post date:** [December 26, 2018, 11:44am UTC](https://discuss.zetetic.net/t/handle-sqlite-sqlcipher-database-upgrade-on-database-update/3317/1 "2018-12-26T11:44:08Z")

</div>

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??

---

<div class="post-metadata">

**Author:** ![sjlombardo](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/sjlombardo/32/3_2.png) [@sjlombardo](https://discuss.zetetic.net/u/sjlombardo)\
**Post date:** [December 27, 2018, 1:22am UTC](https://discuss.zetetic.net/t/handle-sqlite-sqlcipher-database-upgrade-on-database-update/3317/2 "2018-12-27T01:22:43Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![Uche01](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@Uche01](https://discuss.zetetic.net/u/Uche01)\
**Post date:** [December 27, 2018, 1:39am UTC](https://discuss.zetetic.net/t/handle-sqlite-sqlcipher-database-upgrade-on-database-update/3317/3 "2018-12-27T01:39:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [December 27, 2018, 3:20am UTC](https://discuss.zetetic.net/t/handle-sqlite-sqlcipher-database-upgrade-on-database-update/3317/4 "2018-12-27T03:20:46Z")

</div>

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](https://github.com/sqlcipher/android-database-sqlcipher/blob/master/android-database-sqlcipher/src/main/java/net/sqlcipher/database/SQLiteOpenHelper.java) 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](https://github.com/sqlcipher/sqlcipher-android-tests/blob/master/app/src/main/java/net/zetetic/tests/VerifyOnUpgradeIsCalledTest.java) to give you a feel for what I am referring to.

---

<div class="post-metadata">

**Author:** ![Uche01](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@Uche01](https://discuss.zetetic.net/u/Uche01)\
**Post date:** [December 27, 2018, 7:45am UTC](https://discuss.zetetic.net/t/handle-sqlite-sqlcipher-database-upgrade-on-database-update/3317/5 "2018-12-27T07:45:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [December 27, 2018, 4:18pm UTC](https://discuss.zetetic.net/t/handle-sqlite-sqlcipher-database-upgrade-on-database-update/3317/6 "2018-12-27T16:18:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Uche01](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@Uche01](https://discuss.zetetic.net/u/Uche01)\
**Post date:** [December 27, 2018, 5:17pm UTC](https://discuss.zetetic.net/t/handle-sqlite-sqlcipher-database-upgrade-on-database-update/3317/7 "2018-12-27T17:17:09Z")

</div>

Thanks. I fixed the problem…

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [December 28, 2018, 3:27am UTC](https://discuss.zetetic.net/t/handle-sqlite-sqlcipher-database-upgrade-on-database-update/3317/8 "2018-12-28T03:27:32Z")

</div>

Hi @Uche01

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

---

<div class="post-metadata">

**Author:** ![Nasser\_Sawadi](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/nasser_sawadi/32/1165_2.png) [@Nasser\_Sawadi](https://discuss.zetetic.net/u/Nasser_Sawadi)\
**Post date:** [October 7, 2019, 2:34pm UTC](https://discuss.zetetic.net/t/handle-sqlite-sqlcipher-database-upgrade-on-database-update/3317/9 "2019-10-07T14:34:59Z")

</div>

hi  
How to you fixed the problem
