Problems with updates at AppStore - iphone

I have a problem with my application (first one) when people downloading it from appstore, here is the scenario:
I have an a quiz-app with 2.174 questions in the database (core data and sqlite3). The questions resides first in a .txt file and is updated into the database based on the filename of that .txt name, which includes a date. When the app is started and finds that the file name is changed the following happens:
Delete all records in the database
Read in all questions and show update screen
Display first game screen and start playing
The first version of the app had 874 questions and now i have done an update of the app plus added quite a few more questions.
When i test this on the simulator or the device there is no problems at all but i just found out that the following:
When people that already have the app, the first version, the database updates
When the app is downloaded for the first time it only add 874 questions, the same as the first version of the game, but with the updated interface.
I know this is not a lot of details but the feeling I get is that the "old" version is not completely wiped out before the new version is added into the store. Also, i do not understand why there is a difference.
I guess that if i distribute a version with an already updated database it should already been updated in the appstore. If i remember correctly the new version was distributed with an updated database.
Anyone nice that have any ideas or recommendations how, and why, this is happening?
Cheers

If you would have set the version number to your database for your iphone could have been easily handle, save your version number into your db and whenever database is called, compare the version against the expected version
If new version > older version change the schema and update the app version number.

It seems to me that the second version of your app does not correctly check for the (bigger) database to be copied over from the bundle to the app's documents directory. Consequently, the app would simply initialize the database (created lazily in AppDelegate) and this database would be empty. It would then proceed to import the 874 questions.
Check
the bundle includes the correct version of the database file to copied
the code that does the copying of this file.
BTW, if the data model has not changed and the game does not modify the database you might want to consider shipping a new complete database file rather then updating the old one by importing from the text file.
Cheers,
Sascha

Related

Releasing update for the application in App Store

Here I've got a question concerning releasing update of the application in app store.
Suppose I've an application installed on my iPhone, which has some database inside, i.e. overtime user has entered info and the data were kept locally.
If the new version of application is released, and installed on my iPhone. Will the database be lost ?
I suppose all the information of the application, is removed and the update is installed like a new app. Please confirm.
Thanks
No the users data will not be lost.
When you update an app only the bundle data will be updated, meaning the .app directory of the installed app. Any other directory, like Documents and Library will not be touched.
If there is any data in for example the Documents directory that need updating then you have to write code to detect that and make the necessary changes.
If the database is used by Core Data then you will need to version and migrate the data.
All the files stored inside your app's documents directory (which is usually where db file is stored) are preserved during app update.
If you would have set the version number to your database for your iphone could have been easily handle, save your version number into your db and whenever database is called, compare the version against the expected version If new version > older version change the schema (this is needed if you would have changed the schema of your database) with using SQL ALTER statements and update the app version number.
so whenever user is going to update or fresh installation, it will check the new version with your older version, if it differ then update schema, and if its same no need to make any changes.
If you would not have made any schema related changes (for example adding new column..) then you do not need to worry, user will not lose the data.
my guess is that it would not be replacing any of the existing files instead just updating them if any changes....the best example of data is not lost is that.....i usually update most of my games. and they do preserve my highscore even after the updates.. lol! So, go on. Nothing will be lost. Nice question though. :)

What is the behavior of an application when upgdraded at appstore

I wanted to know something which is very disturbing for me. i.e.
Lets say I have an App. which is in the Appstore and running fine.
This App. has a local database with lets say 5 tables.
I update this App. and add 2 more new tables, which makes it a total of 7.
When the previous app version users will upgrade to the newer version. Will the database be updated also for the previous version users ?
If yes ?
then will the previous data will be removed.
If not
then the code will obviously make some crashes as it is going to need the new things which are not replaced.
Waiting for your precious comments.
It will all depend on your database. If you are using CoreData, you can migrate the users data into the new database and structures. All the information for your data model is stored in the .xcdatamodel class for your project. It isn't bundled into your code the way other files are.
The part you would need to look into is the Model Versioning Identifier. Here you will be able to increment your MOM, Managed Object Model.
You can also migrate the data over as well. I would review Apple's documentation on CoreData with focus on versioning and migration. Good luck.
Apple Core Data Versioning
If the database is based on coredata then you will need to use .
But if you are using sqlite DB
Then you can save the version number of your app into your db and whenever database is called(with new installation/upgrade), compare the version against the expected version If new version > older version then change the schema (this is needed if you would have changed the schema of your database) with using SQL ALTER statements and update the app version number. so whenever user is going to update or fresh installation, it will check the new version with your older version,
if it differ then
update schema,
and if its same
no need to make any changes.
If you would not have made any schema related changes (for example adding new column..) then you do not need to worry, user will not lose the data.
The contents of the documents directory is left unchanged. The contents of the .app bundle is completely replaced with the new version.
If you store your database in the documents directory and it is modified by the application, you will need to perform some migration to upgrade to the new version. If it's just a read-only database, you can copy over it with the new database.
It depends on where database is placed. All files in application bundle will be replaced. Files in Documents directory will remain intact unless you overwrite them...
Where do you store your database?
What i consider a good approach is to place database in bundle then on first run copy it to documents directory so that you gain RW access.
In your updated application you can check if database exists in Documents read it and update tables to new version, if not then just copy file from bundle to new location.

