开发者

core data with pre populated sqlite from csv!

开发者 https://www.devze.com 2023-01-12 12:13 出处:网络
Ive been struggling with this for a couple of days now and after scouring the internet I still havent got it working. I have a csv file, from which I need to populate an sqlite db to use with core dat

Ive been struggling with this for a couple of days now and after scouring the internet I still havent got it working. I have a csv file, from which I need to populate an sqlite db to use with core data.

I thought I had found a solution here http://ablogontech.wordpress.com/2009/07/13/using-a-pre-populated-sqlite-database-with-core-data-on-iphone-os-3-0/ but I cannot for the life of me get it to work. Here are the steps I have taken.

  1. Created a new Core Data project and generated the model a开发者_如何学Gond Managed Object classes;
  2. Performed a fetch request in vdl of rootViewController (Im not sure why this is neccessary but apparantly it is?)
  3. Copied the xxx.sqlite from the documents directory of my app into another directory.
  4. Executed the following sqlite commands from the terminal:

sqlite3 xxx sqlite> .mode csv yyy sqlite> .import yyy.csv yyy

Now when it comes to importing the csv data into my table I get a no such table error! Also when i execute a .tables command I get Z before my table name? I have imported data from a csv into a table this way before but not using a core data generated db and I think this is where the problem lies. Does anyone know where Im going wrong or of a better solution to my problem. Please let me know as Im going crazy with this..

Many thanks

Jules


Take a look at this post What you want to do is set up your core data stack then import each record and insert new managed objects and use the values from the csv to set your object's properties.

0

精彩评论

暂无评论...
验证码 换一张
取 消