IPhone SQLite File Management

I am developing an application and I am using SQLite as my database. I want to add and update a sqlite database for the entire duration of my application, so I copied it to the documents directory so that I can do all sorts of things with my database other than just selecting from it.

But since I design "time", my database changes frequently (database architecture is created by another developer) through the process

On iPhone, I check

  • if the database exists in the document directory
  • (if not) copy it to it.
  • use this database

but when I want to update my database (I did it in a separate sqlite manager) it fails in the process of copying the new version because I only check if the database exists.

Have any of you guys experienced the same problem? and what have you done to fix this problem.

My only idea was to create a settings table and pass a string to check the version number of the database.

Is there a way to edit the sql file from the document directory in any sqlite management tool?

or are there any better solutions?

0


a source to share


4 answers


What I did in my application: - First I do the same. Check if the DB is in the documents or not. - Then I check the previously installed version: a small text file in the documents tells me this - If there is a need for an update, I merge the databases: one in the / Documents folder with another from the application package. - In my case, I need to unite. In your case, you can just copy, unless the user changes it.



+1


a source


I am creating a series of sql scripts that can be upgraded from the previous version 1.sql, 2.sql, 3.sql, etc. When I open my database, I ask for the version from the settings table and compare it to the newest .sql file I found in my application. If there is a newer version, I run the .sql scripts until I encounter the latest version. This has now worked for me on several projects.



+1


a source


Have you tried uninstalling the app on iPhone and then deploying the app again afterwards?

0


a source


What I am doing is similar to what you did, except that I added a small second table to the database. This database contains only one record, the version number of the database. So you start with version 1 on this database table. Then, when you change the structure, you update that version number to 2. In your startup codes, check if the database exists. If so, check the version number of the database. If the version number of the database is as expected, just continue. If this is less than you expect, call some code to update the database to the current version and then continue.

0


a source







All Articles