本文整理汇总了C++中Dbt::set_ulen方法的典型用法代码示例。如果您正苦于以下问题:C++ Dbt::set_ulen方法的具体用法?C++ Dbt::set_ulen怎么用?C++ Dbt::set_ulen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dbt
的用法示例。
在下文中一共展示了Dbt::set_ulen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Get
bool Table::Get(Transaction* tx,
const ByteString &key,
ByteString &value)
{
Dbt dbtKey;
Dbt dbtValue;
DbTxn* txn = NULL;
int ret;
if (tx)
txn = tx->txn;
dbtKey.set_flags(DB_DBT_USERMEM);
dbtKey.set_data(key.buffer);
dbtKey.set_ulen(key.length);
dbtKey.set_size(key.length);
dbtValue.set_flags(DB_DBT_USERMEM);
dbtValue.set_data(value.buffer);
dbtValue.set_ulen(value.size);
ret = db->get(txn, &dbtKey, &dbtValue, 0);
// DB_PAGE_NOTFOUND can occur with parallel PRUNE and GET operations
// probably because we have DB_READ_UNCOMMITED turned on
if (ret == DB_KEYEMPTY || ret == DB_NOTFOUND || ret == DB_PAGE_NOTFOUND)
return false;
if (dbtValue.get_size() > (size_t) value.size)
return false;
value.length = dbtValue.get_size();
return true;
}
示例2: get
RecordData Database::get(const RecordID& id) const
{
Dbt key(id.data(), id.size());
Dbt data;
thread_local static std::vector<char> buffer(256);
while (true)
{
try
{
data.set_flags(DB_DBT_USERMEM);
data.set_data(buffer.data());
data.set_ulen(buffer.size());
const int err = dbMain_.get(/*txnid*/nullptr, &key, &data, /*flags*/0);
assert (err == 0);
break;
}
catch(DbException const& ex)
{
if (ex.get_errno() != DB_BUFFER_SMALL)
{
throw;
}
buffer.resize(data.get_size() * 1.5);
}
}
return RecordData(data);
}
示例3: dirs_begin
db_iterator Database::dirs_begin() const
{
Dbc* pCursor = nullptr;
dbDirs_.cursor(NULL, &pCursor, 0);
assert(pCursor);
RecordID id;
Dbt key;
Dbt data;
key.set_flags(DB_DBT_USERMEM);
key.set_data(id.data());
key.set_ulen(id.size());
const int err = pCursor->get(&key, &data, DB_FIRST);
if (err)
{
pCursor->close();
if (err != DB_NOTFOUND)
{
throw DbException("Failed to obtain first directory record", err);
}
return dirs_end();
}
return db_iterator(pCursor, make_Record(std::move(id), RecordData(data)));
}
示例4: fprintf
/**
* Cursor must be closed before the transaction is aborted/commited.
* http://download.oracle.com/docs/cd/E17076_02/html/programmer_reference/transapp_cursor.html
*/
Bdb::ResponseCode Bdb::
update(const std::string& key, const std::string& value)
{
if (!inited_) {
fprintf(stderr, "insert called on uninitialized database");
return Error;
}
DbTxn* txn = NULL;
Dbc* cursor = NULL;
Dbt dbkey, dbdata;
dbkey.set_data(const_cast<char*>(key.c_str()));
dbkey.set_size(key.size());
dbdata.set_data(const_cast<char*>(value.c_str()));
dbdata.set_size(value.size());
Dbt currentData;
currentData.set_data(NULL);
currentData.set_ulen(0);
currentData.set_dlen(0);
currentData.set_doff(0);
currentData.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL);
int rc = 0;
for (uint32_t idx = 0; idx < numRetries_; idx++) {
env_->txn_begin(NULL, &txn, 0);
(*db_).cursor(txn, &cursor, DB_READ_COMMITTED);
// move the cursor to the record.
rc = cursor->get(&dbkey, ¤tData, DB_SET | DB_RMW);
if (rc != 0) {
cursor->close();
txn->abort();
if (rc == DB_NOTFOUND) {
return KeyNotFound;
} else if (rc != DB_LOCK_DEADLOCK) {
fprintf(stderr, "Db::get() returned: %s", db_strerror(rc));
return Error;
}
continue;
}
// update the record.
rc = cursor->put(NULL, &dbdata, DB_CURRENT);
cursor->close();
if (rc == 0) {
txn->commit(DB_TXN_SYNC);
return Success;
} else {
txn->abort();
if (rc != DB_LOCK_DEADLOCK) {
fprintf(stderr, "Db::put() returned: %s", db_strerror(rc));
return Error;
}
}
}
fprintf(stderr, "update failed %d times", numRetries_);
return Error;
}
示例5: GetShort
short CKeyValuePair::GetShort(const std::string &key) {
structKey k( Int16, key.size(), key.c_str() );
Dbt v;
short value;
v.set_flags( DB_DBT_USERMEM );
v.set_ulen( sizeof( short ) );
v.set_size( sizeof( short ) );
v.set_data( &value );
Get( k, &v );
return value;
}
示例6: GetDouble
double CKeyValuePair::GetDouble(const std::string &key) {
structKey k( Double, key.size(), key.c_str() );
Dbt v;
double value;
v.set_flags( DB_DBT_USERMEM );
v.set_ulen( sizeof( double ) );
v.set_size( sizeof( double ) );
v.set_data( &value );
Get( k, &v );
return value;
}
示例7: GetUnsignedLong
unsigned long CKeyValuePair::GetUnsignedLong(const std::string &key) {
structKey k( UInt32, key.size(), key.c_str() );
Dbt v;
unsigned long value;
v.set_flags( DB_DBT_USERMEM );
v.set_ulen( sizeof( unsigned long ) );
v.set_size( sizeof( unsigned long ) );
v.set_data( &value );
Get( k, &v );
return value;
}
示例8: GetFloat
float CKeyValuePair::GetFloat(const std::string &key) {
structKey k( Float, key.size(), key.c_str() );
Dbt v;
float value;
v.set_flags( DB_DBT_USERMEM );
v.set_ulen( sizeof( float ) );
v.set_size( sizeof( float ) );
v.set_data( &value );
Get( k, &v );
return value;
}
示例9: ds
void operator<<(Dbt& dbt, const T& obj)
{
QByteArray ba;
QDataStream ds(&ba, QIODevice::WriteOnly);
// Serialize the object
ds << obj;
dbt.set_ulen(ba.size());
dbt.set_data(ba.data());
}
示例10: read
string read(const char* skey){
Dbt key((void*)skey, ::strlen(skey));
//fetch
char* buf = _allocHeap(); //keep as heap mem
Dbt data;
data.set_data(buf);
data.set_ulen(MAX_LEN);
data.set_flags(DB_DBT_USERMEM);
if( _db->get(nullptr, &key, &data, 0) == DB_NOTFOUND){
return string("F");
};
string res(buf);
delete[] buf;
return res;
};
示例11: test_dbt
void test_dbt(void) {
u_int32_t size = 3;
u_int32_t flags = 5;
u_int32_t ulen = 7;
void* data = &size;
Dbt dbt;
dbt.set_size(size);
dbt.set_flags(flags);
dbt.set_data(data);
dbt.set_ulen(ulen);
assert(dbt.get_size() == size);
assert(dbt.get_flags() == flags);
assert(dbt.get_data() == data);
assert(dbt.get_ulen() == ulen);
}
示例12: key
// Shows a vendor record. Each vendor record is an instance of
// a vendor structure. See loadVendorDB() in
// example_database_load for how this structure was originally
// put into the database.
int
show_vendor(MyDb &vendorDB, const char *vendor)
{
Dbt data;
VENDOR my_vendor;
try {
// Set the search key to the vendor's name
// vendor is explicitly cast to char * to stop a compiler
// complaint.
Dbt key((char *)vendor, (u_int32_t)strlen(vendor) + 1);
// Make sure we use the memory we set aside for the VENDOR
// structure rather than the memory that DB allocates.
// Some systems may require structures to be aligned in memory
// in a specific way, and DB may not get it right.
data.set_data(&my_vendor);
data.set_ulen(sizeof(VENDOR));
data.set_flags(DB_DBT_USERMEM);
// Get the record
vendorDB.getDb().get(NULL, &key, &data, 0);
std::cout << " " << my_vendor.street << "\n"
<< " " << my_vendor.city << ", "
<< my_vendor.state << "\n"
<< " " << my_vendor.zipcode << "\n"
<< " " << my_vendor.phone_number << "\n"
<< " Contact: " << my_vendor.sales_rep << "\n"
<< " " << my_vendor.sales_rep_phone
<< std::endl;
}
catch (DbException &e) {
vendorDB.getDb().err(e.get_errno(), "Error in show_vendor");
throw e;
}
catch (std::exception &e) {
throw e;
}
return (0);
}
示例13: run
void BtRecExample::run()
{
db_recno_t recno;
int ret;
char buf[1024];
// Acquire a cursor for the database.
dbp->cursor(NULL, &dbcp, 0);
//
// Prompt the user for a record number, then retrieve and display
// that record.
//
for (;;) {
// Get a record number.
cout << "recno #> ";
cout.flush();
if (fgets(buf, sizeof(buf), stdin) == NULL)
break;
recno = atoi(buf);
//
// Start with a fresh key each time,
// the dbp->get() routine returns
// the key and data pair, not just the key!
//
Dbt key(&recno, sizeof(recno));
Dbt data;
if ((ret = dbcp->get(&key, &data, DB_SET_RECNO)) != 0) {
dbp->err(ret, "DBcursor->get");
throw DbException(ret);
}
// Display the key and data.
show("k/d\t", &key, &data);
// Move the cursor a record forward.
if ((ret = dbcp->get(&key, &data, DB_NEXT)) != 0) {
dbp->err(ret, "DBcursor->get");
throw DbException(ret);
}
// Display the key and data.
show("next\t", &key, &data);
//
// Retrieve the record number for the following record into
// local memory.
//
data.set_data(&recno);
data.set_size(sizeof(recno));
data.set_ulen(sizeof(recno));
data.set_flags(data.get_flags() | DB_DBT_USERMEM);
if ((ret = dbcp->get(&key, &data, DB_GET_RECNO)) != 0) {
if (ret != DB_NOTFOUND && ret != DB_KEYEMPTY) {
dbp->err(ret, "DBcursor->get");
throw DbException(ret);
}
}
else {
cout << "retrieved recno: " << (u_long)recno << "\n";
}
}
dbcp->close();
dbcp = NULL;
}
示例14: pkey
vector<Identity>
Freeze::IndexI::untypedFindFirst(const Key& bytes, Int firstN) const
{
DeactivateController::Guard
deactivateGuard(_store->evictor()->deactivateController());
Dbt dbKey;
initializeInDbt(bytes, dbKey);
#if (DB_VERSION_MAJOR <= 4) || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR <= 1)
//
// When we have a custom-comparison function, Berkeley DB returns
// the key on-disk (when it finds one). We disable this behavior:
// (ref Oracle SR 5925672.992)
//
dbKey.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL);
#else
//
// In DB > 5.1 we can not set DB_DBT_PARTIAL in the key Dbt,
// when using DB_SET, we must resize the Dbt key param to hold enought
// space or Dbc::get fails with DB_BUFFER_SMALL.
//
dbKey.set_flags(DB_DBT_USERMEM);
dbKey.set_ulen(static_cast<u_int32_t>(bytes.size()));
#endif
Key pkey(1024);
Dbt pdbKey;
initializeOutDbt(pkey, pdbKey);
Dbt dbValue;
dbValue.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL);
const Ice::CommunicatorPtr& communicator = _store->communicator();
const Ice::EncodingVersion& encoding = _store->encoding();
TransactionIPtr transaction = _store->evictor()->beforeQuery();
DbTxn* tx = transaction == 0 ? 0 : transaction->dbTxn();
vector<Identity> identities;
try
{
for(;;)
{
Dbc* dbc = 0;
identities.clear();
try
{
//
// Move to the first record
//
_db->cursor(tx, &dbc, 0);
u_int32_t flags = DB_SET;
bool found;
do
{
for(;;)
{
try
{
//
// It is critical to set key size to key capacity before the
// get, as a resize that increases the size inserts 0
//
pkey.resize(pkey.capacity());
found = (dbc->pget(&dbKey, &pdbKey, &dbValue, flags) == 0);
if(found)
{
pkey.resize(pdbKey.get_size());
Ice::Identity ident;
ObjectStoreBase::unmarshal(ident, pkey, communicator, encoding);
identities.push_back(ident);
flags = DB_NEXT_DUP;
}
break; // for(;;)
}
catch(const DbDeadlockException&)
{
throw;
}
catch(const DbException& dx)
{
handleDbException(dx, pkey, pdbKey, __FILE__, __LINE__);
}
}
}
while((firstN <= 0 || identities.size() < static_cast<size_t>(firstN)) && found);
Dbc* toClose = dbc;
dbc = 0;
toClose->close();
break; // for (;;)
}
catch(const DbDeadlockException&)
{
//.........这里部分代码省略.........
示例15: out
Int
Freeze::IndexI::untypedCount(const Key& bytes) const
{
DeactivateController::Guard
deactivateGuard(_store->evictor()->deactivateController());
Dbt dbKey;
initializeInDbt(bytes, dbKey);
#if (DB_VERSION_MAJOR <= 4) || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR <= 1)
//
// When we have a custom-comparison function, Berkeley DB returns
// the key on-disk (when it finds one). We disable this behavior:
// (ref Oracle SR 5925672.992)
//
dbKey.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL);
#else
//
// In DB > 5.1 we can not set DB_DBT_PARTIAL in the key Dbt,
// when using DB_SET, we must resize the Dbt key param to hold enought
// space or Dbc::get fails with DB_BUFFER_SMALL.
//
dbKey.set_flags(DB_DBT_USERMEM);
dbKey.set_ulen(static_cast<u_int32_t>(bytes.size()));
#endif
Dbt dbValue;
dbValue.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL);
TransactionIPtr transaction = _store->evictor()->beforeQuery();
DbTxn* tx = transaction == 0 ? 0 : transaction->dbTxn();
Int result = 0;
try
{
for(;;)
{
Dbc* dbc = 0;
try
{
//
// Move to the first record
//
_db->cursor(tx, &dbc, 0);
bool found = (dbc->get(&dbKey, &dbValue, DB_SET) == 0);
if(found)
{
db_recno_t count = 0;
dbc->count(&count, 0);
result = static_cast<Int>(count);
}
Dbc* toClose = dbc;
dbc = 0;
toClose->close();
break; // for (;;)
}
catch(const DbDeadlockException&)
{
if(dbc != 0)
{
try
{
dbc->close();
}
catch(const DbDeadlockException&)
{
if(tx != 0)
{
throw;
}
// Else ignored
}
}
if(_store->evictor()->deadlockWarning())
{
Warning out(_store->communicator()->getLogger());
out << "Deadlock in Freeze::IndexI::untypedCount while searching \""
<< _store->evictor()->filename() + "/" + _dbName << "\"; retrying ...";
}
if(tx != 0)
{
throw;
}
// Else retry
}
catch(...)
{
if(dbc != 0)
{
try
{
dbc->close();
}
catch(const DbDeadlockException&)
//.........这里部分代码省略.........