⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mydb.cpp

📁 linux 下的源代码分析阅读器 red hat公司新版
💻 CPP
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -