本文整理汇总了C++中DBC::put方法的典型用法代码示例。如果您正苦于以下问题:C++ DBC::put方法的具体用法?C++ DBC::put怎么用?C++ DBC::put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBC
的用法示例。
在下文中一共展示了DBC::put方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rberkeley_dbcursor_put
/* {{{ rberkeley_dbcursor_put */
SEXP rberkeley_dbcursor_put (SEXP _dbc, SEXP _key, SEXP _data, SEXP _flags)
{
DBC *dbc;
DBT key, data;
u_int32_t flags;
int ret;
flags = (u_int32_t)INTEGER(_flags)[0];
if(flags != DB_AFTER &&
flags != DB_BEFORE &&
flags != DB_CURRENT &&
flags != DB_KEYFIRST &&
flags != DB_KEYLAST &&
flags != DB_NODUPDATA) {
error("incorrect flags value");
}
dbc = R_ExternalPtrAddr(_dbc);
if(R_ExternalPtrTag(_dbc) != install("DBC") || dbc == NULL)
error("invalid 'dbc' handle");
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
key.data = (unsigned char *)RAW(_key);
key.size = length(_key);
data.data = (unsigned char *)RAW(_data);
data.size = length(_data);
ret = dbc->put(dbc, &key, &data, flags);
return ScalarInteger(ret);
}
示例2:
static int
kvs_cursor_update(WT_CURSOR *wtcursor)
{
CURSOR_SOURCE *cursor;
DBC *dbc;
DBT *key, *value;
WT_EXTENSION_API *wt_api;
WT_SESSION *session;
int ret = 0;
session = wtcursor->session;
cursor = (CURSOR_SOURCE *)wtcursor;
wt_api = cursor->wt_api;
dbc = cursor->dbc;
key = &cursor->key;
value = &cursor->value;
if ((ret = copyin_key(wtcursor)) != 0)
return (ret);
copyin_value(wtcursor);
if ((ret = dbc->put(dbc, key, value, DB_KEYFIRST)) != 0)
ERET(wt_api,
session, WT_ERROR, "DbCursor.put: %s", db_strerror(ret));
return (0);
}
示例3: replace_impl
/**
@brief replace OR insert a record
@note
if not thrown an exception, always success
@return true replace the record
false insert the record
@throws exception, failed
*/
bool kmapdset_base::replace_impl(const void* k1, const void* d, DB_TXN* txn, const char* func)
{
PortableDataOutput<AutoGrownMemIO> oKey1, oData;
try {
save_key1(oKey1, k1);
save_data(oData, d);
}
catch (const IOException& exp)
{
string_appender<> oss;
oss << exp.what() << "... at: " << func;
throw std::runtime_error(oss.str());
}
DBT tk1; memset(&tk1, 0, sizeof(DBT)); tk1.data = oKey1.begin(); tk1.size = oKey1.tell();
DBT tdd; memset(&tdd, 0, sizeof(DBT)); tdd.data = oData.begin(); tdd.size = oData.tell();
DBC* curp = NULL;
int ret = m_db->cursor(m_db, txn, &curp, 0);
if (0 == ret)
{
ret = curp->get(curp, &tk1, &tdd, DB_GET_BOTH);
if (0 == ret)
{
tk1.data = oKey1.begin(); tk1.size = oKey1.tell();
tdd.data = oData.begin(); tdd.size = oData.tell();
ret = curp->put(curp, &tk1, &tdd, DB_CURRENT);
curp->close(curp);
if (0 == ret)
return true;
}
else if (DB_NOTFOUND == ret)
{
ret = curp->put(curp, &tk1, &tdd, DB_NODUPDATA);
curp->close(curp);
if (0 == ret)
return false;
}
}
string_appender<> oss;
oss << db_strerror(ret)
<< "... at: " << func
<< "\n"
;
throw std::runtime_error(oss.str());
}
示例4:
void
bdb_insert(
const void *key_data, uint32_t key_size,
const void *value_data, uint32_t value_size)
{
DBC *dbc;
key.data = (void *)key_data;
key.size = key_size;
value.data = (void *)value_data;
value.size = value_size;
dbc = g.dbc;
assert(dbc->put(dbc, &key, &value, DB_KEYFIRST) == 0);
}
示例5: if
static int
kvs_cursor_insert(WT_CURSOR *wtcursor)
{
CURSOR_SOURCE *cursor;
DB *db;
DBC *dbc;
DBT *key, *value;
WT_EXTENSION_API *wt_api;
WT_SESSION *session;
int ret = 0;
session = wtcursor->session;
cursor = (CURSOR_SOURCE *)wtcursor;
wt_api = cursor->wt_api;
dbc = cursor->dbc;
db = cursor->db;
key = &cursor->key;
value = &cursor->value;
if ((ret = copyin_key(wtcursor)) != 0)
return (ret);
copyin_value(wtcursor);
if (cursor->config_append) {
/*
* Berkeley DB cursors have no operation to append/create a
* new record and set the cursor; use the DB handle instead
* then set the cursor explicitly.
*
* When appending, we're allocating and returning a new record
* number.
*/
if ((ret = db->put(db, NULL, key, value, DB_APPEND)) != 0)
ERET(wt_api,
session, WT_ERROR, "Db.put: %s", db_strerror(ret));
wtcursor->recno = *(db_recno_t *)key->data;
if ((ret = dbc->get(dbc, key, value, DB_SET)) != 0)
ERET(wt_api, session, WT_ERROR,
"DbCursor.get: %s", db_strerror(ret));
} else if (cursor->config_overwrite) {
if ((ret = dbc->put(dbc, key, value, DB_KEYFIRST)) != 0)
ERET(wt_api, session, WT_ERROR,
"DbCursor.put: %s", db_strerror(ret));
} else {
/*
* Berkeley DB cursors don't have a no-overwrite flag; use
* the DB handle instead then set the cursor explicitly.
*/
if ((ret =
db->put(db, NULL, key, value, DB_NOOVERWRITE)) != 0) {
if (ret == DB_KEYEXIST)
return (WT_DUPLICATE_KEY);
ERET(wt_api,
session, WT_ERROR, "Db.put: %s", db_strerror(ret));
}
if ((ret = dbc->get(dbc, key, value, DB_SET)) != 0)
ERET(wt_api, session, WT_ERROR,
"DbCursor.get: %s", db_strerror(ret));
}
return (0);
}