forked from ahupowerdns/lmdb-safe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lmdb-view.cc
42 lines (34 loc) · 984 Bytes
/
lmdb-view.cc
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
#include "lmdb-safe.hh"
#include <iostream>
using namespace std;
void countDB(MDBEnv& env, MDBROTransaction& txn, const std::string& dbname)
{
auto db = txn->openDB(dbname, 0);
auto cursor = txn->getCursor(db);
uint32_t count = 0;
MDBOutVal key, val;
while(!cursor.get(key, val, count ? MDB_NEXT : MDB_FIRST)) {
cout << key.get<string>();
if(key.d_mdbval.mv_size == 4)
cout << " " << key.get<uint32_t>();
cout<<": " << val.get<std::string>();
cout << "\n";
++count;
}
cout <<count<<endl;
}
int main(int argc, char** argv)
{
MDBEnv env(argv[1], MDB_RDONLY | MDB_NOSUBDIR, 0600);
auto main = env.openDB("", 0);
auto txn = env.getROTransaction();
auto cursor = txn->getCursor(main);
MDBOutVal key, val;
if(cursor.get(key, val, MDB_FIRST)) {
cout << "Database is empty" <<endl;
}
do {
cout << key.get<string>() << endl;
countDB(env, txn, key.get<string>());
} while(!cursor.get(key, val, MDB_NEXT));
}