我正在更新 sqlite 表中的列,它工作正常,但我认为当每次调用方法来更新值时,我认为如果有一条记录,则将更新值混合到其他记录,那么如果我们有两条记录就可以了,那么我认为它得到了混合在这里是更新的代码
- (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);
}
}