samedi 7 novembre 2015

cannot input data to sqlite database with c++

hy all.. can somebody help me.. i have problem with my code.. i can't input data to my database , i'm using sqlite ...

# include <stdio.h>
# include <iostream>
# include <sqlite3.h> 
# include <stdlib.h>
# include <cstring>
using namespace std;
int main()
{
sqlite3 *conn;
sqlite3_stmt *res;
//int     error = 0;
int rc;
int     rec_count = 0;
const char     *errMSG;
const char     *tail;
//char sql_lite[900]=" ";
int x,number;
string name;
string username;
string password;
rc = sqlite3_open("databaseLogin.db", &conn);
if (rc!=SQLITE_OK)
{
cout<<"Can not open database";

}


cout<<"Enter the number of data to be inserted : ";
cin>>x;

for(number=x;number>0;number--) 
{ 
cout<<"name : ";cin>>name;
cout<<"username : ";cin>>username;
cout<<"password : ";cin>>password;
}
string query = "INSERT INTO login (name,username,password) VALUES ('" +username + "','" + name + "','" + password + "');";

rc = sqlite3_exec(conn, query.c_str(),0, 0, 0);
rc = sqlite3_prepare_v2(conn, "SELECT * FROM login order by No",1000,     &res, &tail);
if (rc != SQLITE_OK)
{
cout<<"We did not get any data!";
exit(0);

}

cout<<"=======================================\n";

while (sqlite3_step(res) == SQLITE_ROW)
{
cout<<sqlite3_column_text(res, 0);
cout<<sqlite3_column_text(res, 1);
cout<<sqlite3_column_text(res, 2);


rec_count++;
}

cout<<"=======================================\n";
cout<<"We received %d records.\nTotal rows=%d\n"<<rec_count<<SQLITE_ROW;

sqlite3_finalize(res);

sqlite3_close(conn);

return 0;
} 

my program returned "we did't got any data" please help me.. i have already placing the databaseLogin.db in the correct path... and i still got this .. thanks

Aucun commentaire:

Enregistrer un commentaire