c++ - sqlite C API,UDATE 数据库

标签 c++ sql database api sqlite

我目前正在开发一种在我已有的程序中创建编辑窗口的方法,该方法访问一个 Sqlite 数据库,该数据库已设置并包含 4 条信息、条目 ID、条目名称(其中是用户指定的),文件位置(也是用户输入的)和组成员。 在编辑窗口中,有两个标签,一个用于名称的文本输入框和一个用于打开文件浏览器的按钮。 我的问题是当我在添加新窗口中设置 sql 数据库时,所有数据都设置在数据库中,虽然当我想从数据库中编辑数据时,我目前删除旧数据然后添加新数据,尽管查看在线文档我发现了一个 UPDATE 方法,虽然这会工作得更好,但无法以某种方式为数据库获取正确的索引,我如何调用索引 3,我得到一个错误

Unhandled exception at 0x01143622 in bv.exe: 0xC0000005: Access violation reading location 0x00000000.

经过一些研究,我发现这是由 NULL 引用指针引起的,我能找到的唯一原因是该字段为空,但我在添加窗口中明确设置了它。 请帮助:(

std::string campaign_sql("SELECT id, name, config, members FROM bv_campaigns");

sqlite3_stmt *prepped_statement;
sqlite3_prepare(mainApp->GetAppData().db_conn, campaign_sql.c_str(), campaign_sql.length(), &prepped_statement, NULL);
//std::string name((const char *)sqlite3_column_text(prepped_statement, 1));
while ( SQLITE_ROW == sqlite3_step(prepped_statement) ) 
{
    std::string name((const char *)sqlite3_column_text(prepped_statement, 1));
    wxMessageBox(name);
    std::string config((const char *)sqlite3_column_text(prepped_statement, 3));
    wxMessageBox(config);

返回 NULL 引用错误

std::string name = pds.getCampaignName();
            std::string config = pds.serialize();

            std::string update_sql("INSERT INTO bv_campaigns (name, type, config) VALUES(?,'campaignCallListDataSourcePython',?)");
            sqlite3_stmt *prepped_statement;
            sqlite3_prepare(this->GetAppData().db_conn, update_sql.c_str(), update_sql.length(), &prepped_statement, NULL);

            sqlite3_bind_text(prepped_statement, 1, name.c_str(), name.length(), NULL);
            sqlite3_bind_text(prepped_statement, 3, config.c_str(), config.length(), NULL);

在添加数据的地方,序列化和获取事件名称函数从添加窗口获取值,

我认为这就是所需的一切。如果我遗漏了什么,请询问。 谢谢

最佳答案

sqlite3_column_text(..., 3) 读取第四个 SELECT 列的值,即 members

此列尚未由您的 INSERT 命令设置,因此它是 NULL

(此外,在 INSERT 命令中,参数的索引为 1 和 2;您也从未设置过 config。)

关于c++ - sqlite C API,UDATE 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13089698/

相关文章:

php - 喜欢使用 Laravel 构建表格,并在顶部显示最受欢迎的内容

c# - BindingNavigator“保存”按钮未将数据保存到数据库

database - 甲骨文假直方图

c++ - 结构体数组的最大大小

c++ - C++ 中的常量混淆

python - 使用适当的变量类型将 CSV 文件从 redshift 导出到本地

Java 将数据从 CSV 导入 SQL 防止重复输入

c++ - Qt 线程似乎并没有在核心上平均共享

c++ - std::tr1::function 及其接受的模板值

mysql - 在MySQL中将列填充到最大值?