Updating an SQLite database on the iPhone - iphone

I have very little knowledge about app development, but I am updating an existing SQLite database (simple text changes to the html that is stored within the database). Everything works fine, but when I submitted the app to Apple the changes weren't showing when people upgrade (if you download it for the first time - straight from the App Store - it is fine, so the database must be saved to the cache).
Does anyone know how I can overwrite the existing database? People have said to change the file name of the database, but will this make the app run slower (will two databases be stalled in the cache). Also peoples data are stalled on the database (bookmarks etc.) so somehow that info still needs to be retained if possible.
Any help would be appreciated.

i also would recommend you to rename the database. thats the easiest and fastest way. rename your model and set it to the standard.
i am using this solution, too. my app is not running slower then before. just test it.
please also see this two links for adding new models to your project:
create new model version(apple)
How to Add Core Data to an existing Utility Application

I think that change should happened only in the build u r tested and not in you have uploaded on appstore.
So better way u upload it again... With all testing done.

Related

iOS - what is the right way to deal with a data model change?

I already have an app in the app store. I want to do an upgrade. My local data store has changed, with an extra table, and with a few fields added in the existing table. I want to retain the data in the old tables. How would I go about doing that? Could someone point me to tutorials that handle that kind of change?
Assuming you're using SQLite: Use a new database with a different name for your update. On startup, check for the table with the old name, copy the data you want, and delete it when you're done.
CoreData has it's own update data which may or may not work for you. You should look into how to change the data model.
Check out Apple's docs on migrating a core data instance. They make it super easy for 90% of the cases. The basic idea, is you break you xdatamodel into versions, so it has a path for migration
Here's a tutorial that might help you Core Data Migration

How to manage the data to fill a Core Data database with a lot of data (Edit: changed title)

I hope all of you have had a good Christmas :-)
In my app i have a database, using Core Data, that requires a lot of data, at least 1.500 records consisting of 6 fields. That means at least 9.000 lines of data. All data is pure text.
During the development phase i have 250 records to test on.
The way i do populate the DB at this point is that i have a text (.txt) file, which i edit in Word and then reads into my database. This is very inconvenient for many reasons such as if i save it, by mistake, in the wrong format it all screws up (i have Swedish characters that changes).
Given the amount of records i will need i would like to ask for advice how people do these things and what to use? Is there some sort of (free) database available that i could use etc.
Cheers
For editing use notepad, notepad++, or gedit. You won't have issues with MS Word specific characters.
I am not too familiar with Core Data, but I believe it uses SQlite on the backend.
I have implemented SQLite directly into a few developments that I have worked on. It might be worth your time to take a look.
Can you give more details about your app? Platform, how often data is accessed, how often it is modified, etc.
Hmm, one way to get started on this might be to fill the Core Data store a single time, and then, whenever you need to run your tests, just copy this store file out of your application bundle into your documents directory. I maintain a "Reset All" function in a game I've worked on using this method, and it works great for very quickly populating Core Data.
Hej,
currently I am developing an app with very similar requirements - a prepopulated Core Data database with 1200+ entries with more or less the same amount of fields.
The data I receive is in xml format. I've written a small mac app which features the same core data model as the iphone app does - it will read the xml and create core data entries accordingly. I then take the database file my mac app created and add it to my iphone apps bundle, from where it will be copied to the documents folder on the first launch (or whenever a reset to the factory data is required).
This is working perfectly, I think you could do something very similar. The only difference would be that, instead of parsing xml, you'd need to write something that reads your textfile. Fear not, it's easy to do!
I've taken the approach to add a unit test that determines if the database exists. If the database doesn't exist, the test creates it from a text file (usually a plist or csv).
This approach enables me to: alter the underlying data via text, "clean" the database by simply deleting it, and run tests against the data. Since you're using CoreData, there might be some additional benefits by ensuring your schema matches the dataset; I once found I'd accidentally set an attribute to not allow nil.

How can I make permanent the custom data I have manually put into my core data database?

Ok, I am admittedly pretty new to core data, and am still not quite as knowledgeable as I would like to be. I am doing some pretty basic data retrieval from the database using values that I went in and added myself (using the sqlite editor Base).
I got everything working in my simulator, and I thought that life was just dandy but I went in and installed the app on my 2g iPod touch, and when my pickerview went to go get data...there wasn't anything there! I guess it's not terribly surprising, but I was thinking that the app build would just copy the db that I had setup??
What is going on? What do I need to do to make it so that the pre-loaded data is available for any and all downloaders of my app?
Thanks!
The core data persistent store won't get automatically added to your app. You will need to add this file to your project so that it becomes part of the app bundle when you build the app. You can see what will happen in xcode after you've added this file under your target settings.
Additionally apple discourages modification of the SQLite data store directly outside of core data. You may be better off just using SQLite in that case. If you feel you really need core data, you may want to make a default SQLite database that is part of your app. The first time the app is run (or the data is reset) you can then import that data into your user's custom core data persistent store. See this portion of apple's documentation on how to import an existing SQLite database into core data. This allows you to have default data but gives you the flexibility of being able to reset the database easily.

Are there good iPhone SQLite3 tutorials which really start from scratch?

I always find something that starts somewhere in the middle, where the database already exists or where some special classes or files have already been added to the project. I want to see the first steps, since they're crucial. i.e. somebody said the database has to be copied into a readwriteable dir on the iphone. Anyone knows a complete tutorial on this?
(no, I don't want to use Core Data or OS 3.0)
You might consult these other similar questions:
"iPhone create SQLite database at runtime?"
"Where’s the best sqlite3 tutorial for iPhone-SDK?"
"Add SQLite Database to iphone app"
Additionally, the SQLiteBooks sample code that Apple provides takes you step-by-step through the process of copying an existing database from the resources directory of your application bundle to the application's Documents directory. It is a little more complex when working with the database, however.
Mobile Orchard also has a list of resources for SQLite on the iPhone.
The source code to my iPhone application Molecules is available, and for now it uses SQLite as a data store (that will be changing to Core Data soon). You may be able to pick something up from that.
What about SQLite Persistent Objects? I used it on my last project and it was cake.
http://iphonedevelopment.blogspot.com/2008/08/sqlite-persistent-objects.html
http://www.galloway.me.uk/2009/02/sqlite-persistent-objects/

Core Data Migration really Slow, Why does it happen at all?

I'm developing a desktop Mac OS X App that saves its very simple data into SQLite with Core Data and a companion mobile App for iPhone that simply needs to read data from the desktop App. Although they share the same Managed Object Model when I load the SQLite database on the mobile app the data takes several seconds to migrate the data. I really would like to avoid this long wait as it appears linearly related to the size of the SQLite file.
Why is data from the same Managed Object Model even needing to migrate at all?
Does anyone know of a way to avoid needing to migrate?
I've discovered what was causing this problem. Although it is probably very obvious I'll relate it so hopefully no one else will make this mistake...
I had two distinct Managed Object Models in my project. Having more than one seems to force Core Data to try migrating to figure out which data matches with which MOM.
As a solution I was able to manually merge the models so both data sources can be represented with the same MOM.