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

Function main

tests/prepared_statment.cc:7–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5using namespace std;
6
7int main() {
8 try {
9
10 database db(":memory:");
11
12 auto pps = db << "select ?"; // get a prepared parsed and ready statment
13
14 int test = 4;
15 pps << test; // set a bound var
16
17 pps >> test; // execute statement
18
19 pps.reset();
20
21 pps << 4; // bind a rvalue
22 pps++; // and execute and reset
23
24 pps << 8 >> test;
25
26 auto pps2 = db << "select 1,2,3,4,5"; // multiple extract test
27
28 pps2 >> [](int a, int b, int c, int d, int e) {
29 std::cout << "L " << a << b << c << d << e << "\n"; // still works as intended
30 };
31
32 auto pps3 = db << "select ?,?,?";
33
34 pps3 << 1 << test << 5 >> [](int a, int b, int, int c) {
35 std::cout << "L2 " << a << b << c << "\n"; // still works as intended
36 };
37
38 db << "select ?,?" << test << 5 >> test; // and mow everything together
39
40 db << "select ?, ?, ?" << 1 << test << 1 >> [](int a, int b, int, int c) {
41 std::cout << "L3 " << a << b << c << "\n"; // still works as intended
42 };
43
44 db << "select ?" << test; // noVal
45 db << "select ?,?" << test << 1;
46 db << "select ?,?" << 1 << test;
47 db << "select ?,?" << 1 << 1;
48 db << "select ?,?" << test << test;
49
50 db << "select ?" << test >> test; // lVal
51 db << "select ?,?" << test << 1 >> test;
52 db << "select ?,?" << 1 << test >> test;
53 db << "select ?,?" << 1 << 1 >> test;
54 db << "select ?,?" << test << test >> test;
55
56 int q = 0;
57
58 db << "select ?" << test >> [&](int t) { q = t++; }; // rVal
59 db << "select ?,?" << test << 1 >> [&](int t, int p) { q = t + p; };
60 db << "select ?,?" << 1 << test >> [&](int t, int p) { q = t + p; };
61 db << "select ?,?" << 1 << 1 >> [&](int t, int p) { q = t + p; };
62 db << "select ?,?" << test << test >> [&](int t, int p) { q = t + p; };
63
64 db << "select ?,?,?" << test << 1 << test; // mix

Callers

nothing calls this directly

Calls 2

resetMethod · 0.80
executeMethod · 0.80

Tested by

no test coverage detected