私はsqliteテーブルの列を更新していますが、値を更新するためにメソッドが呼び出されるたびに、1つのレコードがある場合は別のレコードに更新値を混同すると思います.2つのレコードがある場合は問題ありません.ここで混乱するのは更新用のコードです
- (void)addContentViews:(NSString *)dbPath {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"The Content ID is %@",appDelegate.contentID);
//if(updateStmt == nil) {
NSLog(@"The Content ID is %@",appDelegate.contentID);
NSString*select = [NSString stringWithFormat:@"UPDATE ContentMaster Set Views = ? where contentID ='%@'",appDelegate.contentID];
const char *sql = [select UTF8String];
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
{
if(sqlite3_prepare_v2(database, sql, -1, &updateStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
// }
sqlite3_bind_text(updateStmt,1, [views UTF8String], -1, SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(updateStmt))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
//else
//SQLite provides a method to get the last primary key inserted by using sqlite3_last_insert_rowid
// contentID = sqlite3_last_insert_rowid(database);
//Reset the add statement.
sqlite3_finalize(updateStmt);
}
}