我是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);