本文整理汇总了C++中Db::del方法的典型用法代码示例。如果您正苦于以下问题:C++ Db::del方法的具体用法?C++ Db::del怎么用?C++ Db::del使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db
的用法示例。
在下文中一共展示了Db::del方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Delete
int DiskBDB::Delete (const Vdt&dzname, const Vdt&Key,stats *stats_update)
{
Db *DbHandle;
int ret=0;
ret=m_dzManager->Get(dzname,Key,DbHandle);
if(ret!=0)
{
cout<<"The Handle was not retrieved from datazone manager"<<endl;
return ret;
}
Dbt key(Key.get_data(),Key.get_size());
bool keepTrying=true;
int numTries=0;
while(keepTrying && numTries < m_maxDeadlockRetries)
{
numTries++;
try {
ret=DbHandle->del(NULL,&key,0);
keepTrying=false;
}
catch(DbException &e) {
if(numTries==1)
printf("DiskBDB Delete::%s\n",e.what());
ret=e.get_errno();
if(ret==DB_LOCK_DEADLOCK)
{
if(stats_update)
stats_update->NumDeadlocks++;
}
else
keepTrying=false;
} catch(exception &e) {
cout << e.what() << endl;
return (-1);
}
}
return ret;
}
示例2: bulkSecondaryDelete
/* Bulk delete from a secondary db. */
void BulkExample::bulkSecondaryDelete(
int num, int pair, int *countp, int *iterp, int verbose)
{
Dbt key;
DbTxn *txnp;
DbMultipleDataBuilder *ptrd;
DbMultipleKeyDataBuilder *ptrkd;
u_int32_t flag;
int count, i, iter, j, k, rc, ret;
char ch;
memset(&key, 0, sizeof(Dbt));
txnp = NULL;
count = flag = iter = ret = 0;
rc = rand() % (STRLEN - 1);
/*
* The buffer must be at least as large as the page size of the
* underlying database and aligned for unsigned integer access.
* Its size must be a multiple of 1024 bytes.
*/
if (klen != (u_int32_t)UPDATES_PER_BULK_PUT *
(sizeof(u_int32_t) + DATALEN) * 1024) {
klen = (u_int32_t)UPDATES_PER_BULK_PUT *
(sizeof(u_int32_t) + DATALEN) * 1024;
kbuf = realloc(kbuf, klen);
}
memset(kbuf, 0, klen);
key.set_ulen(klen);
key.set_flags(DB_DBT_USERMEM | DB_DBT_BULK);
key.set_data(kbuf);
/*
* Bulk delete all records of a specific set of keys which includes all
* characters before the random key in the tstring. The random key is
* one of the characters in the tstring.
* If DB_MULTIPLE, construct the key Dbt by the DbMultipleDataBuilder
* with the specific set of keys. If DB_MULTIPLE_KEY, construct the key
* Dbt by the DbMultipleKeyDataBuilder with all key/data pairs of the
* specific set of keys.
*/
flag |= (pair) ? DB_MULTIPLE_KEY : DB_MULTIPLE;
if (pair)
ptrkd = new DbMultipleKeyDataBuilder(key);
else
ptrd = new DbMultipleDataBuilder(key);
try {
for (i = 0; i <= rc; i++) {
if (i % UPDATES_PER_BULK_PUT == 0) {
if (txnp != NULL) {
ret = txnp->commit(0);
txnp = NULL;
if (ret != 0)
throwException(dbenv, NULL,
ret, "DB_TXN->commit");
}
if ((ret = dbenv->txn_begin(NULL,
&txnp, 0)) != 0)
throwException(dbenv,
NULL, ret, "DB_ENV->txn_begin");
}
ch = tstring[i];
if (!pair) {
if (ptrd->append(&ch, sizeof(ch)) == false)
throwException(dbenv,
txnp, EXIT_FAILURE,
"DbMultipleDataBuilder->append");
count++;
if (verbose)
printf("Delete key: %c\n", ch);
} else {
j = 0;
do {
k = j * (STRLEN - 1) + i;
if (ptrkd->append(&ch, sizeof(ch),
&k, sizeof(k)) == false)
throwException(dbenv,
txnp, EXIT_FAILURE,
"DbMultipleKeyDataBuilder->append");
count++;
if (verbose)
printf(
"Delete secondary key: %c, \tdata: %d\n",
ch, k);
} while (++j < (int)(num / (STRLEN - 1)));
}
if ((i + 1) % UPDATES_PER_BULK_PUT == 0) {
if ((ret = sdbp->del(txnp, &key, flag)) != 0)
throwException(dbenv,
txnp, ret, "Bulk DB->del");
iter++;
if (pair)
ptrkd = new
DbMultipleKeyDataBuilder(key);
else
ptrd = new DbMultipleDataBuilder(key);
}
//.........这里部分代码省略.........
示例3: bulkDelete
/* Bulk delete from a database. */
void BulkExample::bulkDelete(
int num, int dups, int *countp, int *iterp, int verbose)
{
Dbt key;
DbTxn *txnp;
DbMultipleDataBuilder *ptrd;
DbMultipleKeyDataBuilder *ptrkd;
u_int32_t flag;
int count, i, j, iter, ret;
txnp = NULL;
count = flag = iter = ret = 0;
memset(&key, 0, sizeof(Dbt));
j = rand() % num;
/*
* The buffer must be at least as large as the page size of the
* underlying database and aligned for unsigned integer access.
* Its size must be a multiple of 1024 bytes.
*/
if (klen != (u_int32_t)UPDATES_PER_BULK_PUT *
(sizeof(u_int32_t) + DATALEN) * 1024) {
klen = (u_int32_t)UPDATES_PER_BULK_PUT *
(sizeof(u_int32_t) + DATALEN) * 1024;
kbuf = realloc(kbuf, klen);
}
memset(kbuf, 0, klen);
key.set_ulen(klen);
key.set_flags(DB_DBT_USERMEM | DB_DBT_BULK);
key.set_data(kbuf);
if (data_val == NULL)
data_val = (data *)malloc(DATALEN);
memset(data_val, 0, DATALEN);
/*
* Bulk delete all records of a specific set of keys which includes all
* non-negative integers smaller than the random key. The random key is
* a random non-negative integer smaller than "num".
* If DB_MULTIPLE, construct the key Dbt by the DbMultipleDataBuilder
* with the specific set of keys. If DB_MULTIPLE_KEY, construct the key
* Dbt by the DbMultipleKeyDataBuilder with all key/data pairs of the
* specific set of keys.
*/
flag |= (dups) ? DB_MULTIPLE_KEY : DB_MULTIPLE;
if (dups)
ptrkd = new DbMultipleKeyDataBuilder(key);
else
ptrd = new DbMultipleDataBuilder(key);
try {
for (i = 0; i < j; i++) {
if (i % UPDATES_PER_BULK_PUT == 0) {
if (txnp != NULL) {
ret = txnp->commit(0);
txnp = NULL;
if (ret != 0)
throwException(dbenv, NULL,
ret, "DB_TXN->commit");
}
if ((ret = dbenv->txn_begin(NULL,
&txnp, 0)) != 0)
throwException(dbenv, NULL,
ret, "DB_ENV->txn_begin");
}
if (dups) {
data_val->id = 0;
get_string(tstring, data_val->str, i);
do {
if(ptrkd->append(&i,sizeof(i),
data_val, DATALEN) == false)
throwException(dbenv,
txnp, EXIT_FAILURE,
"DbMultipleKeyDataBuilder->append");
count++;
if (verbose)
printf(
"Delete key: %d, \tdata: (id %d, str %s)\n",
i, data_val->id,
data_val->str);
} while (data_val->id++ < dups);
} else {
if(ptrd->append(&i,sizeof(i)) == false)
throwException(dbenv, txnp, ret,
"DbMultipleDataBuilder->append");
count++;
if (verbose)
printf("Delete key: %d\n", i);
}
if ((i + 1) % UPDATES_PER_BULK_PUT == 0) {
if ((ret = dbp->del(txnp, &key, flag)) != 0)
throwException(dbenv,
txnp, ret, "Bulk DB->del");
iter++;
if (dups)
ptrkd = new
DbMultipleKeyDataBuilder(key);
else
//.........这里部分代码省略.........