tags:

views:

42

answers:

0

Hi, I've got a problem that I just can't nail an answer to. Basically I want to retrieve a specific column for the last entry in the SQL database.

I've got this so far but it never goes into the last if statement and thus I never get an answer.

-(int) retrieveLastNumberDrawn {

if(detailStmt == nil) {
     const char *sql = "Select NumberToDraw from Coffee Where CoffeeID = ?";
 if(sqlite3_prepare_v2(database, sql, -1, &detailStmt, NULL) != SQLITE_OK)
  NSAssert1(0, @"Error while creating detail view statement. '%s'", sqlite3_errmsg(database));
}

coffeeID = sqlite3_last_insert_rowid(database);
sqlite3_bind_int(detailStmt, 1, coffeeID);

if(sqlite3_step(detailStmt) == SQLITE_ROW){

 //Get the price in a temporary variable.
 NSNumber *NumberToDraw = [[NSNumber alloc] numberWithInt:sqlite3_column_int(detailStmt, 0)];
 tt = [priceDN intValue];
 [NumberToDraw release];

 }
....
}

Any help much appreciated.