2

嗨,我在我的 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;
}
4

1 回答 1

1

我运行您的代码,它在我的平台上运行良好。

为了避免隐式转换,您可以使用 setString 而不是 set,也就是说:

st.set("T1",10)
    .setString("NAME",k)
    .setString("STATUS","bye")
    .execute();
于 2014-07-20T20:23:29.810 回答