本文整理汇总了C++中DBC::c_get方法的典型用法代码示例。如果您正苦于以下问题:C++ DBC::c_get方法的具体用法?C++ DBC::c_get怎么用?C++ DBC::c_get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBC
的用法示例。
在下文中一共展示了DBC::c_get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNextBar
void DbPlugin::getNextBar (QDateTime &startDate, Bar &bar)
{
DBT key, data;
DBC *cur;
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
DBBar dbbar;
memset(&dbbar, 0, sizeof(DBBar));
data.data = &dbbar;
data.ulen = sizeof(DBBar);
data.flags = DB_DBT_USERMEM;
db->cursor(db, NULL, &cur, 0);
QString s = startDate.toString("yyyyMMddhhmmss");
key.data = (char *) s.latin1();
key.size = s.length() + 1;
cur->c_get(cur, &key, &data, DB_SET_RANGE);
int ret = cur->c_get(cur, &key, &data, DB_NEXT);
if (ret)
{
// char *err = db_strerror(ret);
// qDebug("%s %s", s.latin1(), err);
cur->c_close(cur);
return;
}
s = (char *) key.data;
getBar(dbbar, s, bar);
cur->c_close(cur);
}
示例2: sizeof
/**
* e_dbhash_foreach_key:
* @edbh: an #EDbHash
* @func: a callback function
* @user_data: data to pass to @func
*
* Calls @func for each database object.
**/
void
e_dbhash_foreach_key (EDbHash *edbh,
EDbHashFunc func,
gpointer user_data)
{
DB *db;
DBT dkey;
DBT ddata;
DBC *dbc;
gint db_error = 0;
g_return_if_fail (edbh != NULL);
g_return_if_fail (edbh->priv != NULL);
g_return_if_fail (func != NULL);
db = edbh->priv->db;
db_error = db->cursor (db, NULL, &dbc, 0);
if (db_error != 0) {
return;
}
memset (&dkey, 0, sizeof (DBT));
memset (&ddata, 0, sizeof (DBT));
db_error = dbc->c_get (dbc, &dkey, &ddata, DB_FIRST);
while (db_error == 0) {
(*func) ((const gchar *) dkey.data, user_data);
db_error = dbc->c_get (dbc, &dkey, &ddata, DB_NEXT);
}
dbc->c_close (dbc);
}
示例3: ftfs_bstore_scan_one_page
int ftfs_bstore_scan_one_page(DB *data_db, struct ftfs_meta_key *meta_key,
DB_TXN *txn, struct page *page)
{
int ret;
uint64_t block_num;
size_t block_offset;
loff_t offset;
size_t len;
struct ftfs_data_key *data_key;
void *buf, *value_buf;
DBT key_dbt, value_dbt;
DBC *cursor;
offset = page_offset(page);
block_num = block_get_num_by_position(offset);
data_key = kmalloc(DATA_KEY_MAX_LEN, GFP_KERNEL);
if (!data_key)
return -ENOMEM;
value_buf = kmalloc(FTFS_BSTORE_BLOCKSIZE, GFP_KERNEL);
if (!value_buf) {
ret = -ENOMEM;
goto out1;
}
copy_data_key_from_meta_key(data_key, meta_key, block_num);
dbt_init(&key_dbt, data_key, DATA_KEY_MAX_LEN);
dbt_init(&value_dbt, value_buf, FTFS_BSTORE_BLOCKSIZE);
len = PAGE_CACHE_SIZE;
buf = kmap(page);
ret = data_db->cursor(data_db, txn, &cursor, DB_CURSOR_FLAGS);
if (ret)
goto out2;
ret = cursor->c_get(cursor, &key_dbt, &value_dbt, DB_SET_RANGE);
while (len > 0 && ret) {
ssize_t read_size;
block_num = block_get_num_by_position(offset);
block_offset = block_get_offset_by_position(offset);
read_size = min(len, (FTFS_BSTORE_BLOCKSIZE - block_offset));
if (data_key->circle_id == meta_key->circle_id &&
!strcmp(data_key->path, meta_key->path) &&
data_key->block_num == block_num) {
memcpy(buf, value_buf, read_size);
ret = cursor->c_get(cursor, &key_dbt, &value_dbt, DB_NEXT);
} else
memset(buf, 0, read_size);
buf += read_size;
offset += read_size;
len -= read_size;
}
cursor->c_close(cursor);
out2:
kunmap(page);
out1:
kfree(value_buf);
data_key_free(data_key);
return ret;
}
示例4: sizeof
bdb_lookup(const char *zone, const char *name, void *dbdata,
dns_sdblookup_t *l)
#endif /* DNS_CLIENTINFO_VERSION */
{
int ret;
char *type, *rdata;
dns_ttl_t ttl;
isc_consttextregion_t ttltext;
DBC *c;
DBT key, data;
UNUSED(zone);
#ifdef DNS_CLIENTINFO_VERSION
UNUSED(methods);
UNUSED(clientinfo);
#endif /* DNS_CLIENTINFO_VERSION */
if ((ret = ((DB *)dbdata)->cursor((DB *)dbdata, NULL, &c, 0)) != 0) {
isc_log_iwrite(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_SDB, ISC_LOG_ERROR,
isc_msgcat, ISC_MSGSET_GENERAL,
ISC_MSG_FAILED, "DB->cursor: %s",
db_strerror(ret));
return ISC_R_FAILURE;
}
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
(const char *)key.data = name;
key.size = strlen(name);
ret = c->c_get(c, &key, &data, DB_SET);
while (ret == 0) {
((char *)key.data)[key.size] = 0;
((char *)data.data)[data.size] = 0;
ttltext.base = strtok((char *)data.data, " ");
ttltext.length = strlen(ttltext.base);
dns_ttl_fromtext((isc_textregion_t *)&ttltext, &ttl);
type = strtok(NULL, " ");
rdata = type + strlen(type) + 1;
if (dns_sdb_putrr(l, type, ttl, rdata) != ISC_R_SUCCESS) {
isc_log_iwrite(dns_lctx,
DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_SDB, ISC_LOG_ERROR,
isc_msgcat, ISC_MSGSET_GENERAL,
ISC_MSG_FAILED, "dns_sdb_putrr");
return ISC_R_FAILURE;
}
ret = c->c_get(c, &key, &data, DB_NEXT_DUP);
}
c->c_close(c);
return ISC_R_SUCCESS;
}
示例5: getHistory
void DbPlugin::getHistory (BarData *barData, QDateTime &startDate)
{
switch (type)
{
case Index1:
getIndexHistory(barData, startDate);
barData->createDateList();
return;
break;
case Spread1:
getSpreadHistory(barData, startDate);
barData->createDateList();
return;
break;
case CC1:
getCCHistory(barData, startDate);
barData->createDateList();
return;
break;
default:
break;
}
DBT key, data;
DBC *cur;
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
DBBar dbbar;
memset(&dbbar, 0, sizeof(DBBar));
data.data = &dbbar;
data.ulen = sizeof(DBBar);
data.flags = DB_DBT_USERMEM;
db->cursor(db, NULL, &cur, 0);
QString s = startDate.toString("yyyyMMddhhmmss");
key.data = (char *) s.latin1();
key.size = s.length() + 1;
cur->c_get(cur, &key, &data, DB_SET_RANGE);
while (! cur->c_get(cur, &key, &data, DB_PREV))
{
if (barData->count() >= barRange)
break;
Bar bar;
s = (char *) key.data;
getBar(dbbar, s, bar);
bar.setTickFlag(barData->getBarType());
barData->prepend(bar);
}
cur->c_close(cur);
barData->createDateList();
}
示例6: memset
/* Display all the stock quote information in the database. */
int
print_stocks(DB *dbp)
{
DBC *dbc;
DBT key, data;
#define MAXKEYSIZE 10
#define MAXDATASIZE 20
char keybuf[MAXKEYSIZE + 1], databuf[MAXDATASIZE + 1];
int ret, t_ret;
u_int32_t keysize, datasize;
if ((ret = dbp->cursor(dbp, NULL, &dbc, 0)) != 0) {
dbp->err(dbp, ret, "can't open cursor");
return (ret);
}
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
printf("\tSymbol\tPrice\n");
printf("\t======\t=====\n");
for (ret = dbc->c_get(dbc, &key, &data, DB_FIRST);
ret == 0;
ret = dbc->c_get(dbc, &key, &data, DB_NEXT)) {
keysize = key.size > MAXKEYSIZE ? MAXKEYSIZE : key.size;
memcpy(keybuf, key.data, keysize);
keybuf[keysize] = '\0';
datasize = data.size >= MAXDATASIZE ? MAXDATASIZE : data.size;
memcpy(databuf, data.data, datasize);
databuf[datasize] = '\0';
printf("\t%s\t%s\n", keybuf, databuf);
}
printf("\n");
fflush(stdout);
if ((t_ret = dbc->c_close(dbc)) != 0 && ret == 0)
ret = t_ret;
switch (ret) {
case 0:
case DB_NOTFOUND:
return (0);
case DB_LOCK_DEADLOCK:
return (0);
default:
return (ret);
}
}
示例7: store_list
int store_list(const char *key, int (*add_file)(const char *, void *),
void *opaque, struct acrd_txid *txid)
{
DBT db_key, db_data;
int ret;
DB_TXN *tid = NULL;
DBC *cursor;
if (txid)
tid = txid->tid;
ret = dbp->cursor(dbp, tid, &cursor, DB_DIRTY_READ);
if (ret) {
eprintf("failed open a cursor\n");
return ACRD_ERR_UNKNOWN;
}
memset(&db_key, 0, sizeof(db_key));
memset(&db_data, 0, sizeof(db_data));
if (key) {
db_key.data = (void *)key;
db_key.size = strlen(key) + 1;
ret = cursor->c_get(cursor, &db_key, &db_data, DB_SET_RANGE);
} else
ret = cursor->c_get(cursor, &db_key, &db_data, DB_FIRST);
while (ret == 0) {
if (key && strncmp(db_key.data, key, strlen(key)) != 0)
/* prefix doesn't match */
break;
ret = add_file(db_key.data, opaque);
if (ret != 0)
break;
ret = cursor->c_get(cursor, &db_key, &db_data, DB_NEXT);
};
if (ret == 0 || ret == DB_NOTFOUND)
ret = ACRD_SUCCESS;
else {
envp->err(envp, ret, "store_list failed\n");
ret = ACRD_ERR_UNKNOWN;
}
cursor->close(cursor);
return ret;
}
示例8: g_list_reverse
/**
* e_book_backend_db_cache_get_contacts:
* @db: DB Handle
* @query: an s-expression
*
* Returns a list of #EContact elements from @cache matching @query.
* When done with the list, the caller must unref the contacts and
* free the list.
*
* Returns: A #GList of pointers to #EContact.
**/
GList *
e_book_backend_db_cache_get_contacts (DB *db,
const gchar *query)
{
DBC *dbc;
DBT uid_dbt, vcard_dbt;
gint db_error;
GList *list = NULL;
EBookBackendSExp *sexp = NULL;
EContact *contact;
if (query) {
sexp = e_book_backend_sexp_new (query);
if (!sexp)
return NULL;
}
db_error = db->cursor (db, NULL, &dbc, 0);
if (db_error != 0) {
g_warning ("db->cursor failed with %d", db_error);
if (sexp)
g_object_unref (sexp);
return NULL;
}
memset (&vcard_dbt, 0 , sizeof (vcard_dbt));
memset (&uid_dbt, 0, sizeof (uid_dbt));
db_error = dbc->c_get (dbc, &uid_dbt, &vcard_dbt, DB_FIRST);
while (db_error == 0) {
if (vcard_dbt.data && !strncmp (vcard_dbt.data, "BEGIN:VCARD", 11)) {
contact = e_contact_new_from_vcard (vcard_dbt.data);
if (!sexp || e_book_backend_sexp_match_contact (sexp, contact))
list = g_list_prepend (list, contact);
else
g_object_unref (contact);
}
db_error = dbc->c_get (dbc, &uid_dbt, &vcard_dbt, DB_NEXT);
}
db_error = dbc->c_close (dbc);
if (db_error != 0)
g_warning ("db->c_close failed with %d", db_error);
if (sexp)
g_object_unref (sexp);
return g_list_reverse (list);
}
示例9: dump_db
int dump_db()
{
DBC *dbc;
DBT db_key, db_data;
int ret, i;
void *store;
void **store_index;
printf("Going to dump database!\n");
if(key_ops != &ci_str_ops ||val_ops != &ci_str_ops) {
ci_debug_printf(1, "can not dump not string databases\n");
return 0;
}
if ((ret = db->cursor(db, NULL, &dbc, 0)) != 0) {
ci_debug_printf(1, "error creating cursor\n");
return 0;
}
memset(&db_data, 0, sizeof(db_data));
memset(&db_key, 0, sizeof(db_key));
if ((ret = dbc->c_get(dbc, &db_key, &db_data, DB_SET_RANGE)) != 0){
ci_debug_printf(1, "error getting first element of DB : %s\n", db_strerror(ret));
dbc->c_close(dbc);
return 0;
}
do {
printf("%s :", (char *)db_key.data );
if (db_data.data) {
store = db_data.data;
store_index = store;
for(i=0; store_index[i]!=0; i++) {
store_index[i]+=(long int)store;
}
for(i=0; store_index[i]!=0; i++) {
printf("%s |", (char *)store_index[i]);
}
}
printf("\n");
ret = dbc->c_get(dbc, &db_key, &db_data, DB_NEXT);
} while (ret==0);
dbc->c_close(dbc);
return 1;
}
示例10: get_all_items
bool Bigram::get_all_items(GArray * items){
g_array_set_size(items, 0);
if ( !m_db )
return false;
DBC * cursorp = NULL;
DBT key, data;
int ret;
/* Get a cursor */
m_db->cursor(m_db, NULL, &cursorp, 0);
/* 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) {
assert(key.size == sizeof(phrase_token_t));
phrase_token_t * token = (phrase_token_t *)key.data;
g_array_append_val(items, *token);
}
assert (ret == DB_NOTFOUND);
/* Cursors must be closed */
if (cursorp != NULL)
cursorp->c_close(cursorp);
return true;
}
示例11: dbiCursorDel
static int dbiCursorDel(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags)
{
int rc = EINVAL;
int sane = (key->data != NULL && key->size > 0);
if (dbc && sane) {
DBC * cursor = dbc->cursor;
int _printit;
rpmdb rdb = dbc->dbi->dbi_rpmdb;
rpmswEnter(&rdb->db_delops, 0);
/* XXX TODO: insure that cursor is positioned with duplicates */
rc = cursor->c_get(cursor, key, data, DB_SET);
/* XXX DB_NOTFOUND can be returned */
_printit = (rc == DB_NOTFOUND ? 0 : _debug);
rc = cvtdberr(dbc->dbi, "dbcursor->c_get", rc, _printit);
if (rc == 0) {
rc = cursor->c_del(cursor, flags);
rc = cvtdberr(dbc->dbi, "dbcursor->c_del", rc, _debug);
}
rpmswExit(&rdb->db_delops, data->size);
}
return rc;
}
示例12: db_del_kv
/* Silently does nothing if the key/value isn't found.
Can't use auto-commit here! */
int db_del_kv(DB *db, DB_TXN *tid,
unsigned char *key, u_int32_t key_size,
unsigned char *value, u_int32_t value_size) {
DBT DBTKey, DBTValue;
DBC *cursor;
int ret, c_ret;
memset(&DBTKey, 0, sizeof(DBT));
DBTKey.data = key;
DBTKey.size = key_size;
memset(&DBTValue, 0, sizeof(DBT));
DBTValue.data = value;
DBTValue.size = value_size;
if ((ret = db->cursor(db, tid, &cursor, 0)) != 0)
return ret;
if ((ret = cursor->c_get(cursor, &DBTKey, &DBTValue, DB_GET_BOTH)) != 0)
goto fail;
ret = cursor->c_del(cursor, 0);
fail:
if ((c_ret = cursor->c_close(cursor)) != 0)
return c_ret;
return ret;
}
示例13: db_walk
int db_walk(void *dbh, int (*walk_func)(char *key, void *data, int len))
{
DBT key, data;
DBC *dbc;
int rc = 0;
GET_DB(dbh);
if (!walk_func)
return -EINVAL;
if ((rc = db->cursor(db, NULL, &dbc, 0))) {
db->close(db, 0);
return rc;
}
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
while (dbc->c_get(dbc, &key, &data, DB_NEXT) == 0)
if ((rc = walk_func(key.data, data.data, data.size)))
break;
dbc->c_close(dbc);
return rc;
}
示例14: scanscan_hwc
static void scanscan_hwc (void) {
int r;
int counter=0;
for (counter=0; counter<n_experiments; counter++) {
long long totalbytes=0;
int rowcounter=0;
double prevtime = gettime();
DBT k,v;
DBC *dbc;
r = db->cursor(db, tid, &dbc, 0); assert(r==0);
memset(&k, 0, sizeof(k));
memset(&v, 0, sizeof(v));
u_int32_t c_get_flags = DB_NEXT;
if (prelockflag && (counter || prelock)) {
c_get_flags |= lock_flag;
}
while (0 == (r = dbc->c_get(dbc, &k, &v, c_get_flags))) {
//printf("r=%d\n", r);
totalbytes += k.size + v.size;
rowcounter++;
if (limitcount>0 && rowcounter>=limitcount) break;
}
assert(r==DB_NOTFOUND);
r = dbc->c_close(dbc); assert(r==0);
double thistime = gettime();
double tdiff = thistime-prevtime;
printf("Scan %lld bytes (%d rows) in %9.6fs at %9fMB/s\n", totalbytes, rowcounter, tdiff, 1e-6*totalbytes/tdiff);
}
}
示例15: show_koef_db
int show_koef_db(DB *dbp)
{
DBT key, data;
DBC *cursorp;
struct kdb_key *kdbkeyp;
struct kdb_data *kdbdatap;
int ret;
dbp->cursor(dbp, NULL, &cursorp, 0);
/* Initialize our DBTs. */
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
while ((ret = cursorp->c_get(cursorp, &key, &data, DB_NEXT)) == 0) {
kdbkeyp = (struct kdb_key *) key.data;
kdbdatap = (struct kdb_data *) data.data;
fprintf(stdout,"%i : %x : %f\t%f\n",
kdbkeyp->asdu,
kdbkeyp->ioa2,
kdbdatap->koef_u,
kdbdatap->koef_i
);
}
return 0;
}