With the "users" table created, I am ready to enter data in it. These data are entered by the user, and then inserted in the table. I have the following function:
int registrarUsuario(string name, string second){
sqlite3 *db;
int conn;
int exec;
string sql;
// Abriendo conexion con la base de datos
conn = sqlite3_open("usuarios.db", &db);
if(SQLITE_OK != conn){
system("clear");
cerr << "\E[1;31mImposible introducir los datos datos\E[0;00m" << endl;
cin.get();
cin.sync();
sqlite3_close(db);
return 1;
}
else{
system("clear");
// Creando datos SQL
sql = "INSERT INTO usuarios(Nombre,Apellidos) VALUES("+ name + "," + second + ");";
// Introduciendo datos SQL
exec = sqlite3_exec(db, sql.c_str(), NULL, NULL, NULL);
if( SQLITE_OK == exec){
cout << "\E[1;32mDatos introducidos con exito\E[0;00m" << endl;
cin.get();
cin.sync();
sqlite3_close(db);
return 0;
}
}
}
Once entered, the function is called with those parameters. The problem is that when the function is called the program is completely closed.