managing a SQLite database

Discussion in 'iOS Programming' started by beachdog, Sep 8, 2008.

  1. beachdog macrumors member

    Joined:
    Aug 10, 2008
    #1
    I have a couple of questions related to using a SQLite database. I have a fairly large SQL database that is part of my app, and I will be allowing the user to modify the data in the database. I have studied the SQLiteBooks sample, and I noticed that in that example they make a copy of the database that is provided with the app, which the code comments indicate is needed because if the database packaged with the application were to be modified it would cause a code signing problem. I have followed the same pattern in my application, but have some questions:

    1) Since my database is fairly large, it seems like a waste of space for the device to end up with two copies of the database -- the "read only" copy that is part of the application bundle, and the actual "read write" copy that they application actually uses, which is copied into the Documents directory. Is there an alternative that is more efficient from the standpoint of storage usage?

    2) The sample code creates the "read-write" copy if it doesn't exist. However, in my testing I frequently need to make changes to the DB schema and then retest. However, my code sees that the database already exists and therefore does not copy over the modified schema. And if I modify the code to copy it over anyways I get a "file exists" error. How do I get around this?

    3) Problem #2 above led me to think that what I need to be able to do during testing is wipe the old application and any and all data off my device from time to time during testing, but then I realized I did not know how to do that. How can I delete an application from my device that I did not download from iTunes but rather installed via Xcode for testing?

    Thanks in advance...
     
  2. ghayenga macrumors regular

    Joined:
    Jun 18, 2008
    #2
    1) Include an empty database with just the table structure you want and when the user first opens your application download the base data from your server and insert it into the database. Not immediately ready to go, but saves the space of a duplicate copy.

    2) Include a version number table and check to see that the database schema is in sync with what the version of the program requires. If not *delete* the user database, or possibly copy the data out of the user database and then delete it, then copy the new version.
     

Share This Page