本文整理汇总了C++中DB类的典型用法代码示例。如果您正苦于以下问题:C++ DB类的具体用法?C++ DB怎么用?C++ DB使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: db3stat
static int db3stat(dbiIndex dbi, unsigned int flags)
{
DB * db = dbi->dbi_db;
#if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3)
DB_TXN * txnid = NULL;
#endif
int rc = 0;
assert(db != NULL);
#if defined(DB_FAST_STAT)
if (flags)
flags = DB_FAST_STAT;
else
#endif
flags = 0;
dbi->dbi_stats = _free(dbi->dbi_stats);
#if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3)
rc = db->stat(db, txnid, &dbi->dbi_stats, flags);
#else
rc = db->stat(db, &dbi->dbi_stats, flags);
#endif
rc = cvtdberr(dbi, "db->stat", rc, _debug);
return rc;
}
示例2: databaseRemove
static int
databaseRemove(const char* file,
const char* database,
int flags)
{
#ifdef TRACE_FUNC_CALLS
LOG_TRACE_IN;
#endif
DB* localDbHandle;
int ret;
// Removing the database file
db_create(&localDbHandle, NULL, 0);
ret = localDbHandle->remove(localDbHandle,
file,
database,
flags);
#ifdef TRACE_FUNC_CALLS
LOG_TRACE_OUT;
#endif
return ret;
}
示例3: ooMindMap_open
/* opening the MindMap Database */
static int
ooMindMap_open(struct ooMindMap *self, const char *dbpath)
{
int ret;
DB *dbp = self->_storage;
if (!dbp) return oo_FAIL;
/* open the database */
if ((ret = dbp->open(dbp, /* DB structure pointer */
NULL, /* Transaction pointer */
dbpath, /* On-disk file that holds the database. */
NULL, /* Optional logical database name */
DB_BTREE, /* Database access method */
DB_CREATE, /* Open flags */
0664)) /* File mode (using defaults) */
!= oo_OK) {
dbp->err(dbp, ret, "%s: open", dbpath);
(void)dbp->close(dbp, 0);
return oo_FAIL;
}
return 0;
}
示例4: rberkeley_db_compact
/* {{{ rberkeley_db_compact */
SEXP rberkeley_db_compact (SEXP _dbp, SEXP _txnid, SEXP _start,
SEXP _stop, SEXP _c_data, SEXP _flags)
{
DB *dbp;
DB_TXN *txnid;
DBT start, stop, end;
/*DB_COMPACT c_data;*/
u_int32_t flags;
int ret;
if(isNull(_txnid)) {
txnid = R_ExternalPtrAddr(_txnid);
} else {
txnid = NULL;
}
if(!isNull(_start)) {
memset(&start, 0, sizeof(DBT));
start.data = (unsigned char *)RAW(_start);
start.size = length(_start);
}
if(!isNull(_stop)) {
memset(&stop, 0, sizeof(DBT));
stop.data = (unsigned char *)RAW(_stop);
stop.size = length(_stop);
}
flags = (u_int32_t)INTEGER(_flags)[0];
/*memset(&end, 0, sizeof(end));*/
dbp = R_ExternalPtrAddr(_dbp);
if(R_ExternalPtrTag(_dbp) != RBerkeley_DB || dbp == NULL)
error("invalid 'db' handle");
ret = dbp->compact(dbp, txnid, &start, &stop, NULL, flags, &end);
return ScalarInteger(ret);
}
示例5: storage_get_max_iid
/*@
* Walk through the database and return the highest iid we have seen.
* If this is a RECNO database this can probably be done more cheaply
* but for now we will make this usable regardless of the index impl
*/
iid_t
storage_get_max_iid(struct storage * s)
{
int ret;
DB *dbp = s->db;
DBC *dbcp;
DBT key, data;
iid_t max_iid = 0;
/* Acquire a cursor for the database. */
if ((ret = dbp->cursor(dbp, NULL, &dbcp, 0)) != 0) {
dbp->err(dbp, ret, "DB->cursor");
return (1);
}
/* Re-initialize the key/data pair. */
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
/* Walk through the database and print out the key/data pairs. */
while ((ret = dbcp->c_get(dbcp, &key, &data, DB_NEXT)) == 0) {
assert(data.size = sizeof(iid_t));
max_iid = *(iid_t *)key.data;
}
if (ret != DB_NOTFOUND) {
dbp->err(dbp, ret, "DBcursor->get");
return 0;
}
/* Close the cursor. */
if ((ret = dbcp->c_close(dbcp)) != 0) {
dbp->err(dbp, ret, "DBcursor->close");
}
return (max_iid);
}
示例6: cleanup
static void cleanup(pam_handle_t *pamh, void *data, int err) {
DB* db;
if (NULL != data) {
abl_context *context = data;
log_debug(context->args, "In cleanup, err is %08x", err);
if (err && (err & PAM_DATA_REPLACE) == 0) {
log_debug(context->args, "record returned %d",record_attempt(context));
}
config_free(context->args);
free(context->args);
db = context->info->utdb;
db->close(db,0);
db = context->info->usdb;
db->close(db,0);
db = context->info->htdb;
db->close(db,0);
db = context->info->hsdb;
db->close(db,0);
free(context->info);
free(context);
}
}
示例7: main
int main() {
DB *db;
DB *uiddb;
int ret;
db_create(&db, NULL, 0);
db->open(db, NULL, NULL, "data", DB_BTREE, DB_CREATE, 0);
db_create(&uiddb, NULL, 0);
uiddb->open(uiddb, NULL, NULL, "byuid", DB_BTREE, DB_CREATE, 0);
ret = db->associate(db, NULL, uiddb, byuid_callback, 0);
printf("associate: %d\n", ret);
user_t u;
strcpy(u.user, "jls");
u.uid = 1000;
strcpy(u.path, "/home/jls");
DBT key, value;
memset(&key, 0, sizeof(DBT));
memset(&value, 0, sizeof(DBT));
key.data = u.user;
key.size = strlen(u.user);
value.data = &u;
value.size = sizeof(u);
ret = db->put(db, NULL, &key, &value, 0);
printf("put: %d\n", ret);
memset(&value, 0, sizeof(value));
ret = db->get(db, NULL, &key, &value, 0);
printf("put: %d\n", ret);
printf("Uid: %d\n", ((user_t*)value.data)->uid);
memset(&value, 0, sizeof(value));
int uid = 1000;
key.data = &uid;
key.size = sizeof(int);
uiddb->get(uiddb, NULL, &key, &value, 0);
printf("Secondary lookup: user=%s\n", ((user_t*)value.data)->user);
return 0;
}
示例8: map_db_get_entry
static char *
map_db_get_entry(void *hdl, char *key, size_t *len)
{
int ret;
DBT dbk;
DBT dbv;
DB *db = hdl;
char *result = NULL;
dbk.data = key;
dbk.size = strlen(dbk.data) + 1;
if ((ret = db->get(db, &dbk, &dbv, 0)) != 0)
return NULL;
result = calloc(dbv.size, 1);
if (result == NULL)
fatal("calloc");
(void)strlcpy(result, dbv.data, dbv.size);
*len = dbv.size;
return result;
}
示例9: userSearch
QString UtenteBasic::userSearch(DB &d) const
{
int contautenti=1;
QString risposta="";
for (std::map<QString,Utente*>::iterator it=d.begin(); it!=d.end(); ++it)
{
if (it->first==un.login)
continue;
if (rete->is_in(it->second->un.login))
{
risposta+="\n\nutente amico, puoi vedere il profilo intero anche se sei basic: "+it->second->un.login+ "\n"; contautenti++;
risposta+=it->second->info->visualizza();
risposta+=it->second->rete->get_rete();
}
else
{
risposta+="\n\nutente: "+QString::number(contautenti)+ "\n"; contautenti++;
risposta+=("Nome: " +(it->second->info->Nome)+"\n");
risposta+=("Cognome: "+(it->second->info->Cognome)+"\n");
}
}
if (risposta=="") return "Spiacente, nessun risultato :(";
return risposta;
}
示例10: rberkeley_db_set_msgfile
/* {{{ rberkeley_db_set_msgfile */
SEXP rberkeley_db_set_msgfile (SEXP _dbp, SEXP _msgfile)
{
DB *dbp;
FILE *msgfile = NULL;
dbp = R_ExternalPtrAddr(_dbp);
if(R_ExternalPtrTag(_dbp) != RBerkeley_DB || dbp == NULL)
error("invalid 'db' handle");
if(!isNull(_msgfile)) {
msgfile = fopen(CHAR(STRING_ELT(_msgfile,0)),"w");
if(msgfile == NULL)
error("open failed!\n");
} else msgfile = NULL;
dbp->set_msgfile(dbp, msgfile);
if(msgfile == NULL) {
return R_NilValue;
} else {
SEXP ptr = R_MakeExternalPtr(msgfile, install("msgfile"), ScalarLogical(TRUE));
R_RegisterCFinalizer(ptr, (R_CFinalizer_t) rberkeley_fclose);
return ptr;
}
}
示例11: put
int put (void **db, void *key, int key_len, void *value, int value_len) {
int ret;
DBT db_key, db_data;
DB *dbp = *db;
memset(&db_key, 0, sizeof(db_key));
memset(&db_data, 0, sizeof(db_data));
db_key.data = key;
db_key.size = key_len;
db_data.data = value;
db_data.size = value_len;
if ((ret = dbp->put(dbp, NULL, &db_key, &db_data, 0)) == 0)
printf("db: %s: key stored.\n", (char *)db_key.data);
else {
dbp->err(dbp, ret, "DB->put");
exit(1);
}
return ES_OK;
}
示例12: ctx_unlock
static krb5_error_code
ctx_unlock(krb5_context context, krb5_db2_context *dbc)
{
krb5_error_code retval;
DB *db;
retval = osa_adb_release_lock(dbc->policy_db);
if (retval)
return retval;
if (!dbc->db_locks_held) /* lock already unlocked */
return KRB5_KDB_NOTLOCKED;
db = dbc->db;
if (--(dbc->db_locks_held) == 0) {
db->close(db);
dbc->db = NULL;
dbc->db_lock_mode = 0;
retval = krb5_lock_file(context, dbc->db_lf_file,
KRB5_LOCKMODE_UNLOCK);
}
return retval;
}
示例13: main
int main() {
DB *dbp;
DB_ENV *dbenv;
DB_TXN *xid;
DBT key, data;
const unsigned int INSERT_NUM = 100;
char value[22]; /* should be log INSERT_NUM */
int ret, i, t_ret;
env_dir_create();
env_open(&dbenv);
if ((ret = db_create(&dbp, dbenv, 0)) != 0) {
fprintf(stderr, "db_create: %s\n", db_strerror(ret));
exit (1);
}
dbenv->txn_begin(dbenv, NULL, &xid, 0);
if ((ret = dbp->open(dbp,
xid, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
dbp->err(dbp, ret, "%s", DATABASE);
goto err;
}
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.size = sizeof(int);
key.data = malloc(sizeof(int));
data.data = value;
for( i = 0; i < INSERT_NUM; i++ ) {
*((int*)key.data) = i;
data.size = sizeof(char)*strlen(data.data);
sprintf(value, "value: %u\n", i);
dbp->put(dbp, xid, &key, &data, 0);
}
xid->commit(xid, 0);
dbenv->txn_begin(dbenv, NULL, &xid, 0);
for( i = 0; i < INSERT_NUM; i++ ) {
*((int*)key.data) = i;
dbp->get(dbp, xid, &key, &data, 0);
printf("db: %u: key retrieved: data was %s.\n", *((int*)key.data), (char *)data.data);
}
xid->abort(xid);
err: if ((t_ret = dbp->close(dbp, 0)) != 0 && ret == 0)
ret = t_ret;
return 0;
}
示例14: db3cget
static int db3cget(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
unsigned int flags)
{
DB * db = dbi->dbi_db;
int _printit;
int rc;
assert(db != NULL);
if (dbcursor == NULL) {
/* XXX duplicates require cursors. */
rc = db->get(db, dbi->dbi_txnid, key, data, 0);
/* XXX DB_NOTFOUND can be returned */
_printit = (rc == DB_NOTFOUND ? 0 : _debug);
rc = cvtdberr(dbi, "db->get", rc, _printit);
} else {
/* XXX db3 does DB_FIRST on uninitialized cursor */
rc = dbcursor->c_get(dbcursor, key, data, flags);
/* XXX DB_NOTFOUND can be returned */
_printit = (rc == DB_NOTFOUND ? 0 : _debug);
rc = cvtdberr(dbi, "dbcursor->c_get", rc, _printit);
}
return rc;
}
示例15: uriindex_delete
int uriindex_delete (char uri[], char subname[]) {
DB dbpArray;
DB *dbp = NULL;
DBT key;
int ret;
int forreturn = 1;
struct uriindexFormat uriindex;
if (!uriindex_open(&dbp,subname, DB_CREATE)) {
fprintf(stderr,"can't open uriindex\n");
return 0;
}
//resetter minne
memset(&key, 0, sizeof(DBT));
//legger inn datane i bdb strukturen
key.data = uri;
key.size = strlen(uri);
if ((ret = dbp->del(dbp, NULL, &key, 0)) == 0) {
forreturn = 1;
}
else {
dbp->err(dbp, ret, "DBcursor->get");
forreturn = 0;
}
uriindex_close(&dbp);
return forreturn;
}