sqlite3 DELETE problem "Library Routine Called Out Of Sequence"
- by Michael Bordelon
Here is my second stupid Noob problem. I am trying to do a simple Delete and I keep blowing up on the prepare step. I already have other Deletes, Inserts, Updates and Selects working. I am sure it is something simple. I appreciate your help.
+ (void)flushTodaysWorkouts {
sqlite3_stmt *statement = nil;
//open the database
if (sqlite3_open([[BIUtility getDBPath] UTF8String], &database) != SQLITE_OK) {
sqlite3_close(database);
NSAssert(0, @"Failed to opendatabase");
}
NSArray *woList = [self todaysScheduledWorkouts];
for (Workout *wo in woList) {
NSInteger woID = wo.woInstanceID;
if(statement == nil) {
const char *sql = "DELETE FROM IWORKOUT WHERE WOINSTANCEID = ?";
if(sqlite3_prepare_v2(database, sql, -1, &statement, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating delete statement. '%s'", sqlite3_errmsg(database));
}
//When binding parameters, index starts from 1 and not zero.
sqlite3_bind_int(statement, 1, woID);
if (SQLITE_DONE != sqlite3_step(statement))
NSAssert1(0, @"Error while deleting. '%s'", sqlite3_errmsg(database));
sqlite3_finalize(statement);
}
if(database) sqlite3_close(database);
}