我的应用程序使用 SQLite 数据库来存储联系人的某些数据。例如(record_ID、时间戳等)我正在尝试使用此方法使用某些值更新 SQLITE 记录。
初始化数据库后,我曾经调用过这个方法。仅更新了 1 条记录。即使我每次都调用这个方法来更新。
- (void) updateRecord:(int)recordID:(NSString *)sapCustId:(NSString *)sapContactId: (NSString *)timestamp {
static sqlite3_stmt *updateStmt = nil;
if(updateStmt == nil) {
NSString *sql = [NSString stringWithFormat:@"update contactList set sapCustId = \"%@\", sapContactId = \"%@\", timestamp = \"%@\" Where record_ID = \"%d\"", sapCustId, sapContactId, timestamp, recordID];
const char *sql_stmt = [sql UTF8String];
if(sqlite3_prepare_v2(databaseHandle, sql_stmt, -1, &updateStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(databaseHandle));
}
// sqlite3_bind_text(updateStmt, 0, [sapCustId UTF8String], -1, SQLITE_TRANSIENT);
// sqlite3_bind_text(updateStmt, 1, [sapContactId UTF8String], -1, SQLITE_TRANSIENT);
// sqlite3_bind_int(updateStmt, 2, recordID);
// sqlite3_bind_text(updateStmt, 3, [timestamp UTF8String], -1, SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(updateStmt))
NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(databaseHandle));
sqlite3_reset(updateStmt);
sqlite3_close(databaseHandle);
//Reclaim all memory here.
[sapContactId release];
[sapCustId release];
}
告诉我。,如何解决?