下面是我在 test2.cpp 上尝试过的代码
我检查了我的数据库,发现没有添加新记录。我的陈述实际上出了什么问题?
#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;
}
我想问是否有可能知道该语句是否也成功执行。就像添加的一行一样,来自 sqlite3 的某种形式的确认。如果出现错误,它是否也能识别出来?