00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <db_cxx.h>
00015 #include <iostream.h>
00016
00017 static void show_dbt(ostream &os, Dbt *dbt)
00018 {
00019 int i;
00020 int size = dbt->get_size();
00021 unsigned char *data = (unsigned char *)dbt->get_data();
00022
00023 os << "size: " << size << " data: ";
00024 for (i=0; i<size && i<10; i++) {
00025 os << (int)data[i] << " ";
00026 }
00027 if (i<size)
00028 os << "...";
00029 }
00030
00031 int main(int argc, char *argv[])
00032 {
00033 try {
00034 DbEnv *env = new DbEnv(0);
00035 env->open(".", DB_CREATE | DB_INIT_LOG | DB_INIT_MPOOL, 0);
00036
00037
00038 Db *db1 = new Db(env, 0);
00039 db1->open(NULL, "first.db", NULL, DB_BTREE, DB_CREATE, 0);
00040 Dbt *key = new Dbt((char *)"a", 1);
00041 Dbt *data = new Dbt((char *)"b", 1);
00042 db1->put(NULL, key, data, 0);
00043 key->set_data((char *)"c");
00044 data->set_data((char *)"d");
00045 db1->put(NULL, key, data, 0);
00046 db1->close(0);
00047
00048 Db *db2 = new Db(env, 0);
00049 db2->open(NULL, "second.db", NULL, DB_BTREE, DB_CREATE, 0);
00050 key->set_data((char *)"w");
00051 data->set_data((char *)"x");
00052 db2->put(NULL, key, data, 0);
00053 key->set_data((char *)"y");
00054 data->set_data((char *)"z");
00055 db2->put(NULL, key, data, 0);
00056 db2->close(0);
00057
00058
00059 DbLogc *logc;
00060
00061 env->log_cursor(&logc, 0);
00062 int ret = 0;
00063 DbLsn lsn;
00064 Dbt *dbt = new Dbt();
00065 u_int32_t flags = DB_FIRST;
00066
00067 int count = 0;
00068 while ((ret = logc->get(&lsn, dbt, flags)) == 0) {
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 count++;
00081 flags = DB_NEXT;
00082 }
00083 if (ret != DB_NOTFOUND) {
00084 cerr << "*** FAIL: logc.get returned: "
00085 << DbEnv::strerror(ret) << "\n";
00086 }
00087 logc->close(0);
00088
00089
00090
00091
00092 if (count < 4)
00093 cerr << "*** FAIL: not enough log records\n";
00094
00095 cout << "TestLogc done.\n";
00096 }
00097 catch (DbException &dbe) {
00098 cerr << "*** FAIL: " << dbe.what() <<"\n";
00099 }
00100 return 0;
00101 }