mydb.cpp
来自「linux 下的源代码分析阅读器 red hat公司新版」· C++ 代码 · 共 64 行
CPP
64 行
#include "MyDb.hpp"// File: MyDb.cpp// Class constructor. Requires a path to the location// where the database is located, and a database nameMyDb::MyDb(std::string &path, std::string &dbName, bool isSecondary) : db_(NULL, 0), // Instantiate Db object dbFileName_(path + dbName), // Database file name cFlags_(DB_CREATE) // If the database doesn't yet exist, // allow it to be created.{ try { // Redirect debugging information to std::cerr db_.set_error_stream(&std::cerr); // If this is a secondary database, support // sorted duplicates if (isSecondary) db_.set_flags(DB_DUPSORT); // Open the database db_.open(NULL, dbFileName_.c_str(), NULL, DB_BTREE, cFlags_, 0); } // DbException is not a subclass of std::exception, so we // need to catch them both. catch(DbException &e) { std::cerr << "Error opening database: " << dbFileName_ << "\n"; std::cerr << e.what() << std::endl; } catch(std::exception &e) { std::cerr << "Error opening database: " << dbFileName_ << "\n"; std::cerr << e.what() << std::endl; }}// Private member used to close a database. Called from the class// destructor.voidMyDb::close(){ // Close the db try { db_.close(0); std::cout << "Database " << dbFileName_ << " is closed." << std::endl; } catch(DbException &e) { std::cerr << "Error closing database: " << dbFileName_ << "\n"; std::cerr << e.what() << std::endl; } catch(std::exception &e) { std::cerr << "Error closing database: " << dbFileName_ << "\n"; std::cerr << e.what() << std::endl; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?