Wednesday, January 23, 2019

Browsing SQLite's data managed by Swift's Core Data framework

To see the location of the SQLite's database file, go to Product > Scheme > Edit Scheme... then select Run and add the following arguments.
    
-com.apple.CoreData.SQLDebug 1
-com.apple.CoreData.Logging.stderr 1
 



There is a free app to browse the database here https://sqlitebrowser.org/. I uploaded the app to my server here.

Or we can use the sqlite command which is built-in in OSX to enter SQLite's command shell by running this command:

sqlite3 ~/Library/Developer/CoreSimulator/Devices/8BDECFA8-1DD0-4EA8-8F3B-75B7EF61A351/data/Containers/Data/Application/8AF0221B-152B-4A61-B8AA-D3F9D0CBED6E/Library/Application Support/CoreDataTest.sqlite
 

SQLite's Commands


Query table's names

sqlite> .tables
ZEQUATION     ZOPERATORLOG  Z_METADATA    Z_MODELCACHE  Z_PRIMARYKEY
 

Show table's schema

sqlite> .schema zoperatorlog
CREATE TABLE ZOPERATORLOG ( Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZOPERATORTAG INTEGER, ZOPERAND FLOAT );
 

Exit the command shell

> .exit
 

Select statement
The column's names must be specified.

sqlite> select z_pk, zoperatortag from zoperatorlog
 



References
https://wiki.genexus.com/commwiki/servlet/wiki31044,How+To%3A+Query+SQLite+database+from+an+iOS+Offline+App
https://stackoverflow.com/questions/24133022/sqlite-file-location-core-data/47402447#

No comments:

Post a Comment