【问题标题】:Sqlite error: Could not reset the virtual machineSqlite 错误:无法重置虚拟机
【发布时间】:2018-02-13 17:07:28
【问题描述】:

我正在尝试从 csv 文件中读取数据并将每一行添加到 c++ 中的数据库中。 csv 文件格式为id,firstname,surname,job 我的代码是:

while (file.good())
        {
          getline (file, id, ',');
          getline (file, firstname, ',');
          getline (file, surname, ',');
          getline (file, job, ' ');

          cur->set_sql( "INSERT INTO staff VALUES (?, ?, ?, ?);" );
          cur->prepare();

          cur->bind(1, id);
          cur->bind(2, firstname);
          cur->bind(3, surname);
          cur->bind(4, job);
          cur->step();

          cur->reset();
        }

但是当我运行代码时它返回错误Sqlite error: Could not reset the virtual machine. 我不明白这是什么意思或如何解决它。我在谷歌上搜索了错误,但我找不到任何关于它的信息

【问题讨论】:

  • 你看过step的返回码了吗?
  • @UKMonkey 它返回 0
  • 致电sqlite3_errmsg() 以获取实际的错误消息。
  • @CL。它返回1,这意味着sqlite_error
  • sqlite3_errmsg() 不返回数字。

标签: c++ sqlite csv


【解决方案1】:

错误来自libsqlite.hpp(在 github.com 上查看搜索)

void reset(){
        int rc = sqlite3_reset(this->_s);
        if (rc != SQLITE_OK) {
            exception e("Could not reset the virtual machine.");
            throw e;
        }
        this->_valid = true;
        this->_has_row = false;
        this->_prepared = false;
}

我还没有深入研究,但看起来 sqilte 查询包含错误或无法运行。

【讨论】:

    【解决方案2】:

    我发现了如何解决这个错误。我意识到我正在虚拟机上编程,我需要做的就是重新启动它。我的代码没有任何问题!

    【讨论】:

      猜你喜欢
      • 2018-07-17
      • 2013-10-14
      • 2017-05-30
      • 1970-01-01
      • 2014-07-23
      • 2019-08-16
      • 2013-12-07
      • 2020-05-20
      相关资源
      最近更新 更多