For simplicity I made this script, I count the times it enters the loop and I show them on the screen, as I have only one row the correct result is 1, but in the second way it returns a 2
That is, the first time you enter the loop is junk data, and the second time you enter is the correct data
Code: Select all
#include "Probando.h"
#include <wx/string.h>
#include "include/wx/wxsqlite3.h"
#include <iostream>
#include <wx/filefn.h>
using namespace std;
void Probando::crear_tabla ( ) {
wxString testDBName = wxGetCwd() + wxT("/test4.db");
wxSQLite3Database* db = new wxSQLite3Database();
db->Open(testDBName);
// db->ExecuteUpdate(wxT("CREATE TABLE test (col1 INTEGER)"));
// db->ExecuteUpdate(wxT("INSERT INTO test (col1) VALUES (2)"));
// IT IS OK!!!
wxSQLite3ResultSet set = db->ExecuteQuery(wxT("SELECT * FROM test"));
int count = 0;
while (set.NextRow())
{
count++;
}
cout<<"Count one:"<<count<<endl;
//IT IS WRONG!!!
wxSQLite3Statement stmt2 = db->PrepareStatement("select * FROM test");
set = stmt2.ExecuteQuery();
stmt2.Reset();
count = 0;
cout<<"Reset: count now = "<<count<<endl;
while (set.NextRow())
{
count++;
}
cout<<"Count two:"<<count;
set.Finalize();
}
Why can it happen? Am I using functions incorrectly?
Sorry for my English