2012-01-20 1 views
0

Valgrind의 래퍼의 다음 두 가지 방법의 sqlite3_prepare_v2 및 sqlite3_step :Valgrind의 보고서는 sqlite3_step에 값을 초기화되지 않은 및 sqlite3_prepare_v2

ExecQuery에 대해 초기화되지 않은 값 오류를보고합니다 (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; 
    } 
} 

컴파일

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을 단위화할 수 없습니다.

+0

valgrind가 SQLite 호출에서 코드 라인에 대해 불평하지 않습니까? 또는 귀하의 코드에 결함이 있습니까? 때때로 valgrind 가양 성은 무시할 수 있습니다. – gravitron

+0

... sqlite3VdbeExec ... sqlite3Step ... sqlite3_step이있는이 실패 메시지의 Valgrind 스택 트레이스에는 더 깊은 행이 있습니다. Unfortunetly 내 개발자 PC는 주말 여기되지 않습니다. 나는 그 실패를 무시할 수 있을지 모르겠다. –

답변

0

오류가 발생했습니다. 생성 된 INSERT 쿼리에 SQL 구문 오류가 있습니다. 나는 왜 sqlite가 구문 오류를 말하지 않았는지 모르지만 INSERT 생성기 방법을 재 설계 한 후에 valgrind에서 더 이상 unitialised 값 문제가보고되지 않습니다. 이 메시지가 같은 문제가있는 사람에게 유용 할 수 있기를 바랍니다.