Skip to content

Commit 268a3cb

Browse files
committed
Add additional test
1 parent 2f8061f commit 268a3cb

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/error_log2.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
#include <iomanip>
3+
#include <string>
4+
#include <memory>
5+
#include <stdexcept>
6+
#include <sqlite_modern_cpp.h>
7+
#include <sqlite_modern_cpp/log.h>
8+
using namespace sqlite;
9+
using namespace std;
10+
11+
12+
int main() {
13+
bool error_detected = false;
14+
error_log(
15+
[&](errors::constraint e) {
16+
cerr << e.get_code() << '/' << e.get_extended_code() << ": " << e.what() << endl;
17+
error_detected = true;
18+
}
19+
);
20+
database db(":memory:");
21+
db << "CREATE TABLE person (id integer primary key not null, name TEXT);";
22+
23+
try {
24+
db << "INSERT INTO person (id,name) VALUES (?,?)" << 1 << "jack";
25+
// inserting again to produce error
26+
db << "INSERT INTO person (id,name) VALUES (?,?)" << 1 << "jack";
27+
} catch (errors::constraint& e) {
28+
}
29+
30+
if(!error_detected) {
31+
exit(EXIT_FAILURE);
32+
}
33+
34+
exit(EXIT_SUCCESS);
35+
}

0 commit comments

Comments
 (0)