所有时间都没有回复否。
-(BOOL)updateProductTable:(NSString *)productid column_shop_Product_quantity:(NSString *) productquantity{
NSLog(@"%@",productid);
NSLog(@"%@",productquantity);
const char *dbpath = [databasepath UTF8String];
if (sqlite3_open(dbpath, &database) == SQLITE_OK)
{
NSString *updateSQL = [NSString stringWithFormat:@"UPDATE ShopProduct set column_shop_Product_quantity=%@ WHERE column_shop_Product_id=%@",productquantity,productid];
NSLog(@"%@",updateSQL);
const char *update_stmt = [updateSQL UTF8String];
if (sqlite3_prepare_v2(database, update_stmt, -1, &statement, nil) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_DONE)
{
sqlite3_reset(statement);
return YES;
}
else {
return NO;
}
sqlite3_finalize(statement);
}
}
sqlite3_close(database);
return NO;
}
答案 0 :(得分:2)
您的代码存在以下问题:
stringWithFormat:
将值绑定到查询。sqlite3_open_v2
。以下是针对所有这些问题更新的代码:
-(BOOL)updateProductTable:(NSString *)productid column_shop_Product_quantity:(NSString *)productquantity {
NSLog(@"%@",productid);
NSLog(@"%@",productquantity);
BOOL res = NO;
sqlite3 *database = NULL;
const char *dbpath = [databasepath UTF8String];
if (sqlite3_open_v2(dbpath, &database, SQLITE_OPEN_READWRITE, NULL) == SQLITE_OK)
{
const char *updateSQL = "UPDATE ShopProduct set column_shop_Product_quantity=? WHERE column_shop_Product_id=?";
sqlite3_stmt *statement = NULL;
if (sqlite3_prepare_v2(database, updateSQL, -1, &statement, NULL) == SQLITE_OK)
{
sqlite3_bind_int(statement, 0, [productquantity intValue]);
sqlite3_bind_text(statement, 1, [productid UTF8String], -1, SQLITE_TRANSIENT);
if (sqlite3_step(statement) == SQLITE_DONE) {
res = YES;
} else {
NSLog(@"Unable to update data: %s", sqlite3_errmsg(database));
}
sqlite3_finalize(statement);
} else {
NSLog(@"Unable to prepare statement: %s", sqlite3_errmsg(database));
}
sqlite3_close(database);
} else {
NSLog(@"Unable to open database at %@: %s", databasepath, sqlite3_errmsg(database));
}
return res;
}