我是 iOS 中 sqlite3 的新手,我正在尝试更新设备表中的现有记录,如下所示我没有更新主键,尽管我正在根据主键更新记录,其中 deviceAppID 是我的 PK
这是我正在尝试的代码
const char *updateStatement ="UPDATE Device SET deviceGUID=?,testGUID=?,deviceName=?,device=?,deviceOsVersion=?,platform=?,createdDateTime=?,updatedDateTime=?,status=? WHERE deviceAppID=1";
int success;
if(sqlite3_prepare_v2(mDatabase, updateStatement, -1, &mStatement, NULL) == SQLITE_OK)
{
sqlite3_bind_text(mStatement, 2, [device.deviceGUID UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(mStatement, 3, [device.testGUID UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(mStatement, 4, [device.deviceName UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(mStatement, 5, [device.device UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(mStatement, 6, [device.deviceOSVersion UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(mStatement, 7, [device.devicePlatform UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(mStatement, 8, [device.createdDateTime UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(mStatement, 9, [device.updatedDateTime UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_int(mStatement, 10, device.status);
success = sqlite3_step(mStatement);
if (success == SQLITE_ERROR) {
NSAssert1(0, @"Error: failed to insert into the database with message '%s'.", sqlite3_errmsg(mDatabase));
}
}
else {
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(mDatabase));
}
sqlite3_finalize(mStatement);