Below is the code I have tried on a test2.cpp
I checked my database and found out no new record had been added. What actually went wrong in my statement?
#include <iostream>
#include <sqlite3.h>
//g++ -o test2 test2.cpp -lsqlite3
using namespace std;
int main()
{
int counter = 0;
sqlite3 *db;
sqlite3_stmt * stmt;
string username = "panda";
string name = "Kungfu Panda";
string department = "normal";
string password = "hellopassword";
string sqlstatement = "INSERT INTO abe_account (" + username + "," + name + "," + department + "," + password + ");";
if (sqlite3_open("abeserver.db", &db) == SQLITE_OK)
{
sqlite3_prepare( db, sqlstatement.c_str(), -1, &stmt, NULL );//preparing the statement
sqlite3_step( stmt );//executing the statement
}
else
{
cout << "Failed to open db\n";
}
sqlite3_finalize(stmt);
sqlite3_close(db);
return 0;
}
I would like to ask if it's possible to know if the statement is executed with success too. Like one row added, some form of confirmation from sqlite3. And if there's an error, will it be able to cout out too?