#include <iostream>
#include <sqlite3pp.h>
using namespace std;
int main(int argc, char* argv[])
{
try {
sqlite3pp::database db("test.db");
{
db.execute("CREATE TABLE IF NOT EXISTS users ( email varchar(65) primary key, pass varchar(65))");
db.execute("INSERT INTO users (email, pass) VALUES ('AAAA', '1234')");
}
{
sqlite3pp::transaction xct(db);
sqlite3pp::command cmd(db, "INSERT INTO users (email, pass) VALUES (?, ?)");
cout << cmd.bind(1, "BBBB") << endl;
cout << cmd.bind(2, "1234") << endl;
cout << cmd.execute() << endl;
cout << cmd.reset() << endl;
cmd.binder() << "CCCC" << "1234";
cout << cmd.execute() << endl;
xct.commit();
}
{
sqlite3pp::transaction xct(db, true);
sqlite3pp::command cmd(db, "INSERT INTO users (email, pass) VALUES (:name, :name)");
cout << cmd.bind(":name", "DDDD") << endl;
cout << cmd.execute() << endl;
}
}
catch (exception& ex) {
cout << ex.what() << endl;
}
cin.get();
}
第一次提供这样的输出:
0
0
0
0
0
0
0
当我执行它时第二次和前进:
0
0
1
19
1
column email is not unique
为什么它不会比第5(SQL error codes)更早出现任何错误?
答案 0 :(得分:2)
快速浏览一下sqlite3pp的实现,看起来似乎只会返回错误代码,并希望你检查它们;看起来它可能是抛出异常的事务的析构函数,这就是为什么你在你做的那一点上看到你的错误信息。