嗨,我在我的 C++ 代码中使用 tntdb 类时遇到问题,只有整数值 atr 在数据库中更新,而字符串值更新为垃圾值,我在下面给出我的代码,请帮助我解决这个问题
#include <tntdb/connection.h>
#include <tntdb/connect.h>
#include <stdio.h>
#include <string>
#include <sys/shm.h>
using namespace std;
int main()
{
string s="create table test2(T1 int not null primary key,NAME varchar(20),STATUS varchar(20));";
try{
tntdb::Connection conn;
conn = tntdb::connect("sqlite:/home/gaian/Desktop/test.db");
string k="abc";
conn.execute(s);
tntdb::Statement st = conn.prepare("insert into test2(T1,NAME,STATUS) values (:T1, :NAME,:STATUS)");
st.set("T1",10)
.set("NAME",k)
.set("STATUS","bye")
.execute();
}
catch(const std::exception& e){
printf("error is %s\n",e.what());
}
return 0;
}
最佳答案
我运行了您的代码,它在我的平台上运行良好。
为了避免隐式转换,您可以使用 setString 而不是 set,也就是说:
st.set("T1",10)
.setString("NAME",k)
.setString("STATUS","bye")
.execute();
关于c++ - 如何使用 tntdb 类更新 Sqlite 数据库中的字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23757257/