mardi 24 février 2015

I'm trying to use C++ and SQLite but I don'tknow how to pass the parameters into a single string to form the SQLite command.



void InsertDB(unsigned long long phone,string name,int age,string address,long int zipcode)
{
stringstream insert;
insert << "INSERT INTO ADBOOK (PHONE,NAME,AGE,ADDRESS,ZIPCODE) VALUES (" << phone << ",'" << name << "'," << age << ",'" << address << "'," << zipcode << " ); ";
sql = insert.str();

/* Execute SQL statement */
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
fprintf(stdout, "Records created successfully\n");
}
return;

}


I keep getting an error error: cannot convert std::basic_string<char, std::char_traits<char>, std::allocator<char> >' tochar*' in assignment


How can I make this block of code work?


Is there any easier way to implement this? This is a project which requires C++ and any kind of database (MySQL,etc.)


Aucun commentaire:

Enregistrer un commentaire