导入csv到coredata sqlite for iphone [英] import csv to coredata sqlite for iphone

查看:163
本文介绍了导入csv到coredata sqlite for iphone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何导入csv到sqlite(iphopne的核心数据)



我已经尝试使用SQLite管理器,但它导入csv到一个新的表,需要导入一些日期,




  • 因此如何将数据导入我的sqlite数据库?我有3个实体具有不同的属性,在csv我有所有的值在一个csv(所以我可以格式化或根据需要更改它,但如何impor它?)

  • $ b $




提前感谢!

p>

解决方案

我假设你已经设置了你的CoreData,并且一个运行良好。你真的不想直接使用core-data的sqlite DB。这是可能的,但也有点凌乱。




  • 使用浮动的CSV扫描器之一将CSV数据读入字段。

  • 根据需要将CSV字段映射到实体及其属性。
    您可能想使用CSV头来验证您的映射CSV列对属性是否确定。

  • 循环浏览CSV的各行,并逐行更新您的实体。

  • 根据数据量,您可能需要定期保存上下文。



核心数据喜欢NSDate。无论CSV文件在数据列中使用什么,最好将CSV值转换为NSDate。在您的应用程序中使用NSDate会减少头痛的次数。


how can I import csv to sqlite (core data for iphopne)

I have tried using SQLite manager, but it imports the csv to a new table, also I need to import some dates,

  • so how to import the data to my sqlite database? I have 3 entitys with different properties, and in the csv I have all the values in one csv (so I could format it or change it as needed), but how to impor it?

  • also what is the date format that coredata likes?

thanks in advance!

解决方案

I assume you have setup your CoreData and that one is running fine. You don't really want to work directly with the sqlite DB of core-data. It is possible, but also a bit messy.

  • Use one of the CSV scanners floating around to read your CSV data into fields.
  • Map the CSV fields to your entities and to their attributes as needed. You might want to use the CSV header to verify that your mapping CSV-column-to-attribute is ok.
  • Loop through the rows of the CSV and update your entities row by row.
  • Depending on data volume you might want to save your context at regular intervals.

Core-Data likes NSDate. Whatever the CSV file uses in the data column you are best off converting the CSV value into a NSDate. Using NSDate in your App will reduce the number of headaches later.

这篇关于导入csv到coredata sqlite for iphone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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