1 Replies - 177 Views - Last Post: 25 June 2014 - 03:02 AM Rate Topic: -----

#1 ixoye36  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-June 14

Sqlite3 and c++ : insert users values

Posted 25 June 2014 - 01:33 AM

Hi (I dont know if I have to introduce myself somewhere sry If I had to)
Im programming a questionnary using a sqlite database.

I need know that I opened and created my table in my c++ code, to insert data in the table.
My problem now is that I want to insert the informations the user gave in the database..
It looks like this :
//Go for the user infos
   cout << "What is your ID ? : ";
   cin >> id;
   cout << "What is you letter ? : ";
   cin >> letter;

   cout << "Your letter is "<<letter<< " and your ID is "<<id<<"\n";
   
   //Create a table for user infos

   sql1 = "CREATE TABLE USER( ID INT PRIMARY KEY NOT NULL, LET CHAR NOT NULL,)";
   
	   rc = sqlite3_exec(db, sql, callback2, 0, &zErrMsg);
   if( rc != SQLITE_OK ){
   cout << "SQL error: %s\n\n"<< zErrMsg;
      sqlite3_free(zErrMsg);
   }else{
      cout << "Table created successfully\n";
   }

   sql2 = "INSERT INTO USER VALUES (*?*, *?*)"
	   
	   rc = sqlite3_exec(db, sql2, callback2, 0, &zErrMsg);
   if( rc != SQLITE_OK ){
     cout << "SQL error: %s\n"<< zErrMsg;
      sqlite3_free(zErrMsg);
   }else{
      cout << "Records created successfully\n";
   }


I dont know how to insert "letter" and "id" into the table "USER" as you can see line 22

Thank you for your help

Is This A Good Question/Topic? 0
  • +

Replies To: Sqlite3 and c++ : insert users values

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,661
  • Joined: 23-August 08

Re: Sqlite3 and c++ : insert users values

Posted 25 June 2014 - 03:02 AM

Use prepared statements
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1