views:

13

answers:

0

Hi, I am simply trying get the objects in my DB using an Array ie display the search results in another viewcontroller. I think the problem it that I am not linking the delegate to the controller and as a result my Array is not reading the objects when I put my sql statement in....

Here's what it looks like?

+ (void) getInitialDataToDisplay:(NSString *)dbPath {

Peddlev2AppDelegate *appDelegate = (Peddlev2AppDelegate *)[[UIApplication sharedApplication] delegate];

if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {

    const char *sql = "select wineId, brand from products";
    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);
            SearchResultsViewController *wineObj = [[SearchResultsViewController alloc] initWithPrimaryKey:primaryKey];
            wineObj.brand= [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];

            wineObj.isDirty = NO;

            [appDelegate.wineArray addObject:wineObj];
            [wineObj release];
        }
    }
}
else
    sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.

}

It gets up to the

if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {

and then skips over all the data input! ahhh.

The dbPath is in a different view controller and looks like this.

- (NSString *) getDBPath {

//Search for standard documents using NSSearchPathForDirectoriesInDomains
//First Param = Searching the documents directory
//Second Param = Searching the Users directory and not the System
//Expand any tildes and identify home directories.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:@"Wine.sqlite"];

The key thing to note there is that the WineArray is where the data is held and passed to the Viewcontroller that displays the results..

Any ideas?

Thanks.