Does data base change with new update iPhone app

I have a program that my user save something on it. I want to release new version.
My question is: if my users update their app, will their data still be there or not?
My new release its not part of database.
When you update an app, the data is preserved. As far as I am aware, the process is the same as when you test a new build from Xcode.
The only time this could be an issue is if you are using CoreData, and you update your model. In this case, the old store will not work with your new model unless you migrate the old store. Apple has documentation on migrating CoreData stores here.
The database will be in sandbox of the app. So until user deleted the app the database will be there. You can upgrade the app. But if there is something changes into database then you again need to copy the new database to documents directory either by installing the app again and remove the older version Or by manage through code.
All contents of the Documents directory on device is preserved, update only replaces the application bundle, which is read-only anyway.
Can you please let us know for saving what kind of data model you are using, whether Core Data stack or SQLite. If you are using one of them, its pretty obvious you have to write and fetch your DB from documents directory. If your new version does not contain one, it wont work either.

Can't refresh iphone sqlite3 database

I've created an sqlite3 database from the command line and inserted several records. My app retrieves all of them and shows them just fine. I then go back and insert a few more records via the sqlite3 cli, erase the db file out of the simulator's documents directory so that it will be recopied from the main bundle, and the run the app again only to find that it only displays the original records I inserted. The new records do not show. I verified that the new db file was copied to the simulators documents directory, and when I point the sqlite3 cli at it, I can do a select * and see all the records.
What could be going on here? It almost seems as if the previous version of the db file is being cached somewhere and used instead of my updated version.
//Scott
every time you rebuild and run an app in xcode, it creates a new folder under the iphone simulator's applications folder. If your sqlite db is being included from xcode the old db could be put in the new folder while the one your editing is in the old and now unused folder.
I haven't verified his answer, but Stephan Burlot said:
Sqlite uses a cache for requests. Close & reopen the database from time to release cache memory.
(I don't think it's true that every SQLite instance caches requests, but that might be the case on the iPhone.)
Obviously you aren't concerned with memory, but if it is caching requests, maybe just a close and reopen is all you need.
If that isn't the case, my next guess would be that your app is not pointing to the file you think it is pointing to -- did you have it pointing to a database with a different name at one point and forget to update the app? You could verify this by updating the db from within your app, then checking for those updates with the CLI. You might just find that they are not looking at the same db.

iPhone SQLite File management

I'm developing an application and I'm using SQLite as my database storage.
I want to add and update the sqlite database throughout my application duration, so i copied it to the documents directory so i can do all kinds of stuff with my database except only selecting from it.
But since I'm developing "time", my database changes frequently (the database architecture is made by another developer) through the process
On the iPhone i'm checking
if the database exists in the documents directory
(if not) copy it to it.
use that database
but when i want to update my database ( i made in a separate sqlite manager ) it fails through the process of copying the newer version because i'm only checking if the database exists.
Does anyone of you guys experienced the same kind of problem ? and what did you do to pass this kind of problem ..
my only idea was to create a settings table and hold a row that check's for a version number of the database..
Is there also a way to edit the sql file from the documents directory in any sqlite management tool ?
or are there better solutions ?
What i did in my app:
- First i do the same thing. Check whether DB is in Documents or not.
- Then i check the previously installed version: small text file in documents tells me this
- If there is a need of an update, i merge the databases: the one in /Documents with the another one from app bundle.
- In my case i need to merge. In yours may be you can just copy over, if user doesn't change it.
What I do is create a series of sql scripts that are capable of upgrading from a previous version 1.sql, 2.sql, 3.sql, etc. When i open my database i query the version from a settings table and compare it with the newest .sql file i've found in my application bundle. If there is a newer version i begin running the .sql scripts until i have encountered the latest version. This has worked out pretty well for me on a couple of projects now.
Did you try to delete application on iPhone, and after that to deploy application again?
What I do is similar to what you did, except I added a small second table to the database. This database just contains one record - a database version number. So you start with version 1 in this database table. Then, when you change the structure, you update this version number to 2. In your startup code, check to see if the database exists. If so, check the version number of the database. If the version number of the database matches what you expect, just continue. If it's less than what you expect, call some code to upgrade the database to the current version and then continue.