sqlite更新查询不能在c++中工作

sqlite update query not working in C++

本文关键字:c++ 工作 不能 更新 查询 sqlite      更新时间:2023-10-16

我写了一个函数来更新数据库表中名为fsize的字段,但我的函数不起作用。我不知道为什么。我调试sqlite的错误代码,这是0,所以我不知道什么是错的。

void update_fsize(int asizex, char path[], int sizex) {
    char *q;
    q="UPDATE search SET ustat=0,fsize=? WHERE fpath=?";
    if (sqlite3_prepare_v2(db, q, strlen(q), &pointer, 0) == SQLITE_OK) {
        sqlite3_bind_int(pointer, 1, asizex);   
        sqlite3_bind_text(pointer, 2, path, strlen(path), 0); // file path
        sqlite3_step(pointer);   // prepare statemnt Ready
        sqlite3_finalize(pointer);   
    }
    int ecode = sqlite3_errcode(db);
    cout << "n error code is " << ecode;
    cout << "nnn Path: " << path << "n actual size: " << asizex << "n Recored size: " << sizex;
}

特别感谢大家对我的帮助@WhozCraig:)

我将发布解决方案,也许其他人会发现它有用伪代码:
function 1(){
// getting data from database 
data if == to this 
then 
sqlite3_reset(pointer);  // reset pointer 
call db_updater();
db_updater(){
updating database using update query 
}
所以在跳转到另一个函数之前重置指针