-1

我对 Sqllite 更新语句有问题,它不起作用。我不知道为什么,因为一切似乎都很好。错误代码为 0

char *q; // query
char fp[MAX_PATH];
q="UPDATE search SET ustat=1 WHERE fpath=?";
for(int i=0; i<=6; i++){
    if(sqlite3_prepare_v2(db, q, strlen(q), &pointer, 0) == SQLITE_OK){
        //cout<<"\n\n inside loop i values is "<<i<<"\n\n";
        snprintf(fp,MAX_PATH,xbx[i].fpaths,0);
        sqlite3_bind_text(pointer, 1,  fp, strlen(fp), 0); // file name
        sqlite3_step(pointer);   // prepare statemnt Ready
        sqlite3_finalize(pointer);   
    }
}

我在绑定文本语句中使用结构然后我认为问题可能是由于结构然后我将其更改为本地缓冲区但没有成功。

更新:我尝试删除循环并手动设置,但更新语句仍然没有任何问题?????? 错误代码 0

if(sqlite3_prepare_v2(db, q, strlen(q), &pointer, 0) == SQLITE_OK){
                        sqlite3_bind_text(pointer, 1,  xbx[0].fpaths, sizeof(xbx[0].fpaths), 0); // file name
                        sqlite3_bind_text(pointer, 1,  xbx[1].fpaths, sizeof(xbx[1].fpaths), 0);
                        sqlite3_bind_text(pointer, 1,  xbx[2].fpaths, sizeof(xbx[2].fpaths), 0);
                        sqlite3_bind_text(pointer, 1,  xbx[3].fpaths, sizeof(xbx[3].fpaths), 0);
                        sqlite3_bind_text(pointer, 1,  xbx[4].fpaths, sizeof(xbx[4].fpaths), 0);
                        sqlite3_step(pointer);   // prepare statemnt Ready   
                        sqlite3_finalize(pointer);  // delete  prepared statement
            }   
4

1 回答 1

0

好的,我找到了由于 sqlite finalize 语句引起的解决方案....检查您可能错过的所有程序,并且没有放置 sqlite finalize 语句..所以问题解决了:)

if(sqlite3_prepare_v2(db, q, strlen(q), &pointer, 0) == SQLITE_OK){
    //cout<<"\n\n inside loop i values is "<<i<<"\n\n";
    snprintf(fp,MAX_PATH,xbx[i].fpaths,0);
    sqlite3_bind_text(pointer, 1,  fp, strlen(fp), 0); // file name
    sqlite3_step(pointer);   // prepare statemnt Ready 
    sqlite3_reset(pointer);
}
    sqlite3_finalize(pointer);  

}

于 2012-12-27T08:44:03.333 回答