Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

SQLlite Database not updated when user update through AppStore

I have a mysqllite database in my app. After my app was approved by the appstore I submitted an update to the appstore. This update have been approved by Apple butI've a weird bug when the user update his app :

The database (for convenience reasons I didn't change its name) is not updated for the user who already had a previous version of the app.

For new users who buy the latest version, the database is ok.
That's a very annoying problem and I cannot find anything in the documentation regarding this kind of issue.

Any help welcome

— asked August 15th 2010 by michel perrin
  • appstore
  • database
  • sqllite
  • update

2 Answers

  • Accepted Answer


    The iPhone caches the database so you have to give it a different name if you want your update to use a new database. I normally handle this with a version number in the name, like this:

    // Set up the database
    var dbVersion = 1.5;
    var db = Titanium.Database.install('mydatabase.db', 'mydatabase' + dbVersion);

    Then I just change dbVersion whenever there's a change to the structure of the database.

    Of course, because this would cause the installed database to be brand new, any user data would be lost.

    If you are changing your database, but you want to retain any user data, you may have to retain the old name and add some code to alter the database. It's a shame that sqlite doesn't support the ALTER TABLE statement, so modifying a table's structure in code is complicated but not impossible.

    — answered August 15th 2010 by Kenn Nesbitt
  • Are you updating your database with install DB?

    I remember reading install bug somewhere about renaming it, otherwise it would only execute once?

     var db = Titanium.Database.install('mydatabase.db','name');
     var db = Titanium.Database.install('mydatabase.db','newname');
    — answered August 15th 2010 by Daniel Lim
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.