Doug, here it is:
/// /// create a new row (INSERT INTO todo). ///
- (BOOL) createData:(sqlite3 *)db { NSLog(@"TodoTask create data."); if (self = [super init]) { database = db;
if (insert_statment == nil) { const char *sql = "INSERT INTO todo(title, description, priority, status, created, expires, posx, posy, updated) VALUES('?', '?', '?', '?', '?', '?', '?', '?', '?');";
if (sqlite3_prepare_v2(database, sql, -1, &insert_statment, NULL) != SQLITE_OK) {
NSAssert1(0, @"Error: failed to prepare create_statement with message '%s'.", sqlite3_errmsg(database)); } }
sqlite3_bind_text(insert_statment, 1, [self.titleText UTF8String], -1, SQLITE_TRANSIENT); sqlite3_bind_text(update_statment, 2, [self.description UTF8String], -1, SQLITE_TRANSIENT); sqlite3_bind_int(update_statment, 3, self.priority); sqlite3_bind_int(update_statment, 4, self.status); sqlite3_bind_int(update_statment, 7, self.posx); sqlite3_bind_int(update_statment, 8, self.posy);
NSDateFormatter *dt = [[NSDateFormatter alloc] init]; sqlite3_bind_text(update_statment, 5, [[dt stringFromDate:self.created] UTF8String], -1, SQLITE_TRANSIENT); sqlite3_bind_text(update_statment, 6, [[dt stringFromDate:self.expires] UTF8String], -1, SQLITE_TRANSIENT); sqlite3_bind_text(update_statment, 9, [[dt stringFromDate:self.created] UTF8String], -1, SQLITE_TRANSIENT); [dt release];
int success = sqlite3_step(insert_statment); sqlite3_reset(insert_statment);
if (success != SQLITE_DONE) { NSAssert1(0, @"Error: failed to insert into with message '%s'.", sqlite3_errmsg(database)); }
primaryKey = sqlite3_last_insert_rowid(database); } NSLog(@"... data created."); return TRUE; }