SQLite的插入語句下面是我在測試2.cpp與C++
我檢查我的數據庫,發現沒有加入新的記錄嘗試的代碼。我的發言中究竟發生了什麼錯誤?
#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的某種形式的確認。如果出現錯誤,它是否也能夠得到滿足?
在SQL中缺少'VALUES'? – 2012-08-14 05:03:00
[您可以創建數據庫,表以及將數據插入表] [1] [1]:http://stackoverflow.com/questions/10540728/creating-an-sqlite3-database-file-通過目標C/11795399#11795399 希望它會幫助你。 – 2012-08-14 05:33:43