【问题标题】:sqlite3_step() returns SQLITE_MISUSE in tutorial situationsqlite3_step() 在教程情况下返回 SQLITE_MISUSE
【发布时间】:2014-10-02 20:36:39
【问题描述】:

我是第一次使用SQLite3,无法弄清楚以下错误。以下是相关行:

//open db; I checked, and sqlite3_open() returns 0 here (SQLITE_OK)
rc = sqlite3_open(filename.c_str(),&db);

//...

//create & prepare query.
string query = "SELECT * FROM MOCK_DATA;"; //I am positive MOCK_DATA exists and is non empty
sqlite3_stmt* stmt;
cout<<sqlite3_prepare(db,query.c_str(),0,&stmt,NULL)<<endl; //this prints 0: SQLITE_OK

//here we get the error 
cout<<sqlite3_step(stmt)<<endl; //returns 21: SQLITE_MISUSE

谁能告诉我我做错了什么? :) 谢谢!

【问题讨论】:

    标签: c++ sql sqlite


    【解决方案1】:

    sqlite3_prepare() 的第二个参数是 SQL 字符串的长度。零表示您的 SQL 为空。提供一个负值,例如 -1 以使 sqlite3 读取到 C 字符串中的第一个 NUL 字符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多