Sqlite3更新查询在ios应用程序中不工作 [英] Sqlite3 update query not working in ios app

查看:176
本文介绍了Sqlite3更新查询在ios应用程序中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按下按钮时,尝试更新我的表格栏。

I am trying to update one of my table's column upon button click.

问题是代码没有给出任何异常,仍然不更新表。

The issue is that code isn't giving any exception still it is not updating the table.

当视图控制器重新加载时,它显示旧值,而不是更新。

When the view controller load again , it shows the old value rather then updated one.

更新数据库的代码如下。

Code for update db is attached below.

@try {
    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {

        NSString *sqlStatement = @"UPDATE messagesTable SET Favorite = 1 where MessageID=";
        sqlStatement = [sqlStatement stringByAppendingString:msgId];

        NSLog(@"sql statement: %@", sqlStatement);



        const char *sql = [sqlStatement UTF8String];
        int result = sqlite3_prepare_v2(database, sql, -1, &compiledStatement, NULL);
        if(result != SQLITE_OK) {
            NSLog(@"Prepare-error #%i: %s", result, sqlite3_errmsg(database));
        }

                   // Release the compiled statement from memory
        sqlite3_finalize(compiledStatement);

    }


    sqlite3_close(database);


}
@catch (NSException *exception) {
    NSLog(@"Name: %@",exception.name);
    NSLog(@"Reason: %@",exception.reason);

}
@finally {

}


$ b b

欢迎任何建议。 : - )

Any suggestions are welcome. :-)

推荐答案

您不是调用 sqlite3_step 更新。在 sqlite3_prepare 之后和 sqlite3_finalize 之前,您需要类似于:

You are not calling sqlite3_step, which performs the update. After the sqlite3_prepare and before the sqlite3_finalize, you need something like:

if (sqlite3_step(compiledStatement) != SQLITE_DONE)
    NSLog(@"%s: step error: %s", __FUNCTION__, sqlite3_errmsg(database));

这篇关于Sqlite3更新查询在ios应用程序中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