00001 #include "MyDb.hpp"
00002
00003
00004
00005
00006
00007 MyDb::MyDb(std::string &path, std::string &dbName,
00008 bool isSecondary)
00009 : db_(NULL, 0),
00010 dbFileName_(path + dbName),
00011 cFlags_(DB_CREATE)
00012
00013 {
00014 try
00015 {
00016
00017 db_.set_error_stream(&std::cerr);
00018
00019
00020
00021 if (isSecondary)
00022 db_.set_flags(DB_DUPSORT);
00023
00024
00025 db_.open(NULL, dbFileName_.c_str(), NULL, DB_BTREE, cFlags_, 0);
00026 }
00027
00028
00029 catch(DbException &e)
00030 {
00031 std::cerr << "Error opening database: " << dbFileName_ << "\n";
00032 std::cerr << e.what() << std::endl;
00033 }
00034 catch(std::exception &e)
00035 {
00036 std::cerr << "Error opening database: " << dbFileName_ << "\n";
00037 std::cerr << e.what() << std::endl;
00038 }
00039 }
00040
00041
00042
00043 void
00044 MyDb::close()
00045 {
00046
00047 try
00048 {
00049 db_.close(0);
00050 std::cout << "Database " << dbFileName_
00051 << " is closed." << std::endl;
00052 }
00053 catch(DbException &e)
00054 {
00055 std::cerr << "Error closing database: " << dbFileName_ << "\n";
00056 std::cerr << e.what() << std::endl;
00057 }
00058 catch(std::exception &e)
00059 {
00060 std::cerr << "Error closing database: " << dbFileName_ << "\n";
00061 std::cerr << e.what() << std::endl;
00062 }
00063 }