SQLite更新语句执行没有错误,但表行没有更新?

时间:2011-10-06 15:55:32

标签: iphone sqlite

我不能为我的生活看到它可能是什么?任何建议?感谢

(void)setRegId: (NSInteger) _regId

{

NSInteger r_id = _regId;
NSInteger row = 1;

ret = sqlite3_open(dbName, &database);
if (ret != SQLITE_OK)
{
    printf("Error opening the db: %s\n", sqlite3_errmsg(database));
    sqlite3_close(database);
    return;
}

sqlite3_stmt *compiledStatement = nil;
if (compiledStatement == nil) {
    const char *sql = "UPDATE RegDB Set id = ? Where rowindex = ?";

    if (sqlite3_prepare_v2(database, sql, -1, &compiledStatement, NULL) != SQLITE_OK) 
    {
        NSLog(@"Error: failed to prepare compiledStatement with message '%s'.",sqlite3_errmsg(database));
        return;
    }
}

sqlite3_bind_int(compiledStatement, 1, r_id);
sqlite3_bind_int(compiledStatement, 2, row);

int success = sqlite3_step(compiledStatement);
if (success == SQLITE_ERROR){
    NSLog(@"Error: failed to update compiledStatement with message '%s'.", sqlite3_errmsg(database));
}

sqlite3_finalize(compiledStatement);

if(sqlite3_close(database) != SQLITE_OK)
{
    NSLog(@"Error: failed to closed DB with message     '%s'.",sqlite3_errmsg(database));
    }

        }

1 个答案:

答案 0 :(得分:0)

您需要检查是否正在发送正确的更新语句,并且您正在正确读取结果。

尝试记录您的最终陈述(或至少记录变量r_idrow)。在Firefox中使用sqlite3或SQLiteManager来检查数据库中的更改。