ios - Core Data SQLite File No Data -


when debug core data, sqlite file app in iphone. sqlite has no data except version. i'm sure i've saved data nsmanagedobject , can data through code. can reopen app. logs show data has inserted sqlite file.

the following shows first time data persisted sqlite file:

- (void)write {    nsentitydescription *entity = [nsentitydescription entityforname:nsstringfromclass([network class]) inmanagedobjectcontext: [appdelegate sharedappdelegate].managedobjectcontext];    network *network = (network*)[[nsmanagedobject alloc] initwithentity:entity insertintomanagedobjectcontext:self.managedobjectcontext];   network.name = @"network";   [self.managedobjectcontext save:nil];  }  - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {    [self write];    return yes; } 

the following log debugging core data:

2015-06-15 13:10:28.198 smartlight[1226:419855] coredata: annotation: connecting sqlite database file @ "/var/mobile/containers/data/application/fb384ae0-5dc5-4924-8f58-0b944ad63f03/documents/lightmodel.sqlite" 2015-06-15 13:10:28.204 smartlight[1226:419855] coredata: annotation: creating schema. 2015-06-15 13:10:28.205 smartlight[1226:419855] coredata: sql: pragma page_size=4096 2015-06-15 13:10:28.206 smartlight[1226:419855] coredata: sql: pragma auto_vacuum=2 2015-06-15 13:10:28.219 smartlight[1226:419855] coredata: sql: begin exclusive 2015-06-15 13:10:28.220 smartlight[1226:419855] coredata: sql: select tbl_name sqlite_master tbl_name = 'z_metadata' 2015-06-15 13:10:28.222 smartlight[1226:419855] coredata: sql: create table zbluedevice ( z_pk integer primary key, z_ent integer, z_opt integer, zdeviceid integer, zdevicetype integer, zmaxdeviceid integer, znetworkid integer, znetwork integer, z4remoters integer, z4lights integer, zaddress varchar, zname varchar )  2015-06-15 13:10:28.226 smartlight[1226:419855] coredata: sql: create index zbluedevice_znetwork_index on zbluedevice (znetwork) 2015-06-15 13:10:28.227 smartlight[1226:419855] coredata: sql: create index zbluedevice_z4remoters_index on zbluedevice (z4remoters) 2015-06-15 13:10:28.229 smartlight[1226:419855] coredata: sql: create index zbluedevice_z4lights_index on zbluedevice (z4lights) 2015-06-15 13:10:28.230 smartlight[1226:419855] coredata: sql: create index zbluedevice_z_ent_index on zbluedevice (z_ent) 2015-06-15 13:10:28.231 smartlight[1226:419855] coredata: sql: create table znetwork ( z_pk integer primary key, z_ent integer, z_opt integer, zmaxdeviceid integer, znetworkid integer, zname varchar, zpassword varchar )  2015-06-15 13:10:28.232 smartlight[1226:419855] coredata: annotation: creating primary key table. 2015-06-15 13:10:28.233 smartlight[1226:419855] coredata: sql: create table z_primarykey (z_ent integer primary key, z_name varchar, z_super integer, z_max integer) 2015-06-15 13:10:28.234 smartlight[1226:419855] coredata: sql: insert z_primarykey(z_ent, z_name, z_super, z_max) values(1, 'bluedevice', 0, 0) 2015-06-15 13:10:28.235 smartlight[1226:419855] coredata: sql: insert z_primarykey(z_ent, z_name, z_super, z_max) values(2, 'light', 1, 0) 2015-06-15 13:10:28.236 smartlight[1226:419855] coredata: sql: insert z_primarykey(z_ent, z_name, z_super, z_max) values(3, 'remoter', 1, 0) 2015-06-15 13:10:28.236 smartlight[1226:419855] coredata: sql: insert z_primarykey(z_ent, z_name, z_super, z_max) values(4, 'network', 0, 0) 2015-06-15 13:10:28.237 smartlight[1226:419855] coredata: sql: create table z_metadata (z_version integer primary key, z_uuid varchar(255), z_plist blob) 2015-06-15 13:10:28.239 smartlight[1226:419855] coredata: sql: select tbl_name sqlite_master tbl_name = 'z_metadata' 2015-06-15 13:10:28.240 smartlight[1226:419855] coredata: sql: delete z_metadata z_version = ? 2015-06-15 13:10:28.241 smartlight[1226:419855] coredata: sql: insert z_metadata (z_version, z_uuid, z_plist) values (?, ?, ?) 2015-06-15 13:10:28.242 smartlight[1226:419855] coredata: sql: commit 2015-06-15 13:10:28.256 smartlight[1226:419855] coredata: sql: pragma journal_mode=wal 2015-06-15 13:10:28.271 smartlight[1226:419855] coredata: sql: pragma journal_mode=wal 2015-06-15 13:10:28.272 smartlight[1226:419855] coredata: sql: pragma cache_size=200 2015-06-15 13:10:28.273 smartlight[1226:419855] coredata: sql: select z_version, z_uuid, z_plist z_metadata 2015-06-15 13:10:32.569 smartlight[1226:419855] coredata: sql: begin exclusive 2015-06-15 13:10:32.570 smartlight[1226:419855] coredata: sql: select z_max z_primarykey z_ent = ? 2015-06-15 13:10:32.571 smartlight[1226:419855] coredata: sql: update z_primarykey set z_max = ? z_ent = ? , z_max = ? **2015-06-15 13:10:32.572 smartlight[1226:419855] coredata: sql: commit 2015-06-15 13:10:32.578 smartlight[1226:419855] coredata: sql: begin exclusive 2015-06-15 13:10:32.580 smartlight[1226:419855] coredata: sql: insert znetwork(z_pk, z_ent, z_opt, zmaxdeviceid, zname, znetworkid, zpassword) values(?, ?, ?, ?, ?, ?, ?) 2015-06-15 13:10:32.581 smartlight[1226:419855] coredata: sql: commit** 2015-06-15 13:10:32.584 smartlight[1226:419855] coredata: sql: pragma page_count 2015-06-15 13:10:32.585 smartlight[1226:419855] coredata: annotation: sql execution time: 0.0007s 2015-06-15 13:10:32.585 smartlight[1226:419855] coredata: sql: pragma freelist_count 2015-06-15 13:10:32.586 smartlight[1226:419855] coredata: annotation: sql execution time: 0.0005s 

