iOS 9 update seems to have broken sqlite3 - ios

After updating to the iOS 9.1 pre-release, our legacy iOS app that uses a local app sqlite database is no longer able to read tables ("no such table: xxx" errors). I have updated the sqlite3.dylib reference via Link Binary with Libraries (/usr/libs/...), and it seems to be able to connect and open the database just fine, but the "no such table" error still persists. One odd thing: when browsing to the database file on the file system during debugging, I am able to open up the database in Firefox SQLITE and see the tables in question, and confirm they exist.
One other point: the target architectures being built are arm7 and arm64 - $(ARCHS_STANDARD).
Thank you in advance for any tips / help!
Update: Even though the filepath to the database during debugging in the simulator exists and contains a valid database containing tables, trying to SELECT * from sqlite_master returns no rows -- leading me to think it is creating a new database, even though the file path it uses to open the database is valid and contains a database.

The problem ended up being related to event firing. It seems in iOS 8x, when the viewDidLoad, the filepath to the database was being set. Then the database was being opened and selected from without issue. In the exact same code in iOS 9 something was firing off before viewDidLoad which was opening the database with a nil filepath string. Not being a dedicated iOS developer, I am not 100% sure what the difference is in the two OS versions and delegate / event firing, but I thought I would answer my own post in case others had this problem!

Related

How to empty SQLite DB for iOS distribution/ Generic iOS build

I just submitted an app to the App store and it is now available. Unfortunately I realized that my development test data was included in the SQLite database! How do I go about emptying my database for the distribution, in other words removing all rows from tables? I know how to do this for a simulation (Reset content and settings), but since the deployed version just uses the Generic iOS build that does not run in the simulator, I am not sure how to clear the database.
Figured this out myself. You have to find the location of the sql file in your project.
Find the .sql file in your project.
Go to File-> Show in Finder
Then go to that location using Terminal and use sqlite3 to set up your DB as you want it.

The model used to open the store is incompatible with the one used to create the store Xcode 7.1

I created a core data model that was working fine until I added a new entity to the model, my code is fine I think... because Xcode can't detect any errors, but as soon as I run my app on the simulator the compiler gives me an error saying
reason=The model used to open the store is incompatible with the one used to create the store
I don't quite understand what this error means. I did search for references regarding this error but the one I found is outdated it was from Xcode 3.2, I'm currently running Xcode 7.1.1, interestingly enough there's no check mark on none of the replies. Despite that I still tried to use some of those methods and nothing has worked.
Things I tried
Resetting iOS Simulator -> Reset Contents and Settings...
Deleted the [Simulator App Folder]/Document/*.sqlite and ran the project
Have you had the same problem? If so can you help me troubleshoot it? Thanks.
That error means that you changed the model so that it doesn't match the one you were using when you created the app's data. It's the classic sign of changing a data model and not either doing model migration or deleting the app from the phone/simulator (and it's been pretty much the same as long as Core Data has existed, so old information is not irrelevant). Deleting the app from the simulator would normally be all that's needed to run the app again. If it's not working, then you're somehow leaving old data in place.
The best way to delete an app from the simulator is usually the same as you'd delete an app on a real device-- click and hold until the app icon starts moving, then click the "x" on its icon to delete it.
If deleting the app doesn't help, you're using old data some other way. Maybe you have some pre-loaded data built into the app that was configured using an old version of the model?
My favorite solution is to open the sqlite database with a third party app, then open the Z_MetaData table and delete the row found in there.
Works like a charm every time.
It may affect your 'migration' if you do migrations.
We do not, so not an issue.

Access sqlite DB IOS

I'm looking to access my sqlite database, be it via an application, browser or just the plain file. I can't find the file.
Not aiming for the dumbest question of the year award here, I seriously can't find it.
Supposedly it was in Library - Application support - Coresimulator - ....
Core simulator doesn't exist here, so I can't continue my search.
Then supposedly it was changed to Library - Developer - Coresimulator - Devices ....
Devices doesn't exist here, so I can't continue my search.
Allowing search for hidden files via command: defaults write com.apple.finder AplleShowAllFiles YES
Still not able to locate my sqlite database file. The application in which I'm using the database works like a charm, I just simply can't access the data that is stored because I can not find the file..
It probably is as stupid as can be, but please enlighten me as to where I can find it in my release of OS X. (10.10 yosemite)

viewing coredata with sqlite browser in xcode 5

Since upgrading to XCode 5, I am unable to view data in the sqlite file in my Applications Folder. The folder structure has changed somewhat but I can still find the correct App but when I open the sqlite file with the sqlite browser there does not appear to be any data in CoreData.
Any ideas?
I suggest you to use CoreDataPro app for viewing your CoreData storage.
My fork has minor improvement - alphabetical ordering of Simulator managed object models.
In iOS 7 SQLite's Write-Ahead Logging is turned on by default. In this mode data is split into three files (.sqlite, .sqlite-shm, .sqlite-wal). I've seen that some SQLite viewers ignore .sqlite-shm and .sqlite-wal files, thus not showing proper data.
I'm using SQLite Manager plugin in Firefox, it works pretty decent.
You can get the plugin here https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/
After you install the plugin you will see 'SQLite Manager' (with a database icon in blue color) item in Tools menu.

Core Data migration failing on Release builds only

I added an attribute to a Core Data model (iOS). I was on version 2, so I added a new model and saved the new attribute under version 3.
My loading code is standard (initializing a MOM using initWithContentsOfURL: pointing at my .momd directory inside my bundle), then passing that MOM to a NSPersistentStoreCoordinator.
Then, I download my app from the App Store, run it, and then try to test the migration. Lightweight migration is working fine on my Simulator and my phone in Debug (tethered to Xcode 4).
However, when I sync a Release build (using the "Archive" feature on Xcode) using iTunes, my app's data store fails to migrate with this error:
Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed.
(Cocoa error 134130.)", reason=Can't find model for source store}
Worse yet, the store gets lost in some voodoo state where it cannot escape - if I re-tether the device and install a Debug build from Xcode again, I can't "recover" the migration.
The error message above omits the details about my entities. I can provide that if helpful, but any ideas on what might be wrong here? I've read just about every question on SO about this error code and so far all of them have failed to produce a result.
I tried a manual migration, but it also yielded an error. However, since I only added 1 attribute to 1 entity, it doesn't make sense that lightweight migration isn't working.
Every time I've seen this problem, in my code or someone else, it has been XCode getting into some kind of bad state with regards to the model versions it deploys in the application. Open the Release IPA archive of your app, and look at what mom files are in it. If you see one of the previous versions missing, that is likely this same problem. As for a solution, I've had mixed results; some variation of the following steps works for me, but never in a consistent order.
Clean & delete the derived data for the project (make sure you have an archive of your released app saved so you can symbolicate if necessary)
Rename the previous model version files (in xcode), adding or removing the space between the name and the digit representing the version number (if it has a space, replace with '_', if it doesn't have a space try adding one)
Add a new version of the model, without changing any of it's content, and make it the 'current' version
I know these steps seem like grasping at straws, which is exactly what it feels like whenever this happens to me. You might consider using one of your support incidents with Apple, it would be nice to know what their official answer to this issue is.

Resources