MCPcopy Create free account
hub / github.com/SqliteModernCpp/sqlite_modern_cpp / main

Function main

tests/exceptions.cc:11–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10
11int main() {
12 database db(":memory:");
13 db << "CREATE TABLE person (id integer primary key not null, name TEXT);";
14 bool expception_thrown = false;
15
16 try {
17 db << "INSERT INTO person (id,name) VALUES (?,?)" << 1 << "jack";
18 // inserting again to produce error
19 db << "INSERT INTO person (id,name) VALUES (?,?)" << 1 << "jack";
20 } catch (errors::constraint& e) {
21 cerr << e.get_code() << ": " << e.what() << " during "
22 << quoted(e.get_sql()) << endl;
23 expception_thrown = true;
24#if SQLITE_VERSION_NUMBER >= 3014000
25 if(e.get_sql() != "INSERT INTO person (id,name) VALUES (1,'jack')") {
26#else
27 if(e.get_sql() != "INSERT INTO person (id,name) VALUES (?,?)") {
28#endif
29 cerr << "Wrong statement failed\n";
30 exit(EXIT_FAILURE);
31 }
32 }
33
34 if(!expception_thrown) {
35 exit(EXIT_FAILURE);
36 }
37
38 exit(EXIT_SUCCESS);
39}

Callers

nothing calls this directly

Calls 2

get_codeMethod · 0.80
get_sqlMethod · 0.80

Tested by

no test coverage detected