gpt4 book ai didi

c++ - sqlite3_step() 在教程情况下返回 SQLITE_MISUSE

转载 作者:太空宇宙 更新时间:2023-11-04 11:27:22 28 4
gpt4 key购买 nike

我是第一次使用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

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

最佳答案

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

关于c++ - sqlite3_step() 在教程情况下返回 SQLITE_MISUSE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26169231/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com