-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcpp.api3.cpp
More file actions
47 lines (39 loc) · 895 Bytes
/
cpp.api3.cpp
File metadata and controls
47 lines (39 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "sqlite3/conn.hpp"
#include "sqlite3/stmt.hpp"
#include "scope_guard.hpp"
#include <iostream>
////////////////////////////////////////////////////////////////////////////////
//
//
//
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
using namespace api::sqlite3;
using namespace std;
using namespace sg;
conn c;
c.open();
c.execute("create table hens(id int primary key, name text)");
auto g = make_scope_guard([&] { c.execute("COMMIT;"); });
try
{
// Transaction support
c.execute("BEGIN;");
stmt s;
s.prepare(c, "insert into hens(id, name) values(?, ?)");
s.bind(1, 101);
s.bind(2, "henrietta");
s.step();
s.reset();
s.bind(1, 102);
s.bind(2, "duck");
s.step();
}
catch (...)
{
g.dismiss();
c.execute("ROLLBACK;");
}
return 0;
}