为什么sqlite3pp示例会以这种方式运行?

时间:2022-06-05 01:44:47

So I try simple sqlite3pp modified a bit code:

所以我尝试简单的sqlite3pp修改了一下代码:

#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();

}

First time it gives such output:

第一次提供这样的输出:

0
0
0
0
0
0
0

And on second time and forward when I execute it:

当我执行它时,第二次和前进:

0
0
1
19
1
column email is not unique

Why it does not throw any error sooner than 5th (SQL error codes)?

为什么它不会比第5次(SQL错误代码)更快地抛出任何错误?

1 个解决方案

#1


2  

Having had a quick look in the implementation of sqlite3pp, it seems stuff tends to just return error codes, and expects you to check them; it looked like it could be the destructor for the transaction that is throwing an exception, which is why you see your error message at the point that you do.

快速浏览一下sqlite3pp的实现,似乎东西往往只返回错误代码,并希望你检查它们;看起来它可能是抛出异常的事务的析构函数,这就是为什么你在你做的时候看到你的错误消息。

#1


2  

Having had a quick look in the implementation of sqlite3pp, it seems stuff tends to just return error codes, and expects you to check them; it looked like it could be the destructor for the transaction that is throwing an exception, which is why you see your error message at the point that you do.

快速浏览一下sqlite3pp的实现,似乎东西往往只返回错误代码,并希望你检查它们;看起来它可能是抛出异常的事务的析构函数,这就是为什么你在你做的时候看到你的错误消息。