lundi 9 novembre 2015

sqlite3_step and infinite loop

sqlite3_step is very interesting function. I dont know why this function for example if I have 3 records in table VEHICLES then I can get data of first record, next second record, next third record, next first record, next ... wait, infinity loop. If it can be important, I use all sources to compile all project and I compile it to dll library.

I opens database with this and this works. I tried also with sqlite3_open and similar functions.

sqlite3_open_v2(SQLite::name.c_str(), & SQLite::db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);

In this function something goes wrong.

bool SQLiteVehicle::getVehiclesFromDB(void)
{
sampgdk::logprintf("getVehiclesFromDB: Nakurwiam.");
int result;
std::string sql("SELECT * FROM 'VEHICLES';");
sqlite3_stmt * stmt = NULL;
if (sqlite3_prepare_v2(SQLite::db, sql.c_str(), sql.length(), &stmt, NULL) != SQLITE_OK)
{
    sampgdk::logprintf("getVehiclesFromDB: Mistake.");
    return false;
}
else
{
    while (SQLITE_ROW == (result = sqlite3_step(stmt)))
    {
        //some code
    }
}
sqlite3_finalize(stmt);
return true;
}

If I limits SQL query, then I will get number of lines as I limited.

Aucun commentaire:

Enregistrer un commentaire