本文整理汇总了C++中Db::err方法的典型用法代码示例。如果您正苦于以下问题:C++ Db::err方法的具体用法?C++ Db::err怎么用?C++ Db::err使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db
的用法示例。
在下文中一共展示了Db::err方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void BtRecExample::run()
{
db_recno_t recno;
int ret;
char buf[1024];
// Acquire a cursor for the database.
dbp->cursor(NULL, &dbcp, 0);
//
// Prompt the user for a record number, then retrieve and display
// that record.
//
for (;;) {
// Get a record number.
cout << "recno #> ";
cout.flush();
if (fgets(buf, sizeof(buf), stdin) == NULL)
break;
recno = atoi(buf);
//
// Start with a fresh key each time,
// the dbp->get() routine returns
// the key and data pair, not just the key!
//
Dbt key(&recno, sizeof(recno));
Dbt data;
if ((ret = dbcp->get(&key, &data, DB_SET_RECNO)) != 0) {
dbp->err(ret, "DBcursor->get");
throw DbException(ret);
}
// Display the key and data.
show("k/d\t", &key, &data);
// Move the cursor a record forward.
if ((ret = dbcp->get(&key, &data, DB_NEXT)) != 0) {
dbp->err(ret, "DBcursor->get");
throw DbException(ret);
}
// Display the key and data.
show("next\t", &key, &data);
//
// Retrieve the record number for the following record into
// local memory.
//
data.set_data(&recno);
data.set_size(sizeof(recno));
data.set_ulen(sizeof(recno));
data.set_flags(data.get_flags() | DB_DBT_USERMEM);
if ((ret = dbcp->get(&key, &data, DB_GET_RECNO)) != 0) {
if (ret != DB_NOTFOUND && ret != DB_KEYEMPTY) {
dbp->err(ret, "DBcursor->get");
throw DbException(ret);
}
}
else {
cout << "retrieved recno: " << (u_long)recno << "\n";
}
}
dbcp->close();
dbcp = NULL;
}
示例2: BulkHeaderGroupBody
bool BulkHeaderGroup::BulkHeaderGroupBody()
{
// belt and braces
key.set_data(keymem);
data.set_data(datamem);
if (m_cancel)
{
emit updateJob(JobList::BulkHeaderGroup, JobList::Cancelled, job->seq);
return false;
}
emit updateJob(JobList::BulkHeaderGroup, JobList::Running, job->seq);
NewsGroup* ng = job->ng;
Db* db = ng->getDb();
MultiPartHeader mph;
SinglePartHeader sph;
HeaderBase* hb = 0;
HeaderGroup* headerGroup = 0;
HeaderGroup* advancedHeaderGroup = 0;
// typedef QMap<QString, QString> HeaderGroupIndexes; // subj, headerGroup index
// typedef QMap<QString, HeaderGroup*> HeaderGroups; // headerGroup index, headerGroup *
HeaderGroupIndexes headerGroupIndexes;
HeaderGroups headerGroups;
DBC *dbcp = 0;
DBT ckey, cdata;
memset(&ckey, 0, sizeof(ckey));
memset(&cdata, 0, sizeof(cdata));
size_t retklen, retdlen;
void *retkey = 0, *retdata = 0;
int ret, t_ret;
void *p = 0;
quint64 count=0;
cdata.data = (void *) new char[HEADER_BULK_BUFFER_LENGTH];
cdata.ulen = HEADER_BULK_BUFFER_LENGTH;
cdata.flags = DB_DBT_USERMEM;
ckey.data = (void *) new char[HEADER_BULK_BUFFER_LENGTH];
ckey.ulen = HEADER_BULK_BUFFER_LENGTH;
ckey.flags = DB_DBT_USERMEM;
/* Acquire a cursor for the database. */
if ((ret = db->get_DB()->cursor(db->get_DB(), NULL, &dbcp, DB_CURSOR_BULK)) != 0)
{
db->err(ret, "DB->cursor");
char* ptr = 0;
ptr = (char*)(ckey.data);
Q_DELETE_ARRAY(ptr);
ptr = (char*)(cdata.data);
Q_DELETE_ARRAY(ptr);
return false;
}
// To save the group records
ng->articlesNeedDeleting(false);
// Store the data in the database - flush first ...
u_int32_t delCount;
uchar keymem[KEYMEM_SIZE];
uchar datamem[DATAMEM_SIZE];
Dbt key, data;
char* p2 = 0;
QByteArray ba;
const char *k = 0;
key.set_flags(DB_DBT_USERMEM);
key.set_data(&keymem);
key.set_ulen(KEYMEM_SIZE);
data.set_flags(DB_DBT_USERMEM);
data.set_ulen(DATAMEM_SIZE);
data.set_data(&datamem);
QString subj = "MDQuban", from = "MDQuban";
//QString rs1 = "^(.*)(\".*\")";
//QString rs2 = "^(.*)\\s-\\s(.*)$";
//QString rs3 = "^(\\S+.*)\\[.*\\].*(\".*\")";
//QString rs3 = "^(.*)\\s-\\s.*\\s-\\s(.*)$";
QRegExp rx[3];
bool rxPosBack[3];
bool noRegexpGrouping;
QString recKey, storeIndex;
QString prevSubj = "MDQuban", prevFrom = "MDQuban";
int pos;
//.........这里部分代码省略.........
示例3: 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;
}
示例4: doloop
int RepMgr::doloop()
{
Db *dbp;
Dbt key, data;
char buf[BUFSIZE], *rbuf;
int ret;
dbp = NULL;
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
ret = 0;
for (;;) {
if (dbp == NULL) {
dbp = new Db(&dbenv, 0);
try {
dbp->open(NULL, DATABASE, NULL, DB_BTREE,
DB_CREATE | DB_AUTO_COMMIT, 0);
} catch(DbException dbe) {
dbenv.err(ret, "DB->open");
throw dbe;
}
}
cout << "QUOTESERVER" ;
cout << "> " << flush;
if (fgets(buf, sizeof(buf), stdin) == NULL)
break;
if (strtok(&buf[0], " \t\n") == NULL) {
switch ((ret = print_stocks(dbp))) {
case 0:
continue;
default:
dbp->err(ret, "Error traversing data");
goto err;
}
}
rbuf = strtok(NULL, " \t\n");
if (rbuf == NULL || rbuf[0] == '\0') {
if (strncmp(buf, "exit", 4) == 0 ||
strncmp(buf, "quit", 4) == 0)
break;
dbenv.errx("Format: TICKER VALUE");
continue;
}
key.set_data(buf);
key.set_size((u_int32_t)strlen(buf));
data.set_data(rbuf);
data.set_size((u_int32_t)strlen(rbuf));
if ((ret = dbp->put(NULL, &key, &data, 0)) != 0)
{
dbp->err(ret, "DB->put");
if (ret != DB_KEYEXIST)
goto err;
}
}
err:
if (dbp != NULL)
(void)dbp->close(DB_NOSYNC);
return (ret);
}
示例5: doloop
int RepMgrGSG::doloop()
{
Dbt key, data;
Db *dbp;
char buf[BUFSIZE], *rbuf;
int ret;
dbp = 0;
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
ret = 0;
for (;;) {
if (dbp == 0) {
dbp = new Db(&dbenv, 0);
try {
dbp->open(NULL, DATABASE, NULL, DB_BTREE,
app_data.is_master ? DB_CREATE | DB_AUTO_COMMIT :
DB_AUTO_COMMIT, 0);
} catch(DbException dbe) {
// It is expected that this condition will be triggered
// when client sites start up. It can take a while for
// the master site to be found and synced, and no DB will
// be available until then.
if (dbe.get_errno() == ENOENT) {
cout << "No stock db available yet - retrying." << endl;
try {
dbp->close(0);
} catch (DbException dbe2) {
cout << "Unexpected error closing after failed" <<
" open, message: " << dbe2.what() << endl;
dbp = NULL;
goto err;
}
dbp = NULL;
sleep(SLEEPTIME);
continue;
} else {
dbenv.err(ret, "DB->open");
throw dbe;
}
}
}
cout << "QUOTESERVER" ;
if (!app_data.is_master)
cout << "(read-only)";
cout << "> " << flush;
if (fgets(buf, sizeof(buf), stdin) == NULL)
break;
if (strtok(&buf[0], " \t\n") == NULL) {
switch ((ret = print_stocks(dbp))) {
case 0:
continue;
case DB_REP_HANDLE_DEAD:
(void)dbp->close(DB_NOSYNC);
cout << "closing db handle due to rep handle dead" << endl;
dbp = NULL;
continue;
default:
dbp->err(ret, "Error traversing data");
goto err;
}
}
rbuf = strtok(NULL, " \t\n");
if (rbuf == NULL || rbuf[0] == '\0') {
if (strncmp(buf, "exit", 4) == 0 ||
strncmp(buf, "quit", 4) == 0)
break;
dbenv.errx("Format: TICKER VALUE");
continue;
}
if (!app_data.is_master) {
dbenv.errx("Can't update at client");
continue;
}
key.set_data(buf);
key.set_size((u_int32_t)strlen(buf));
data.set_data(rbuf);
data.set_size((u_int32_t)strlen(rbuf));
if ((ret = dbp->put(NULL, &key, &data, 0)) != 0)
{
dbp->err(ret, "DB->put");
if (ret != DB_KEYEXIST)
goto err;
}
}
err: if (dbp != 0) {
(void)dbp->close(DB_NOSYNC);
}
return (ret);
}