本文整理汇总了C++中Db::errx方法的典型用法代码示例。如果您正苦于以下问题:C++ Db::errx方法的具体用法?C++ Db::errx怎么用?C++ Db::errx使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db
的用法示例。
在下文中一共展示了Db::errx方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
u_int32_t env_flags = DB_CREATE | // If the environment does not exist, create it.
DB_INIT_MPOOL; // Initialize the in-memory cache.
//std::string envHome("./");
std::string envHome("/home/kirill");
u_int32_t db_flags = DB_RDONLY; // only read
std::string dbName("X-po2s.db");
//std::string dbName("X-so2p.db");
//std::string dbName("X-sp2o.db");
DbEnv myEnv(0);
Db *myDb; // Instantiate the Db object
Dbc *cursorp; // cursor
try
{
cout << "X-po2s.db output:" << endl;
myEnv.open(envHome.c_str(), env_flags, 0);
myDb = new Db(&myEnv, 0);
myDb->open(NULL, dbName.c_str(), NULL, DB_BTREE, db_flags, 0);
// Get a cursor
myDb->cursor(NULL, &cursorp, 0);
Dbt key, data;
// Position the cursor to the first record in the database whose
// key and data begin with the correct strings.
int ret = cursorp->get(&key, &data, DB_NEXT);
while (ret != DB_NOTFOUND)
{
cout << "..." << endl;
std::cout << "key: " << (char *)key.get_data()
<< "data: " << (char *)data.get_data()<< std::endl;
ret = cursorp->get(&key, &data, DB_NEXT);
}
// Cursors must be closed
if (cursorp != NULL)
cursorp->close();
if (myDb != NULL) {
myDb->close(0);
}
myEnv.close(0);
cout << "Closing ..." << endl;
}
// Must catch both DbException and std::exception
catch(DbException &e)
{
myDb->err(e.get_errno(), "Database open failed %s", dbName.c_str());
throw e;
}
catch(std::exception &e)
{
// No DB error number available, so use errx
myDb->errx("Error opening database: %s", e.what());
throw e;
}
return 0;
}