Reverse-engineering Core Data db results in "Can't find model for source store" error - ios

I have the task to re-engineer an iPhone app which makes use of Core Data to store some values. Unfortunately I do not have access to the original source code but I do have acces to old database files, copied directly from the device where the old version of the app is installed.
I have to create a new version of the app with some new functionality and I am trying to import the data from the Sqlite Db and migrate it to a new version.
I am already failing at the task to read the data from the old database. Though I can open the Sqlite file and such was able to exactly reproduce the data structure in my own datamodel, everytime I try to read the data, it fails with a
Can't find model for source store
error.
Ignoring the old data is not an option because there is important data stored there.
I googled for solutions and tried every recommended solution related to migrating data but it all fails. Maybe I can not use the Sqlite created by another app? Or so I overlook something in re-engineering the structure of the datamodel even when I used exactly the some field names and datatypes? Is there another way around this?

I could not solve the issue but I found a workaround. By using Sqlite directly, I was able to query the legacy data and import it into my newly created data model. A good starter point for using Sqlite is here:
http://www.techotopia.com/index.php/IOS_4_iPhone_Database_Implementation_using_SQLite

Related

How to fetch record from sqlite database that has been created automatically when implemented in coredata

I have app in that i am using coredata. And when i install the app three files are getting created in the document directory called “test.sqlite, test.sqlite-shm and test.sqlite-wal". And now in second app i copy the test.sqlite in the folder and i want to access the database and tables but i got error like this "no such table found". Is there any issue that i create the database with coredata? please help me.
You either need to:
send all of the sqlite* files that Core Data creates
export the content from the data store, format it and send that
Option 1 should work and be fast to implement, but it isn't very future proof. Option 2 will take longer but is a much better solution.

No data in tables when copying sqlite database to ios app

I'm using core data and am pre-populating it using a SQlite database that I provide in the bundle. It's been working fine for a while, however I've just edited the database and when I copy it over there is no data displayed. So I opened the database that is on the ios simulator, in base, and I found an sqlitemaster table that contains lots of SQL statements such as CREATE TABLE..., but the tables I want don't contain any data.
What's weirder is that after a while the database is fine and all the data is in it as normal. Is this because the statements in the sqlitemaster table were executed?
Has this happened to anybody else? I don't know whether it's because I've upgraded to iOS 7 or not? If anybody could point me in the right direction that would be great
The latest iOS Core Data SQLite backend uses journaling. You should notice .shm and .wal files in the same directory as what you assumed was your main sqlite backing store for Core Data. This data eventually gets into the main file, but journaling optimizes some situations for Core Data configured with SQLite.
As a developer, you generally never care about this from within the app, but if you are trying to inspect the persisted Core Data graph via the actual file, you'll need to be aware.
I've had a look around and the journaling was causing it to go all weird. Found this post which shows the same problem I had. If anyone else has this look at that post

Core Data duplicate project for update of a submitted app

i have submitted an app on the app store that uses core data.
The problem is that i duplicated my project and then lost the first source code. If i update the app using the "duplicated" source code does it delete all core datas users may have stored? i know that if you change the file file-xcdatamodel without mapping the previous datas you will lose all you had stored, can i assume the duplicated project use the exact same file?
thanks in advance
In that case I think that, if you didn't modify your xcdatamodel, the data stored by user will keep during the upgrade. In order to be sure, you can install your own apo from App Store, save some data, update this app from Xcode with your new version and check if the stored data still are there.
If you've modify your xcdatamodel, you must perform a light or a heavy migration, depending on your canges.

How to get data from installed DB and insert the extracted data in New DB in iOS

I have a Database (used SQLite ) file that i copy in the documents while the applicaiotn is installed , now i have added one field in a Table and i want to install new DB in the Device. To achieve this i think i have to do Database Migration.
The issue i am facing is that I am not able to think the Code to get Whole Data from the installed Database and then insert that extracted data into New Database (while installation) , I have less experienced in iOS Programming so please Provide details from Scratch .
Thanks in Advance :)
This is not really an iOS issue, but a conceptional problem.
If you want to add new tables to the database, why do you copy an old version of the database rather than one that already contains the new tables?
As for the import of existing data, simply read out the old database and write it to the new database. This should be simple enough with the available SQLite API. Explaining the details would be beyond the scope of this question. (You will find enough info on these basic things online.)

iOS App SQLite database structure change

I am updating an old iOS app which used sqlite database. I changed the database structure adding columns to existing tables. Now, I am testing it on my device. If I clear my old app from iPad and then run this new updated version on it, it is working fine. But if I have the old version installed on ipad already and test this updated version, it is somehow using the old database instead of the one updated. Can some one help me why it is doing this?
My guess and to try and make a simple answer for you is this. It's likely you updated the database in the project file - which means when you run it, your new db will exist in the bundle. files in the bundle cannot be updated, so its common practice to copy the database out of the bundle and store it somewhere in the ios sandbox. I usually use the documents directory to keep it simple.
Most likely what is happening is that when you run it over a pervious install, it see's that the file is already copied over to the device so it does not touch it, however on new installs, it probably sees the database is missing so it copies it there and that is why on new installs it works fine but existing ones it does not.
Look in the app delegate or your root view controller for code that checks for the existing database and copies the database over if needed on startup.
If you need to update the database on existing installs, you would need to force the copy.
Beware though if you have data in the existing database not to overwrite it if its important. If important data is stored there, you have to either do a little shell game of getting the data and importing into the new database, or maybe a simpler way, is to run the database schema modification commands on the existing database so it is the same.
again, beware and make a copy of the local database file before you run those commands, just in case.
best of luck
In iOS, a SQLLite database is really just a file. When you used the old app, it created the schema in the database file. When you load the new app, the data remains, untouched. If you want to use the new schema, you will have to detect the old schema and update the existing data. I believe that there are documented ways to deal with this. Bryanmac's question reference seems to be a good place to start.
When you install a new version of your app, iOS actually installs it in a new directory and then copies the contents of the documents folder from the older version to the one in the newer version. If you want to just use your new db, the best way is to have this db renamed or stored in a different directory inside your app's document store.
Here's a relevant article on updating An sqlite CoreData backing store on iOS:
http://www.musicalgeometry.com/?p=1736

Resources