Search code examples
c++sqlitewxwidgets

Cannot populate the list with data from all rows of sqlite3 database table ,error: Trace/breakpoint trap(core dumped)


I am a beginner to wxWidgets and sqlite3. I am trying to display the data from a table in a list view. The table has several rows and three columns and I have created and inserted the columns in the list view.

Here is the part of code I am having trouble with:

int i = 0;
sqlite3 *db;
sqlite3_stmt *stmt;
sqlite3_stmt *cstmt;
const char* sql = "SELECT *FROM List";
sqlite3_open("MEMBERS.db",&db);
sqlite3_prepare_v2(db,sql,-1,&stmt,NULL);
sqlite3_step(stmt);
while(sqlite3_step(stmt) == SQLITE_ROW)
{
 list -> InsertItem(i,sqlite3_column_text(stmt,i));
 list->SetItem(i,i+1,sqlite3_column_text(stmt,i+1),-1);
 list ->SetItem(i,i+2,sqlite3_column_text(stmt,i+2),-1);
 i++;
}
sqlite3_finalize(stmt);

Whenever I compile and try to run this, I get an error saying "/src/common/list.cpp(317): assert "Assert failure" failed in Item(): invalid index in wxListBase::Item" If I comment out the two 'list -> SetItem(...)' lines, I do not get this error and I see the data in the second row of the table displayed in the first column. How can I solve this issue?


Solution

  • Why are using i+1 and i+2 as column indices for SetItem()? This is clearly wrong, the columns are numbered 0, 1 and 2.