【问题标题】:Cannot populate the list with data from all rows of sqlite3 database table ,error: Trace/breakpoint trap(core dumped)无法使用来自 sqlite3 数据库表的所有行的数据填充列表,错误:跟踪/断点陷阱(核心转储)
【发布时间】: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 返回的字符串仅在语句被逐步/最终确定之前有效,因此请确保您正在复制它们。

标签: c++ sqlite wxwidgets


【解决方案1】:

为什么使用i+1i+2 作为SetItem() 索引?这显然是错误的,列编号为 0、1 和 2。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-27
    • 2012-01-10
    • 1970-01-01
    • 1970-01-01
    • 2012-12-18
    • 2019-01-25
    相关资源
    最近更新 更多