本文整理汇总了C++中DB::seq方法的典型用法代码示例。如果您正苦于以下问题:C++ DB::seq方法的具体用法?C++ DB::seq怎么用?C++ DB::seq使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB
的用法示例。
在下文中一共展示了DB::seq方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mail_cache_db_clean_up
int mail_cache_db_clean_up(struct mail_cache_db * cache_db,
chash * exist)
{
DB * dbp;
int r;
DBT db_key;
DBT db_data;
dbp = cache_db->internal_database;
r = dbp->seq(dbp, &db_key, &db_data, R_FIRST);
if (r == -1)
return -1;
while (r == 0) {
chashdatum hash_key;
chashdatum hash_data;
hash_key.data = db_key.data;
hash_key.len = db_key.size;
r = chash_get(exist, &hash_key, &hash_data);
if (r < 0) {
r = dbp->del(dbp, &db_key, 0);
if (r != 0)
return -1;
}
r = dbp->seq(dbp, &db_key, &db_data, R_NEXT);
if (r < 0)
return -1;
}
return 0;
}
示例2: mail_cache_db_get_keys
int mail_cache_db_get_keys(struct mail_cache_db * cache_db,
chash * keys)
{
DB * dbp;
int r;
DBT db_key;
DBT db_data;
dbp = cache_db->internal_database;
r = dbp->seq(dbp, &db_key, &db_data, R_FIRST);
if (r == -1)
return -1;
while (r == 0) {
chashdatum hash_key;
chashdatum hash_data;
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 = dbp->seq(dbp, &db_key, &db_data, R_NEXT);
if (r < 0)
return -1;
}
return 0;
}
示例3: int
static int
map_db_compare(void *hdl, char *key, enum map_kind kind,
int (*func)(char *, char *))
{
int ret = 0;
DB *db = hdl;
DBT dbk;
DBT dbd;
int r;
char *buf = NULL;
for (r = db->seq(db, &dbk, &dbd, R_FIRST); !r;
r = db->seq(db, &dbk, &dbd, R_NEXT)) {
buf = calloc(dbk.size+1, 1);
if (buf == NULL)
fatalx("calloc");
strlcpy(buf, dbk.data, dbk.size+1);
log_debug("key: %s, buf: %s", key, buf);
if (func(key, buf))
ret = 1;
free(buf);
if (ret)
break;
}
return ret;
}
示例4: while
static krb5_error_code
ctx_iterate(krb5_context context, krb5_db2_context *dbc,
krb5_error_code (*func)(krb5_pointer, krb5_db_entry *),
krb5_pointer func_arg)
{
DB *db;
DBT key, contents;
krb5_data contdata;
krb5_db_entry *entry;
krb5_error_code retval, retval2;
int dbret;
retval = ctx_lock(context, dbc, KRB5_LOCKMODE_SHARED);
if (retval)
return retval;
db = dbc->db;
dbret = db->seq(db, &key, &contents, R_FIRST);
while (dbret == 0) {
contdata.data = contents.data;
contdata.length = contents.size;
retval = krb5_decode_princ_entry(context, &contdata, &entry);
if (retval)
break;
retval = k5_mutex_unlock(krb5_db2_mutex);
if (retval)
break;
retval = (*func)(func_arg, entry);
krb5_dbe_free(context, entry);
retval2 = k5_mutex_lock(krb5_db2_mutex);
/* Note: If re-locking fails, the wrapper in db2_exp.c will
still try to unlock it again. That would be a bug. Fix
when integrating the locking better. */
if (retval)
break;
if (retval2) {
retval = retval2;
break;
}
dbret = db->seq(db, &key, &contents, R_NEXT);
}
switch (dbret) {
case 1:
case 0:
break;
case -1:
default:
retval = errno;
}
(void) ctx_unlock(context, dbc);
return retval;
}
示例5:
/* Get initial entry. */
static int
curs_start(iter_curs *curs)
{
DB *db = curs->dbc->db;
return db->seq(db, &curs->key, &curs->data, curs->startflag);
}
示例6: dbopen
int
next_rule()
{
DB *db;
DBT dbt;
DBT key;
int i = 0;
db = dbopen(RULESCRIPT, O_CREAT | O_RDWR, 0600, DB_BTREE, NULL);
while (db->seq(db, &key, &dbt, R_NEXT)== 0){
i += 1;
}
db->close(db);
return i;
}
示例7: dict_db_sequence
static int dict_db_sequence(DICT *dict, int function,
const char **key, const char **value)
{
const char *myname = "dict_db_sequence";
DICT_DB *dict_db = (DICT_DB *) dict;
DB *db = dict_db->db;
DBT db_key;
DBT db_value;
int status = 0;
int db_function;
dict->error = 0;
#if DB_VERSION_MAJOR > 1
/*
* Initialize.
*/
memset(&db_key, 0, sizeof(db_key));
memset(&db_value, 0, sizeof(db_value));
/*
* Determine the function.
*/
switch (function) {
case DICT_SEQ_FUN_FIRST:
if (dict_db->cursor == 0)
DICT_DB_CURSOR(db, &(dict_db->cursor));
db_function = DB_FIRST;
break;
case DICT_SEQ_FUN_NEXT:
if (dict_db->cursor == 0)
msg_panic("%s: no cursor", myname);
db_function = DB_NEXT;
break;
default:
msg_panic("%s: invalid function %d", myname, function);
}
/*
* Acquire a shared lock.
*/
if ((dict->flags & DICT_FLAG_LOCK)
&& myflock(dict->lock_fd, INTERNAL_LOCK, MYFLOCK_OP_SHARED) < 0)
msg_fatal("%s: lock dictionary: %m", dict_db->dict.name);
/*
* Database lookup.
*/
status =
dict_db->cursor->c_get(dict_db->cursor, &db_key, &db_value, db_function);
if (status != 0 && status != DB_NOTFOUND)
msg_fatal("error [%d] seeking %s: %m", status, dict_db->dict.name);
/*
* Release the shared lock.
*/
if ((dict->flags & DICT_FLAG_LOCK)
&& myflock(dict->lock_fd, INTERNAL_LOCK, MYFLOCK_OP_NONE) < 0)
msg_fatal("%s: unlock dictionary: %m", dict_db->dict.name);
if (status == 0) {
/*
* Copy the result so it is guaranteed null terminated.
*/
*key = SCOPY(dict_db->key_buf, db_key.data, db_key.size);
*value = SCOPY(dict_db->val_buf, db_value.data, db_value.size);
}
return (status);
#else
/*
* determine the function
*/
switch (function) {
case DICT_SEQ_FUN_FIRST:
db_function = R_FIRST;
break;
case DICT_SEQ_FUN_NEXT:
db_function = R_NEXT;
break;
default:
msg_panic("%s: invalid function %d", myname, function);
}
/*
* Acquire a shared lock.
*/
if ((dict->flags & DICT_FLAG_LOCK)
&& myflock(dict->lock_fd, INTERNAL_LOCK, MYFLOCK_OP_SHARED) < 0)
msg_fatal("%s: lock dictionary: %m", dict_db->dict.name);
if ((status = db->seq(db, &db_key, &db_value, db_function)) < 0)
msg_fatal("error seeking %s: %m", dict_db->dict.name);
/*
* Release the shared lock.
*/
if ((dict->flags & DICT_FLAG_LOCK)
//.........这里部分代码省略.........
示例8: memset
/**
* librdf_hash_bdb_cursor_get - Retrieve a hash value for the given key
* @context: BerkeleyDB hash cursor context
* @key: pointer to key to use
* @value: pointer to value to use
* @flags: flags
*
* Return value: non 0 on failure
**/
static int
librdf_hash_bdb_cursor_get(void* context,
librdf_hash_datum *key, librdf_hash_datum *value,
unsigned int flags)
{
librdf_hash_bdb_cursor_context *cursor=(librdf_hash_bdb_cursor_context*)context;
#ifdef HAVE_BDB_CURSOR
DBC *bdb_cursor=cursor->cursor;
#else
/* For BDB V1 */
DB* db;
#endif
DBT bdb_key;
DBT bdb_value;
int ret;
/* docs say you must zero DBT's before use */
memset(&bdb_key, 0, sizeof(DBT));
memset(&bdb_value, 0, sizeof(DBT));
/* Always initialise BDB version of key */
bdb_key.data = (char*)key->data;
bdb_key.size = key->size;
#ifdef DB_DBT_MALLOC
/* BDB V2 or later? */
bdb_key.flags=DB_DBT_MALLOC; /* Return in malloc() allocated memory */
bdb_value.flags=DB_DBT_MALLOC;
#endif
#ifndef HAVE_BDB_CURSOR
/* For BDB V1 */
db=cursor->hash->db;
#endif
switch(flags) {
case LIBRDF_HASH_CURSOR_SET:
#ifdef HAVE_BDB_CURSOR
/* V2/V3 prototype:
* int DBcursor->c_get(DBC *cursor, DBT *key, DBT *data, u_int32_t flags);
*/
ret=bdb_cursor->c_get(bdb_cursor, &bdb_key, &bdb_value, DB_SET);
#else
/* V1 */
ret=db->seq(db, &bdb_key, &bdb_value, 0);
#endif
break;
case LIBRDF_HASH_CURSOR_FIRST:
#ifdef HAVE_BDB_CURSOR
/* V2/V3 prototype:
* int DBcursor->c_get(DBC *cursor, DBT *key, DBT *data, u_int32_t flags);
*/
ret=bdb_cursor->c_get(bdb_cursor, &bdb_key, &bdb_value, DB_FIRST);
#else
/* V1 */
ret=db->seq(db, &bdb_key, &bdb_value, R_FIRST);
#endif
break;
case LIBRDF_HASH_CURSOR_NEXT_VALUE:
#ifdef HAVE_BDB_CURSOR
/* V2/V3 */
ret=bdb_cursor->c_get(bdb_cursor, &bdb_key, &bdb_value, DB_NEXT);
#else
/* V1 */
ret=db->seq(db, &bdb_key, &bdb_value, R_NEXT);
#endif
/* If succeeded and key has changed, end */
if(!ret && cursor->last_key &&
memcmp(cursor->last_key, bdb_key.data, bdb_key.size)) {
/* always allocated by BDB using system malloc */
SYSTEM_FREE(bdb_key.data);
SYSTEM_FREE(bdb_value.data);
#ifdef DB_NOTFOUND
/* V2 and V3 */
ret=DB_NOTFOUND;
#else
ret=1;
#endif
}
break;
case LIBRDF_HASH_CURSOR_NEXT:
#ifdef HAVE_BDB_CURSOR
#ifdef DB_NEXT_NODUP
//.........这里部分代码省略.........
示例9: dbopen
int
main(void)
{
HASHINFO info;
DB *db;
DBT key, value, returned;
int *data;
int n, i;
info.bsize = 512;
info.cachesize = 500;
info.lorder = 0;
info.ffactor = 4;
info.nelem = 0;
info.hash = NULL;
db = dbopen("big2.db", O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0664, DB_HASH, &info);
data = malloc(800 * sizeof(int));
for (n = 0; n < 800; n++)
data[n] = 0xDEADBEEF;
key.size = sizeof(int);
key.data = &n;
value.size = 800 * sizeof(int);
value.data = (void *)data;
for (n = 0; n < 200000; n++) {
returned.data = NULL;
if (n == 4627)
printf("");
if (n % 50 == 0)
printf("put n = %d\n", n);
if (db->put(db, &key, &value, 0) != 0)
printf("put error, n = %d\n", n);
if (db->get(db, &key, &returned, 0) != 0)
printf("Immediate get error, n = %d\n", n);
assert (returned.size == 3200);
for (i = 0; i < 800; i++)
if (((int *)returned.data)[i] != 0xDEADBEEF)
printf("ERRORRRRRR!!!\n");
}
for (n = 0; n < 200000; n++) {
if (n % 50 == 0)
printf("seq n = %d\n", n);
if ((db->seq(db, &key, &returned, 0)) != 0)
printf("Seq error, n = %d\n", n);
assert(returned.size == 3200);
for (i = 0; i < 800; i++)
if (((int *)returned.data)[i] != 0xDEADBEEF)
printf("ERRORRRRRR!!! seq %d\n", n);
}
for (n = 0; n < 2000; n++) {
if (n % 50 == 0)
printf("get n = %d\n", n);
if (db->get(db, &key, &returned, 0) != 0)
printf("Late get error, n = %d\n", n);
assert(returned.size == 1200);
for (i = 0; i < 300; i++)
if (((int *)returned.data)[i] != 0xDEADBEEF)
printf("ERRORRRRRR!!!, get %d\n", n);
}
db->close(db);
free(value.data);
return(0);
}
示例10: vsdb_glob
vsdb_ret_t vsdb_glob(vsdb_t vsdb, const char *glob, size_t glob_length,
const char ***keys, size_t **key_lengths,
const void ***values, size_t **value_sizes,
size_t *count)
{
DB *db;
DBT kt, dt;
vsdb_ret_t vsdb_ret;
int ret;
size_t i;
struct {
DBT *kts, *dts;
size_t count;
size_t capacity;
} buf;
vsdb_ret = vsdb_okay;
bzero(&buf, sizeof(buf));
lockdb(vsdb);
if ((db = getdb(vsdb)) == NULL)
goto failed;
if (glob == NULL)
goto failed;
if (glob_length == SIZE_T_MAX)
glob_length = strlen(glob);
if (glob_length == 0)
goto failed;
if (keys == NULL || key_lengths == NULL || values == NULL || value_sizes == NULL)
goto failed;
if (count == NULL)
goto failed;
if (glob_length == 1 && glob[0] == '*') {
if ((ret = db->seq(db, &kt, &dt, R_FIRST)) < 0) {
goto failed;
}
else if (ret == 0) {
do {
if (buf.count == buf.capacity) {
if (buf.capacity == 0) {
buf.capacity = 16;
buf.kts = (DBT *)malloc(sizeof(DBT) * buf.capacity);
buf.dts = (DBT *)malloc(sizeof(DBT) * buf.capacity);
}
else {
buf.capacity <<= 1;
buf.kts = (DBT *)realloc(buf.kts, sizeof(DBT) * buf.capacity);
buf.dts = (DBT *)realloc(buf.dts, sizeof(DBT) * buf.capacity);
}
}
dup_dbt(&buf.kts[buf.count], &kt);
dup_dbt(&buf.dts[buf.count], &dt);
buf.count++;
} while ((ret = db->seq(db, &kt, &dt, R_NEXT)) == 0);
if (ret < 0) {
goto failed;
}
}
}
else if (glob_length > 0 && glob[glob_length - 1] == '*') {
kt.data = (void *)glob;
kt.size = glob_length - 1;
if ((ret = db->seq(db, &kt, &dt, R_CURSOR)) < 0) {
goto failed;
}
else if (ret == 0) {
do {
if (buf.count == buf.capacity) {
if (buf.capacity == 0) {
buf.capacity = 16;
buf.kts = (DBT *)malloc(sizeof(DBT) * buf.capacity);
buf.dts = (DBT *)malloc(sizeof(DBT) * buf.capacity);
}
else {
buf.capacity <<= 1;
buf.kts = (DBT *)realloc(buf.kts, sizeof(DBT) * buf.capacity);
buf.dts = (DBT *)realloc(buf.dts, sizeof(DBT) * buf.capacity);
}
}
if (strncmp((const char *)kt.data, glob, ((glob_length - 1) < kt.size) ? (glob_length - 1) : kt.size) != 0) {
break;
}
dup_dbt(&buf.kts[buf.count], &kt);
dup_dbt(&buf.dts[buf.count], &dt);
buf.count++;
} while ((ret = db->seq(db, &kt, &dt, R_NEXT)) == 0);
if (ret < 0) {
goto failed;
}
}
}
else {
goto failed;
//.........这里部分代码省略.........
示例11: pam_cc_db_seq
int pam_cc_db_seq(void *_db, void **cookie,
const char **key_p, size_t *keylength_p,
const char **data_p, size_t *datalength_p)
{
DB *db = (DB *)_db;
DBT key;
DBT val;
int rc;
#if DB_VERSION_MAJOR >= 2
DBC *cursor = (DBC *)*cookie;
int first = 0;
#endif
memset(&key, 0, sizeof(key));
memset(&val, 0, sizeof(val));
#if DB_VERSION_MAJOR < 2
rc = db->seq(db, &key, &val, (*cookie == NULL ? R_FIRST : R_NEXT));
if (*cookie == NULL) {
*cookie = (void *)1;
}
#else
if (cursor == NULL) {
# if DB_VERSION_MAJOR > 2 || (DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR > 5)
rc = db->cursor(db, NULL, &cursor, 0);
# else
rc = db->cursor(db, NULL, &cursor);
# endif
if (rc != 0) {
errno = rc;
return PAM_SERVICE_ERR;
}
*cookie = cursor;
first++;
}
rc = cursor->c_get(cursor, &key, &val,
first ? DB_FIRST : DB_NEXT);
#endif /* DB_VERSION_MAJOR <= 2 */
switch (rc) {
case DB_NOTFOUND:
rc = PAM_SUCCESS;
break;
case 0:
rc = PAM_INCOMPLETE;
break;
default:
errno = rc;
rc = PAM_SERVICE_ERR;
return rc;
break;
}
*key_p = key.data;
*keylength_p = key.size;
*data_p = val.data;
*datalength_p = val.size;
return rc;
}