File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments