Menu

[r46]: / framework / trunk / tests / bdbtest.cpp  Maximize  Restore  History

Download this file

76 lines (66 with data), 1.4 kB

 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "easy_bdb.h"
#include <iostream>
using namespace std;
using namespace ebdb;
struct data {
int val;
int sq;
};
int main(int argc,char **argv)
{
Environment e("./db/");
Index_Auto_Increment<data,int,&data::val> db(e,"test.db",DB_BTREE);
data d;
int i;
int N=10;
try{
if(argc==2 && argv[1][0]=='c') {
e.create();
db.create();
}
else {
e.open();
db.open();
}
cursor<data,int> cur(db);
if(argc==2 && argv[1][0]=='c') {
for(i=0;i<N;i++) {
d.val=i;
d.sq=i*i;
if(db.insert(d)) {
cout<<"Inserted: "<<d.val<<endl;
}
else {
cout<<"Not Inserted: "<<d.val<<endl;
}
}
}
#if 1
for(cur.begin();cur;cur++) {
d=cur;
cout<<d.val<<' '<<d.sq<<endl;
/*if(d.val<10) {
d.sq++;
cur=d;
}
else {
cur.del();
}*/
}
#elif 0
for(i=0;i<N;i++) {
db.get(i,d);
// cout<<d.val<<' '<<d.sq<<endl;
d.sq++;
db.update(d);
}
#endif
cout<<d.sq<<endl;
}
catch(DbException &e) {
cerr<<e.what()<<endl;
}
db.close();
e.close();
return 0;
}
MongoDB Logo MongoDB