2

hi i am getting a problem while using tntdb classes in my c++ code only integer values atr updating in database while string values are updating as garbage values i am giving my code below please help me out to solve this issue

#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;
}
jplatte
  • 1,121
  • 11
  • 21
user2406774
  • 151
  • 1
  • 1
  • 7
  • The code looks valid to me at first glance. Could you please be more specific about the problem you have? – jplatte May 20 '14 at 12:37

1 Answers1

1

I run your code and it works fine on my plateform.

In order to avoid implicit cast you could use setString instead of set, that is to say :

st.set("T1",10)
    .setString("NAME",k)
    .setString("STATUS","bye")
    .execute();
mpromonet
  • 11,326
  • 43
  • 62
  • 91