gen: fix IN expr codegen for caml
[sqlgg.git] / demo / demo_cxx.cpp
blob8d3ae8b4007439bc2880928f7ac45cfc7983974c
1 #include "../impl/sqlite3_traits.hpp" // sqlite3 traits
2 #include "demo_cxx_gen.hpp" // generated
3 #include <iostream>
4 #include <vector>
6 using namespace std;
8 typedef sqlgg<sqlite3_traits> gen_t;
9 typedef long long int64;
11 struct output_transfers
13 void operator()(std::string const& fullname, int total)
15 cout << fullname << " = " << total << endl;
19 struct output_donors
21 void operator()(std::string const& surname)
23 cout << surname << endl;
27 int main()
29 sqlite3* db = NULL;
30 sqlite3_open(":memory:", &db);
32 gen_t gen(db);
34 // create tables
35 gen.create_person();
36 gen.create_money();
38 // add all person records
39 gen.add_person("John","Black");
40 int64 john = sqlite3_last_insert_rowid(db);
41 gen.add_person("Ivan","Petrov");
42 int64 ivan = sqlite3_last_insert_rowid(db);
43 gen.add_person("Sancho","Alvares");
44 int64 sancho = sqlite3_last_insert_rowid(db);
46 // add money relations
47 gen.add_money(john,ivan,200);
48 gen.add_money(john,sancho,100);
49 gen.add_money(john,sancho,250);
50 gen.add_money(sancho,ivan,300);
52 // summarize by person
53 cout << "Total transfers:" << endl;
54 gen.calc_total(output_transfers());
56 // list donors
57 cout << "Donors:" << endl;
58 gen.list_donors("petrov",100,output_donors());
60 // properly close database
61 sqlite3_close(db);
63 return 0;