简体   繁体   English

将部分mySQL DB从网站转换为iOS上的CoreData / SQLite

[英]Convert parts of mySQL DB from website into CoreData/SQLite on iOS

I have a website with mySQL database, parts of which I'd like to reuse in my iPhone app by populating CoreData DB (basically iPhone app is going to be an offline version of the website). 我有一个带有mySQL数据库的网站,我希望通过填充CoreData数据库在我的iPhone应用程序中重用其中一部分(基本上iPhone应用程序将成为该网站的离线版本)。

I am thinking of writing scripts which will translate mySQL into SQLite and then somehow feed the data into CoreData. 我正在考虑编写脚本,将mySQL转换为SQLite,然后以某种方式将数据提供给CoreData。

How would you accomplish this task? 你将如何完成这项任务?

Solution

Check out the following tutorial: 查看以下教程:

http://www.raywenderlich.com/980/core-data-tutorial-how-to-preloadimport-existing-data http://www.raywenderlich.com/980/core-data-tutorial-how-to-preloadimport-existing-data

TL;DR - uses a python script to write to the SQLite database in a Core Data compatible format. TL; DR - 使用python脚本以Core Data兼容格式写入SQLite数据库。

Possible Drawbacks 可能的缺点

  • If you've got a complex database, this could get messy fast. 如果你有一个复杂的数据库,这可能会很快乱。
  • If there's any errors in the format of the SQLite database, Core Data is not tolerant and you might get unexplained crashes. 如果SQLite数据库的格式有任何错误,Core Data就不能容忍,你可能会遇到无法解释的崩溃。
  • Apple recommend that you never mess directly with the data store directly, which makes me a bit nervous of this approach. Apple建议您不要直接直接使用数据存储,这让我对这种方法感到有点紧张。

Alternative 替代

I'd dump the mySQL database to a CSV file, model the Core Data store in Xcode as unusual and write a quick and dirty importer within the application itself. 我将mySQL数据库转储到CSV文件,将Xcode中的Core Data存储模型设置为异常,并在应用程序本身内编写一个快速且脏的导入器。

You could use cCSVParse to do the CSV heavy lifting. 您可以使用cCSVParse来执行CSV重载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM