tags:

views:

124

answers:

1

Approach #1 where I have native SQL and I can change it whatever I want

if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
   const char *sql = "select coffeeID, coffeeName from coffee";
   sqlite3_stmt *selectstmt;
   if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
      while(sqlite3_step(selectstmt) == SQLITE_ROW) {

        NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
        Coffee *coffeeObj = [[Coffee alloc] initWithPrimaryKey:primaryKey];
        coffeeObj.coffeeName = [NSString stringWithUTF8String:(char*)sqlite3_column_text(selectstmt, 1)];

        coffeeObj.isDirty = NO;

        [appDelegate.coffeeArray addObject:coffeeObj];
        [coffeeObj release];
    }

of course I have a class Coffies where this code named as get_list was implemented

Approach #2

in view controller

@interface RecipeListTableViewController : UITableViewController <RecipeAddDelegate, NSFetchedResultsControllerDelegate> {
    @private
        NSFetchedResultsController *fetchedResultsController;
        NSManagedObjectContext *managedObjectContext;

@implementation

    - (void)viewDidLoad {
        if (![[self fetchedResultsController] performFetch:&error]) 

and this approach will magically select nessesary data

I need to have make the following operations (list with order and filter, insert, update, delete and special list with group by) over some SQLite table, what approach should I prefer - class with Native SQL functions or based on NSManagedObject

+2  A: 

See the answers to this question and this excellent blog article. Oh, and accept more answers to your questions.

Nikolai Ruhe
the blog article is helpfull, thank you
se_pavel