-
Notifications
You must be signed in to change notification settings - Fork 1
/
ptnk_dump.cpp
47 lines (39 loc) · 963 Bytes
/
ptnk_dump.cpp
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 <iostream>
#include <memory>
#include "ptnk.h"
using namespace ptnk;
int
main(int argc, char* argv[])
{
if(argc < 2)
{
fprintf(stderr, "usage: %s ptnkdb\n", argv[0]);
return 1;
}
try
{
const char* dbfile = argv[1];
DB db(dbfile);
Buffer tablename;
std::unique_ptr<DB::Tx> tx(db.newTransaction());
for(int i = 0; /* NOP */; ++ i)
{
tx->tableGetName(i, &tablename);
if(! tablename.isValid()) break;
std::cout << "** Table: " << tablename.rref().inspect() << std::endl;
Buffer k(4096), v(4096);
std::unique_ptr<DB::Tx::cursor_t, decltype(&DB::Tx::curClose)> cur(tx->curFront(tablename.rref()), DB::Tx::curClose);
if(! cur.get()) continue;
do
{
tx->curGet(&k, &v, cur.get());
std::cout << k.rref().inspect() << " -> " << v.rref().inspect() << std::endl;
}
while(tx->curNext(cur.get()));
}
}
catch(std::exception& e)
{
std::cerr << "caught exception: " << e.what() << std::endl;
}
}