I'm getting "error while updating row" error when I'm trying to update sqlite row in iOS. Here is my update method:
-(BOOL) updateResultForLesson:(int)lessonId result:(int)result{
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &database) == SQLITE_OK)
{
sqlite3_stmt *statement;
NSString *querySQL = [NSString stringWithFormat:@"update lessons set result=%d where id=%d",result, lessonId];
const char *query_stmt = [querySQL UTF8String];
sqlite3_prepare_v2(database, query_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
NSLog(@"updated");
return YES;
}
else {
sqlite3_reset(statement);
NSLog(@"error while updating row");
return NO;
}
}
return NO;
}
and here insert method which works fine:
-(BOOL) addLesson:(NSString *)title levelId:(NSInteger)levelId categoryId:(NSInteger)categoryId{
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &database) == SQLITE_OK)
{
int result = 0;
NSString *insertSQL = [NSString stringWithFormat:@"insert into lessons (title, level_id, category_id, result) values(\"%@\", \"%d\", \"%d\", \"%d\")",title, levelId, categoryId, result];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(database, insert_stmt,-1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
;
return YES;
}
else {
sqlite3_reset(statement);
return NO;
}
}
return NO;
}
what am I doing wrong? can anyone help? Insert and select methods works well, I have only problem with updating rows.
Aucun commentaire:
Enregistrer un commentaire