Question

What is best possible way for in-app Sqlite Data Migration. As I am new to iphone development , I created my app using Sqlite. Please help the concern

Was it helpful?

Solution

You create a database upgrade procedure and make it execute the first time when the application starts.

So this will create a new table through a create statement when application loads for the first time.

And also it will help you save all the data that user has in his current database. This is what is most recommended as there is no additional requirement to migrate your existing database anywhere.

Also please refer to my answer in this link:

Don't wan't to replacing the old database when app is updated

Hope this helps you.

If you need more help then please feel free to contact me.

EDIT:

In case when you need to make changes to an exiting table which contains some data then you need to do some steps as follows:

1) Rename the existing table

Say TableName was 'TestTable', So Rename the table to 'TestTableOld'

2) Create a new table called 'TestTable' which has the new columns you want and other altercations made.

3) Copy data from 'TestTableOld' to 'TestTable' with the query like:

Insert into TestTable('col1',col2'...'coln') Values Select col1, col2, col3,...'coln' From TestTableOld;

4) Drop the table 'TestTableOld'

Follow the above four step procedure as this would work as an alter statement and also it would preserve all your data from your original table.

Hope you get it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top