iOS,CoreData,SQLite,文件丢失数据 [英] iOS, CoreData, SQLite, File losing its data

查看:216
本文介绍了iOS,CoreData,SQLite,文件丢失数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它通过从json文件导入到sqlitedb中来生成一些静态数据,当运行该应用程序时,数据库文件中包含数据并且已正确加载,我通常会进入通常位于

I have an app that generates some static data by importing from a json file into a sqlitedb, When running the app the DB file has data in it and is loaded properly, I usually go to the build folder "usually under

  /Library/Application Support/iPhone Simulator/7.0.3-64/Applications/

并检查sqlite文件并验证它是否有数据
现在我复制相同的文件夹并将其粘贴到桌面上,然后打开
我注意到在每个sqlite文件中都会生成一个-shm和-wal文件。

and inspect the sqlite file and verify that it does have data. Now I copy that same folder and paste it on the desktop, and open it in the same sqlite browser, and the data is gone?? why I don't know!! I notice that for every sqlite file there is a -shm and -wal file generated.

为什么会这样?

好,所以我尝试了一些调查,我有两种情况:

Ok so I tried a little bit more investigating, I have two scenarios :

1:我在完成生成SQLite文件后立即放置一个断点,然后转到build文件夹。如果我将该文件复制到台式机数据库丢失了数据。

1 : I put a break point right after I finished generating the SQLite file, and then go the build folder, In the build folder the DB has data in it, if I copy that file to the desktop the db loses its data.

2:我不放置断点,让应用正常完成(正常运行),然后转到build文件夹,db文件包含数据,当我将其复制并粘贴到在桌面上,它仍然保留数据。

2 : I don;t put a break point, let the app finish normally ( gracefully ) and then go to the build folder, the db file has data, and when I copy and paste it to the desktop it still retains the data.

所以我认为当xcode退出(或者应用程序正常关闭)时,发生了某些事情,当我放置断点时,我就错过了!!

So I assume there's something that happens when xcode exits ( or the app closes normally ) that I am missing out on when I put a breakpoint !!

推荐答案

从iOS 7开始,默认情况下在 Journaling 模式下使用sqlite数据库-这意味着对数据库的所有更改被写入更新文件,而不是直接写入数据库。您可以将行为改回旧方式-在此处查看完整说明

Starting with iOS 7 the sqlite database is used in Journaling mode by default - which means that all changes to the database are written to "update files", not to the database directly. You can change the behaviour back to the "old" way - have a look here for a complete explanation :

核心数据和iOS 7:持久存储的不同行为

这篇关于iOS,CoreData,SQLite,文件丢失数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