gpt4 book ai didi

ios - Sqlite 插入或替换不更新一列

转载 作者:行者123 更新时间:2023-11-28 22:21:26 25 4
gpt4 key购买 nike

我正在使用插入或更新数据。我有一个表 sub_sub_categories,有一列 is_favorite 默认值为 0,当用户添加到收藏夹时我将它设置为 1。在每次启动应用程序时,我都会插入或替换来自网络的所有数据。当我这样做时,它还会将 is_favorite 设置为 0。虽然我没有设置它。如何阻止它更新 is_favorite 列。这是我的代码。

for (int i=0; i < arraySubSubCategories.count; i++) {
id dict = [arraySubSubCategories objectAtIndex:i];

NSString *query = [NSString stringWithFormat:@"INSERT OR REPLACE into sub_sub_categories (id, name, sub_category_id, problem_name, problem_description, why, why_link, solution, solution_link, sort_order, is_deleted) VALUES (%@, '%@', %@, '%@', '%@', '%@', '%@', '%@', '%@', %@, %@)",
[dict objectForKey:@"id"],
[MyCommonFunctions addSlashes:[dict objectForKey:@"name"]],
[dict objectForKey:@"sub_category_id"],
[MyCommonFunctions addSlashes:[dict objectForKey:@"problem_name"]],
[MyCommonFunctions addSlashes:[dict objectForKey:@"problem_description"]],
[MyCommonFunctions addSlashes:[dict objectForKey:@"why"]],
[MyCommonFunctions addSlashes:[dict objectForKey:@"why_link"]],
[MyCommonFunctions addSlashes:[dict objectForKey:@"solution"]],
[MyCommonFunctions addSlashes:[dict objectForKey:@"solution_link"]],
[dict objectForKey:@"sort_order"],
[dict objectForKey:@"is_deleted"]];

[MyCommonFunctions InsUpdateDelData:query];
}

编辑查询是:

INSERT OR REPLACE into sub_sub_categories (id, name, sub_category_id, problem_name, problem_description, why, why_link, solution, solution_link, sort_order, is_deleted) VALUES (93, 'some data', 6, '', 'some data', 'some data', '', 'some data', 'some data', 0, 0)

最佳答案

INSERT OR REPLACE 不会在 db 中保留以前的值,它会用给定值或默认值覆盖它。

您必须首先查询您的数据库以获取现有字段(如果记录存在)并将您不想替换的字段放入查询中。

关于ios - Sqlite 插入或替换不更新一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20280890/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com