viewing coredata with sqlite browser in xcode 5 - ios

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.

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.

Core Data not saving directly to sqlite

In the old days, when I developed iOS app using Core Data for < iOS 7, I remembered that if I am not mistaken, sqlite file in emulator was not saved directly. I need to go to Home in iPad, then the sqlite file was updated.
Now I faced same thing. I observe my sqlite file never get modified, only the SHM and WAL file. So how can I check my data in sqlite?
The data is being persisted by Core Data since my app can fetch the new inserted/updated data.
Any advices from anyone?
Finally after some research, because I copy and paste the 3 sqlite files from emulator to desktop, it seems the files lost all link and the data isn't displayed. Open the sqlite file directly inside emulator, works!

iOS 9 update seems to have broken sqlite3

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!

How to preload data into an iOS app using sqlite files

Prior to the new Xcode 5 build, I was able to preload data into my core data powered app by referencing the file from the project. However, ever since I upgraded my XCode, my json data is now being saved into 3 files:
an empty .sqlite file
a .sqlite-wal file
a .sqlite-shm file.
How do I do import this data into my app?
In the past all I had to do was copy the sqlite file and I was done. Now, I have no idea what file I'm supposed to copy.
I can confirm "compacting" the database using the FIREFOX add-on provided by #Lukasz Kowalski herein is confirmed with 10.9.1 / Xcode 5 / iOS 7. To clarify procedure...
download Firefox, then get his SQLite Manager add-on.
Copy enclosing StoreContent folder with PersistentStore, PersistentStore-wal and PersistentStore-shm files to desktop for re-combination into single pre-iOS7 UIManagedDocument database that functions as before. where to find:
~/Library/ApplicationSupport/iPhoneSimulator/7.xx/Applications/gobble-d-gook/APPNAME/Documents/APPNAMEDatabase/StoreContent/{your database files}
Launch Firefox, open window, from menu Tools > Sqlite Manager
Use SQLite Manager to open database: desktop > StoreContent > PersistentStore
Select from Menu > Compact Database option.
Select from Menu > Close Database
done! they are combined.
I found out from apple's developer site that in oder to get core data to behave in the old way (pre-iOS 7), and generate just the sqlite file, I had to add this to the persistentStore addStore method, under the options parameter.
#{ NSSQLitePragmasOption : #{ #"journal_mode" : #"DELETE" } }
I hope this helps anyone else who encounters this problem.
Cheers
Try just the sqlite file. See if it works, add the other two one by one.
You could also save the JSON in a txt file and on load parse it into Core Data. Depending on how much data you have, you should do this in batches with the first batch being just large enough to populate the first view and then continue parsing the rest. All in a background queue off course.
Not as easy as it was before, but this is a solution. Maybe someone else has a better solution?
I have found solution to create 1 .sqlite file when you have 3 files: .sqlite, .sqlite-wal and .sqlite-shm. To do that you should use „SQLite Manager” addon for Firefox (https://addons.mozilla.org/pl/firefox/addon/sqlite-manager/?src=userprofile):
install and run addon in Firefox
open your coredata .sqlite from directory of your app in iPhone Simulator
use Compact Database which will produce 1 .sqlite file :)
now you can use old method (prior to XCode 5) to include .sqlite into your application

Persistent storage (WebSQL and local storage) in iOS 6 w/ PhoneGap

The issue of iOS not persisting localStorage/WebSQL databases has been discussed frequently here and on other sites. The problem I am having is that the workarounds are so varied and have evolved over time. I have found 2 different PhoneGap plugins which use the native SQLite API, a plugin that periodically copies the SQL database to the documents directory,and even suggested settings in a Xcode .plist file that can be used to specify the location of SQL database. It's confusing because I'm not sure which solution applies best to the current point in time (iOS 6+ and Cordova 2.4+). Is this built in to Cordova now or do I still need a plugin. If so, which plugin? What about the setting the database location in an Xcode config file. Any help is deeply appreciated
Current versions of phonegap don't require a external plugin to use SQL with a sqlite database. The current code is compatible with iOS. You don't need to write/implement your own workaround, and you can be sure that phonegap will implement werever you need to get your app running (that's why the name phone-gap they will fill the GAP).
http://docs.phonegap.com/en/2.1.0/cordova_storage_storage.md.html#Storage

Resources