+ demo_caml
[sqlgg.git] / demo / demo_cxx.cpp
blobcc3619042119e75925e198b9240ba40e9d71e1d2
1 //
3 #include "../sqlite3_helper.hpp"
4 #include "demo_cxx_gen.hpp"
5 #include <iostream>
6 #include <vector>
8 using namespace std;
10 typedef sqlgg<sqlite3_traits> gen;
11 typedef long long int64;
13 int main()
15 sqlite3* db = NULL;
16 sqlite3_open(":memory:", &db);
18 // create tables
19 gen::create_person(db);
20 gen::create_money(db);
22 // add all person records
23 gen::add_person(db,"John","Black");
24 int64 john = sqlite3_last_insert_rowid(db);
25 gen::add_person(db,"Ivan","Petrov");
26 int64 ivan = sqlite3_last_insert_rowid(db);
27 gen::add_person(db,"Sancho","Alvares");
28 int64 sancho = sqlite3_last_insert_rowid(db);
30 // add money relations
31 gen::add_money(db,john,ivan,200);
32 gen::add_money(db,john,sancho,100);
33 gen::add_money(db,john,sancho,250);
34 gen::add_money(db,sancho,ivan,300);
36 // summarize by person
37 typedef std::vector<gen::data_4> collection;
38 collection all;
39 gen::calc_debit(db,all);
41 // output
42 for (collection::const_iterator i = all.begin(), end = all.end(); i != end; ++i)
44 std::cout << i->fullname << " = " << i->debit << std::endl;
47 // properly close database
48 sqlite3_close(db);
50 return 0;