Objective c Sqlite更新不生效
我的更新数据库查询不起作用。我搜索并阅读了许多主题,但没有找到解决方案。此外,我有一个删除语句,它工作顺利 我的代码:Objective c Sqlite更新不生效,objective-c,sqlite,Objective C,Sqlite,我的更新数据库查询不起作用。我搜索并阅读了许多主题,但没有找到解决方案。此外,我有一个删除语句,它工作顺利 我的代码: //Checking for any previously open connection which was not closed [self closeAnyOpenConnection]; //SqLite query NSString *fetchQuery = [NSString stringWithFormat:@"Update Category Set CatO
//Checking for any previously open connection which was not closed
[self closeAnyOpenConnection];
//SqLite query
NSString *fetchQuery = [NSString stringWithFormat:@"Update Category Set CatOrder = '%d' where CatOrder = '%d'", withToIndex + 1, withFromIndex + 1];
const char *updateQuery = [fetchQuery UTF8String];
sqlite3_stmt *sqlStatement = nil;
if(sqlite3_prepare_v2(databaseReference, updateQuery, -1, &sqlStatement, NULL) == SQLITE_OK)
{
// executes the sql statement with the data you need to update in the db
sqlite3_step(sqlStatement);
// clearing the sql statement
sqlite3_finalize(sqlStatement);
//closing the database after the query execution
sqlite3_close(databaseReference);
如果调用
sqlite3\u prepare\u v2
失败,则记录错误。还要检查sqlite3\u步骤的结果。另外,为什么只有在调用sqlite3\u prepare\u v2
成功时才关闭数据库?为什么要频繁地打开和关闭数据库?在应用程序启动时打开数据库一次,并将其保持打开状态。完成后将其关闭。感谢您的帮助。sqlite3_finalize导致的问题。我称之为前一种方法。同时,我将删除所有关闭和打开的数据库代码。我只给他们打一次电话。