0
Valgrind的報告有關sqlite3_prepare_v2和sqlite3_step在包裝的以下兩種方法:Valgrind的報告中sqlite3_step未初始化值和sqlite3_prepare_v2
使用ExecQuery未初始化值誤差:
bool
CSQLiteDB::execQuery(const char* szSQL,CSQLiteQuery& sqlite_query_out, string* error /*=NULL*/)
{
if(!checkDB()){
return false;
}
//HERE IS THE ESSENCE
sqlite3_stmt* pVM = NULL;
if(!compile(szSQL,&pVM,error))
{
return false;
}
int nRet = sqlite3_step(pVM); //Here is the second call with uninitialised value.
//HERE IS THE END OF THE ESSENCE
if (nRet == SQLITE_DONE)
{
sqlite_query_out = CSQLiteQuery(mpDB, pVM, true/*eof*/);
return true;
}
else if (nRet == SQLITE_ROW)
{
// at least 1 row
sqlite_query_out = CSQLiteQuery(mpDB, pVM, false/*eof*/);
return true;
}
else
{
nRet = sqlite3_finalize(pVM);
if(error)
*error= sqlite3_errmsg(mpDB);
return false;
}
}
編譯(從使用ExecQuery調用)
bool
CSQLiteDB::compile(const char* szSQL,sqlite3_stmt** pVM, string* error /*=NULL*/)
{
checkDB();
const char* szTail = 0;
int nRet = sqlite3_prepare_v2(mpDB, szSQL, -1, pVM, &szTail); //Here is the first call with uninitialized error.
if (nRet != SQLITE_OK)
{
if(error)
*error = sqlite3_errmsg(mpDB);
return false;
}
return true;
}
可錯了呢?在sqlite3_prepare_v2中,pVM是一個輸出值。由於sqlite3_prepare_v2,pVM int sqlite3_step不能單元化。
valgrind是否抱怨SQLite調用中的一行代碼?或者你的代碼有問題?有時Valgrind誤報可以忽略... – gravitron
Valgrind stacktrace中有很多更深層次的行,在這個失敗消息中有... sqlite3VdbeExec ... sqlite3Step ... sqlite3_step。不幸的是,我的開發人員電腦在週末不在這裏。我不知道我能否忽視失敗。 –