views:

439

answers:

1

I don't have enough "Stack Overflow fu" yet to have found a previous answer to this.

One of my apps has its data in a SQLite database and I've used the Apple SQLiteBooks sample as primary inspiration -- however, SQLiteBooks has only a single table and a single view. I've got multiple (related) tables accessed as distinct views in a tab bar -- e.g. Cookbooks, Recipes, Ingredients, Utensils, etc. Some issues with the sample code:

1) It seems that the sample code initializes too early (in applicationDidFinishLaunching: when I'm leaning towards viewDidLoad:)

2) The static SQL query strings need to be different per class (on the other hand, they generally only differ by the table being accessed, so can I use "?" in the static string and then bind the table ID as needed?)

3) If I follow the lead of TheElements sample code, which uses plists as data store, I seem to spend too much time and memory "pre-building" the data sources of the not-yet-viewed tabs.

Does anyone have pointers to best practices as to how/where to define multiple instances of the single class from the sample while keeping performance high and memory low?

+1  A: 

You cannot use ? to bind table names, only values on the query.

I suggest you take a look at FMDB which is a SQLite wrapper in Objective-C.

With that, you can easily make different objects query the databases (some sort of home-grown ORM).

There are a few ActiveRecord implementations in Objective-C that you may take a look at, but I haven't used them.

pgb
Thanks... I looked at this and OmniDataObjects once, but I thought that they were overkill for the requirements. I'll look again.I'm comfortable with accessing the database as a database (vs. persistent objects) -- just want to make sure that I do it efficiently.
iPhoneDollaraire