本文整理汇总了C++中DBC类的典型用法代码示例。如果您正苦于以下问题:C++ DBC类的具体用法?C++ DBC怎么用?C++ DBC使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBC类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bdb_close
void
bdb_close(void)
{
DB *db;
DBC *dbc;
DB_ENV *dbenv;
dbc = g.dbc;
db = g.bdb;
dbenv = db->dbenv;
assert(dbc->close(dbc) == 0);
assert(db->close(db, 0) == 0);
assert(dbenv->close(dbenv, 0) == 0);
free(keybuf);
keybuf = NULL;
}
示例2: dup
int Dbc::dup(Dbc** cursorp, u_int32_t _flags)
{
int ret;
DBC *dbc = this;
DBC *new_cursor = 0;
ret = dbc->dup(dbc, &new_cursor, _flags);
if (DB_RETOK_STD(ret))
// The following cast implies that Dbc can be no larger than DBC
*cursorp = (Dbc*)new_cursor;
else
DB_ERROR(DbEnv::get_DbEnv(dbc->dbenv),
"Dbc::dup", ret, ON_ERROR_UNKNOWN);
return (ret);
}
示例3: bdb_last_id
int bdb_last_id( BackendDB *be, DB_TXN *tid )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
int rc;
ID id = 0;
unsigned char idbuf[sizeof(ID)];
DBT key, data;
DBC *cursor;
DBTzero( &key );
key.flags = DB_DBT_USERMEM;
key.data = (char *) idbuf;
key.ulen = sizeof( idbuf );
DBTzero( &data );
data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
/* Get a read cursor */
rc = bdb->bi_id2entry->bdi_db->cursor( bdb->bi_id2entry->bdi_db,
tid, &cursor, 0 );
if (rc == 0) {
rc = cursor->c_get(cursor, &key, &data, DB_LAST);
cursor->c_close(cursor);
}
switch(rc) {
case DB_NOTFOUND:
rc = 0;
break;
case 0:
BDB_DISK2ID( idbuf, &id );
break;
default:
Debug( LDAP_DEBUG_ANY,
"=> bdb_last_id: get failed: %s (%d)\n",
db_strerror(rc), rc, 0 );
goto done;
}
bdb->bi_lastid = id;
done:
return rc;
}
示例4: unlink
bool Bigram::save_db(const char * dbfile){
DB * tmp_db = NULL;
int ret = unlink(dbfile);
if ( ret != 0 && errno != ENOENT)
return false;
ret = db_create(&tmp_db, NULL, 0);
assert(ret == 0);
if (NULL == tmp_db)
return false;
ret = tmp_db->open(tmp_db, NULL, dbfile, NULL,
DB_HASH, DB_CREATE, 0600);
if ( ret != 0 )
return false;
DBC * cursorp = NULL;
DBT key, data;
/* Get a cursor */
m_db->cursor(m_db, NULL, &cursorp, 0);
if (NULL == cursorp)
return false;
/* Initialize our DBTs. */
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
/* Iterate over the database, retrieving each record in turn. */
while ((ret = cursorp->c_get(cursorp, &key, &data, DB_NEXT)) == 0) {
int ret = tmp_db->put(tmp_db, NULL, &key, &data, 0);
assert(ret == 0);
}
assert (ret == DB_NOTFOUND);
/* Cursors must be closed */
if ( cursorp != NULL )
cursorp->c_close(cursorp);
if ( tmp_db != NULL )
tmp_db->close(tmp_db, 0);
return true;
}
示例5: ooMindMap_keys
static int
ooMindMap_keys(struct ooMindMap *self,
mindmap_size_t **ids,
mindmap_size_t batch_size,
mindmap_size_t batch_start)
{ DBT key, data;
DB *dbp;
DBC *dbcp;
int ret;
dbp = self->_storage;
/* initialize the key/data pair */
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
/* acquire a cursor for the database */
if ((ret = dbp->cursor(dbp, NULL, &dbcp, 0)) != 0) {
dbp->err(dbp, ret, "DB->cursor");
goto error;
}
/* TODO: batching */
/* walk through the database and print out the key/data pairs. */
while ((ret = dbcp->c_get(dbcp, &key, &data, DB_NEXT)) == 0)
printf("%.*s : %.*s\n",
(int)key.size, (char *)key.data,
(int)data.size, (char *)data.data);
if (ret != DB_NOTFOUND)
{ dbp->err(dbp, ret, "DBcursor->get");
goto error;
}
/* close everything down */
if ((ret = dbcp->c_close(dbcp)) != 0) {
dbp->err(dbp, ret, "DBcursor->close");
goto error;
}
return oo_OK;
error:
(void)dbp->close(dbp, 0);
return oo_FAIL;
}
示例6: put
int Dbc::put(Dbt* key, Dbt *data, u_int32_t flags_arg)
{
DBC *cursor = this;
int err;
if ((err = cursor->c_put(cursor, key, data, flags_arg)) != 0) {
// DB_KEYEXIST is a "normal" return, so should not be
// thrown as an error
//
if (err != DB_KEYEXIST) {
DB_ERROR("Db::put", err, ON_ERROR_UNKNOWN);
return (err);
}
}
return (err);
}
示例7: get
int Dbc::get(Dbt* key, Dbt *data, u_int32_t flags_arg)
{
DBC *cursor = this;
int err;
if ((err = cursor->c_get(cursor, key, data, flags_arg)) != 0) {
// DB_NOTFOUND and DB_KEYEMPTY are "normal" returns,
// so should not be thrown as an error
//
if (err != DB_NOTFOUND && err != DB_KEYEMPTY) {
DB_ERROR("Db::get", err, ON_ERROR_UNKNOWN);
return (err);
}
}
return (err);
}
示例8: del
int Dbc::del(u_int32_t flags_arg)
{
DBC *cursor = this;
int err;
if ((err = cursor->c_del(cursor, flags_arg)) != 0) {
// DB_KEYEMPTY is a "normal" return, so should not be
// thrown as an error
//
if (err != DB_KEYEMPTY) {
DB_ERROR("Db::del", err, ON_ERROR_UNKNOWN);
return (err);
}
}
return (err);
}
示例9: count_records
int
count_records(DB *dbp, DB_TXN *txn)
{
DBT key, data;
DBC *cursorp;
int count, ret;
cursorp = NULL;
count = 0;
/* Get the cursor */
ret = dbp->cursor(dbp, txn, &cursorp, DB_READ_UNCOMMITTED);
if (ret != 0) {
dbp->err(dbp, ret, "count_records: cursor open failed.");
goto cursor_err;
}
/* Get the key DBT used for the database read */
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
do {
ret = cursorp->get(cursorp, &key, &data, DB_NEXT);
switch (ret) {
case 0:
count++;
break;
case DB_NOTFOUND:
break;
default:
dbp->err(dbp, ret, "Count records unspecified error");
goto cursor_err;
}
} while (ret == 0);
cursor_err:
if (cursorp != NULL) {
ret = cursorp->close(cursorp);
if (ret != 0) {
dbp->err(dbp, ret,
"count_records: cursor close failed.");
}
}
return (count);
}
示例10: dbiCursorPut
static int dbiCursorPut(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags)
{
int rc = EINVAL;
int sane = (key->data != NULL && key->size > 0 &&
data->data != NULL && data->size > 0);
if (dbc && sane) {
DBC * cursor = dbc->cursor;
rpmdb rdb = dbc->dbi->dbi_rpmdb;
rpmswEnter(&rdb->db_putops, (ssize_t) 0);
rc = cursor->c_put(cursor, key, data, DB_KEYLAST);
rc = cvtdberr(dbc->dbi, "dbcursor->c_put", rc, _debug);
rpmswExit(&rdb->db_putops, (ssize_t) data->size);
}
return rc;
}
示例11: get
int Dbc::get(Dbt* key, Dbt *data, u_int32_t _flags)
{
int ret;
DBC *dbc = this;
ret = dbc->c_get(dbc, key, data, _flags);
if (!DB_RETOK_DBCGET(ret)) {
if (ret == ENOMEM && DB_OVERFLOWED_DBT(key))
DB_ERROR_DBT("Dbc::get", key, ON_ERROR_UNKNOWN);
else if (ret == ENOMEM && DB_OVERFLOWED_DBT(data))
DB_ERROR_DBT("Dbc::get", data, ON_ERROR_UNKNOWN);
else
DB_ERROR("Dbc::get", ret, ON_ERROR_UNKNOWN);
}
return (ret);
}
示例12: setCursor
/*
* Sets a cursor.
*
* Arguments:
* cursor Pointer to the cursor. Shall not be NULL.
* mode The mode for setting the cursor. One of DB_SET_RANGE
* or DB_NEXT.
* Returns:
* 0 Success. "*cursor" is set.
* ENOENT No such entry.
* EIO Backend database error. "log_start()" called.
*/
static RegStatus setCursor(
Cursor* const cursor,
int mode)
{
DBC* dbCursor = cursor->dbCursor;
DBT* keyDbt = &cursor->key;
DBT* valueDbt = &cursor->value;
int status = dbCursor->get(dbCursor, keyDbt, valueDbt, mode);
if (DB_NOTFOUND == status) {
status = ENOENT;
}
else if (0 != status) {
status = EIO;
}
return status;
}
示例13: outFile
void DBBase::dump (QString &d)
{
QFile outFile(d);
if (! outFile.open(QIODevice::WriteOnly))
return;
Q3TextStream outStream(&outFile);
DBT key, data;
DBC *cur;
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
db->cursor(db, NULL, &cur, 0);
while (! cur->c_get(cur, &key, &data, DB_NEXT))
outStream << (char *) key.data << "=" << (char *) data.data << "\n";
cur->c_close(cur);
outFile.close();
}
示例14: mail_cache_db_get_keys
int mail_cache_db_get_keys(struct mail_cache_db * cache_db,
chash * keys)
{
DB * dbp;
int r;
DBC * dbcp;
DBT db_key;
DBT db_data;
dbp = cache_db->internal_database;
r = dbp->cursor(dbp, NULL, &dbcp, 0);
if (r != 0)
return -1;
memset(&db_key, 0, sizeof(db_key));
memset(&db_data, 0, sizeof(db_data));
while (1) {
chashdatum hash_key;
chashdatum hash_data;
r = dbcp->c_get(dbcp, &db_key, &db_data, DB_NEXT);
if (r != 0)
break;
hash_key.data = db_key.data;
hash_key.len = db_key.size;
hash_data.data = NULL;
hash_data.len = 0;
r = chash_set(keys, &hash_key, &hash_data, NULL);
if (r < 0) {
return -1;
}
}
r = dbcp->c_close(dbcp);
if (r != 0)
return -1;
return 0;
}
示例15: pget
int Dbc::pget(Dbt* key, Dbt *pkey, Dbt *data, u_int32_t _flags)
{
int ret;
DBC *dbc = this;
ret = dbc->c_pget(dbc, key, pkey, data, _flags);
/* Logic is the same as for Dbc::get - reusing macro. */
if (!DB_RETOK_DBCGET(ret)) {
if (ret == ENOMEM && DB_OVERFLOWED_DBT(key))
DB_ERROR_DBT("Dbc::pget", key, ON_ERROR_UNKNOWN);
else if (ret == ENOMEM && DB_OVERFLOWED_DBT(data))
DB_ERROR_DBT("Dbc::pget", data, ON_ERROR_UNKNOWN);
else
DB_ERROR("Dbc::pget", ret, ON_ERROR_UNKNOWN);
}
return (ret);
}