将应用程序升级中存储在sqlite中的用户数据迁移到核心数据 [英] Migrating user data stored in sqlite to core data in app upgrade

查看:92
本文介绍了将应用程序升级中存储在sqlite中的用户数据迁移到核心数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Stack Overflow的新手并且已经编程了一年,所以仍然是这个东西的新手(即,请耐心等待我!)。我正在升级在xcode 3中创建的旧应用程序,它使用sqlite数据库来存储用户生成的数据。升级的应用程序需要与iCloud一起使用,因此我决定切换到Core Data(因为sqlite本身无法与iCloud同步)。我在实现核心数据结构方面没有问题但我的问题在于如何允许用户保留他们现有的数据。



我已经看过这些主题:< a href =https://stackoverflow.com/questions/6577019/how-to-import-a-pre-existing-sqlite-file-into-core-data>如何将预先存在的sqlite文件导入Core数据?和需要从SQLite数据库填充核心数据,虽然我可以创建一个实用程序应用程序来导入现有数据,但这是没用的,因为初始应用程序包中没有现有数据,数据由用户存储。



我真的很感激我能得到的任何帮助,完全把自己捆绑在一起!也许我最好完全避免使用核心数据并找到另一种解决方案来保存iCloud中的sqlite数据?



提前致谢!

解决方案

您可以使用核心数据。创建核心数据模型和堆栈,迁移过程包括查询sqlite数据库中的数据以将其插入核心数据数据库。



假设您的sqlite中有三个表。人,车辆和财产。您将在核心数据模式下创建等效实体,然后您必须从这些表中查询信息以将其插入核心数据中。您需要熟悉如何将数据插入核心数据数据库,以及如何在多线程环境中使用它(以避免在迁移过程中锁定应用程序)。



<请注意以下几点:




  • 尝试以块的形式保存。不要将所有内容加载到内存中,但也必须避免对NSManagedObjectContext实例进行大量的保存调用。每个对上下文的保存调用都是IO。平衡IO和内存取决于您的数据使用情况。

  • 索引您可以编入索引的现有实体的属性。这将帮助您建立关系(如果有的话)

  • 在开始迁移之前询问系统的时间。使用UIApplication的beginBackgroundTaskWithExpirationHandler:为了确保有足够的时间从系统继续迁移(如果用户将应用程序发送到后台)。

  • 不要打扰清理sqlite数据库。完成后删除数据库文件。



这些是我现在可以给你建议的一些事情。如果我想到更多,我会编辑这篇文章。祝你好运。


I'm new to Stack Overflow and have been programming for only a year, so still a newbie with this stuff (i.e., please bear with me!). I'm upgrading an old app created in xcode 3 that uses an sqlite database to store user-generated data. The upgraded app needs to work with iCloud, so I've decided to switch to Core Data (because sqlite on its own can't be synced with iCloud). I have no problem implementing the Core Data structures but my problem is in how to allow users to retain their existing data.

I have already looked at topics along these lines: How to import a pre-existing sqlite file into Core Data? and Need To Populate Core Data From SQLite Database, and while I can create a utility app to import existing data, this is of no use because there is no existing data with the initial app bundle, the data is stored by the user.

I'd really appreciate any help I can get on this, have totally tied myself in a big knot over it! Maybe I'm better off avoiding core data altogether and finding another solution to save the sqlite data in iCloud?

Thanks in advance!

解决方案

You can use core data. Create your core data model and stack, and your migration process consists of querying chucks of data from your sqlite database to insert them into the core data database.

Let's say that you have three tables in your sqlite. Person, Vehicle, and Property. You will create the equivalent entities in your core data mode, then you will have to query information from these tables to insert them into core data. You need to get familiar on how to insert data into a core data database, and how to use it on a multithreading environment (to avoid locking the application during the migration process).

Here's a few things to keep in mind:

  • Try to save in chunks. Do not load everything into memory, but also you must avoid making numerous save calls into your NSManagedObjectContext instance. Every save call into the context is IO. Balance IO and memory depending on your data usage.
  • Index the properties you have on your existing entities that can be indexed. This will help you build relationships (if any)
  • Ask the system for time before starting the migration. Use UIApplication's beginBackgroundTaskWithExpirationHandler: in order to be sure to have enough time from the system to continue the migration (in case the user sends the application to the background).
  • Do not bother cleaning the sqlite database. Delete the database file when you are done with it.

These are some of the things I can advice to you for now. If i think of more, I will edit this post. Best of luck.

这篇关于将应用程序升级中存储在sqlite中的用户数据迁移到核心数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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