views:

59

answers:

1

I'm wanting to build up a pre-filled sqlite database using Django as a front-end data entry inputter; however I've read this site and on StackOverflow that isn't that easy to do; and one needs to use CSV files.

That's fine if your database is pretty small - but what if you're pre-filling it with data that has relationships (ie: Customers, Orders, Salespeople, etc); or if the database you're building requires a lot of data input (1,000+ records).

My app/database will be pretty big and have a lot of pre-filled data with multiple references/relationships -- I really don't want to re-enter all this stuff into CSV files or into the Simulator and I thought using Django would be a really quick and dirty way of getting vast amounts of related data into an iphone app.

This kinda raises the question of whether Core Data is really worth it, the learning curve is really high, the syntax can be cumbersome and I'm considering just using FMDatabase, except I can't get the LIMIT/OFFSET to display rows of data in batches correctly (any help or hints on tips how to do this would be great!).

Therefore, if you're wanting to pre-fill a database using Core Data and a large database what is the best route forward?

A: 

You might want to have a look at the Active Record port for cocoa/cocoa touch. I've done an app like this before, and what we (the client and i), choose to do was to import the data from an XML file on the first app launch. The idea being that as the parser was built into the app, we could do OVA updates if we choose to at a later date. The data did have fairly complex relationships, but i decided Core Data was still the way forward.

I've only used raw SQLite once, and that was before we had CoreData on the iPhone. Also you should consider what your solution is for doing schema migrations which are handled by CoreData.

A Hybrid solution is to load the data into Core Data in the simulator, and then ship that SQLite database with the app, and copy it into the app's document directory, on the initial load. Best of both worlds.

Good luck

Jonathan
Jonathan, thanks for your answer -- I was worried that I was never going to get an answer. I like the idea of Active Record and will review it further. I am still learning Core Data; the whole migrations thing scares me, but I am confident I can learn it.
zardon
I've seen people talk about using FMDatabase, but then how do you stagger through records on a tableView (cloning the features of NSFetchController *or whatever its called) -- the only issue is writing all the relationships long-hand. I guess Core Data or a hybrid model is the best way forward.
zardon
Marcus Zara's book on Core Data http://pragprog.com/titles/mzcd/core-data is fairly useful, and not too expensive at about $20 for the e-book version. He talks about versioning, migration and also has a chapter on working with core data in a multi-threaded environment, crucial for doing large imports. CoreData is certainly worth learning
Jonathan
My brute force approach, in my nieve days before coredata, was to start loading the data in the background during view transitions. By the time the animation finished the data was loaded into an array, which i then used as a backing collection for the datasource. Using NSFetchController is much easier :) plus it handles sections, and datastore changes.
Jonathan