the log shows network column inserted.

here read data core data after app closed , opened again:

- (void)read {   nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] initwithentityname:nsstringfromclass([network class])];   network *network = [self.managedobjectcontext executefetchrequest:fetchrequest error:nil].firstobject;   nslog(@"%@", network); }  - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {    [self read];    return yes; } 

the log response shows:

    2015-06-15 13:16:12.344 smartlight[1234:421137] coredata: annotation: connecting sqlite database file @ "/var/mobile/containers/data/application/7a74b12a-6481-4b10-9307-fc7a92dd1912/documents/lightmodel.sqlite" 2015-06-15 13:16:12.347 smartlight[1234:421137] coredata: sql: select tbl_name sqlite_master tbl_name = 'z_metadata' 2015-06-15 13:16:12.350 smartlight[1234:421137] coredata: sql: pragma journal_mode=wal 2015-06-15 13:16:12.350 smartlight[1234:421137] coredata: sql: pragma cache_size=200 2015-06-15 13:16:12.351 smartlight[1234:421137] coredata: sql: select z_version, z_uuid, z_plist z_metadata 2015-06-15 13:16:12.352 smartlight[1234:421137] coredata: sql: select 0, t0.z_pk, t0.z_opt, t0.zmaxdeviceid, t0.zname, t0.znetworkid, t0.zpassword znetwork t0  2015-06-15 13:16:12.353 smartlight[1234:421137] coredata: annotation: sql connection fetch time: 0.0004s 2015-06-15 13:16:12.353 smartlight[1234:421137] coredata: annotation: total fetch execution time: 0.0010s 1 rows. 2015-06-15 13:16:20.603 smartlight[1234:421137] <network: 0x17015bf90> (entity: network; id: 0xd000000000040000 <x-coredata://500a532b-ca76-48fb-b0c2-5fe0affab454/network/p1> ; data: <fault>) 

the log shows data has been saved successfully. however, sqlite file documents directory has not find data saved, except data saved system (e.g. version).

enter image description here

the znetwork table should has column.

can explain going on, or why can't find data in sqlite file?

i know what happen. 3 files must put together。enter image description here


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -