【发布时间】:2015-12-02 14:56:35
【问题描述】:
我是 wxWidgets 和 sqlite3 的初学者。 我正在尝试在列表视图中显示表格中的数据。 该表有几行和三列,我在列表视图中创建并插入了这些列。
这是我遇到问题的代码部分:
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);
每当我编译并尝试运行它时,我都会收到一条错误消息“/src/common/list.cpp(317): assert "Assert failure" failed in Item(): invalid index in wxListBase::Item” 如果我注释掉两个 'list -> SetItem(...)' 行,我不会收到此错误,并且我会看到第一列中显示的表格第二行中的数据。 我该如何解决这个问题?
【问题讨论】:
-
检查 SQLite 函数可能返回的错误,尤其是
sqlite3_prepare_v2。请注意,通过在循环之前调用一次sqlite3_stmt_step来跳过第一行。sqlite3_column_text返回的字符串仅在语句被逐步/最终确定之前有效,因此请确保您正在复制它们。