Titanium Community Questions & Answer Archive

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

New Database sqlite not updated when deployment (emulator or device)


I put the sqlite database inside the resource folder and it seems to get copied into the emulator or actual device.
But when I made some changes to the sqlite file and I try the emulator or device launch again, it seems like the old database is not being replaced because I get errors accessing new data.

It only work after I manually delete the App from the device or emulator.

Is there a way to resolve this issue?

— asked March 27th 2010 by Peter Lum
  • database
  • device
  • emulator
  • sqlite
  • update

4 Answers

  • Accepted Answer

    The problem is that the iPhone simulator is caching the SQlLite db so you need to restore the simulator settings(iPhone simulator/initialize content and settings) everytime you make changes in your db in order to be able to notice the changes.
    Hope this helps.

    — answered March 29th 2010 by michel perrin
    • Absolutely bloody marvellous. I thought this may be the answer to my problem (the same issues Peter was experiencing) but now I am unable to even run my project in the iPhone simulator.

      I'm using Titanium Studio build on OSX, iOS SDK 4.3 and am totally unimpressed with the inability of Titanium Studio to react to project cleans, total forced rebuilds or any other approach I've taken to try and force my project to pick the latest database file from my Resources folder - in either the iPhone simulator OR android emulator.

      Does anybody have an up-to-date working solution for this?

      I am sooooo close to dropping Titanium Studio completely as the tool is approaching unusable for me.

      — commented August 16th 2011 by Robert Turrall
    • Thank you!

      — commented May 20th 2014 by Dat Nguyen
  • Yes, there is.
    You can do this by giving your database a new name when installing it. The easiest thing would probably be to append a version variable to the name and then update this on database changes:

    var dbVersion = 1.0;
    Ti.Database.Install('mydatabase.sqlite', 'mydatabase' + dbVersion);


    — answered March 27th 2010 by Jacob Waller
  • I've done this but now i have a strange problem where it works fine on my simulator but doesn't update the database on my device, even if i delete the app then reinstall. How is it caching the database when I am using versioning as well as deleting the app?

    — answered July 6th 2011 by Ben Palmer
  • Hey Ben,

    I'm thinking that you could use something similar to this:

    Ti.Database.Install('mydatabase.sqlite', 'mydatabase' + dbVersion);

    Based on this, I think only the previous database will be destroyed (the DB that's in app-memory)

    Let me know how it goes


    — answered July 26th 2011 by Ross McKinley
    • oops… that should read

      var dbVersion = 1.0;
      Ti.Database.Install('mydatabase.sqlite', 'mydatabase' + dbVersion);

      — commented July 26th 2011 by Ross McKinley
    • I'll try that. I ended up finding a work around where I called the database a different name when installing but also made a copy of it eg. mydatabase2.sqlite

      — commented July 26th 2011 by Ben Palmer
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.