本文整理汇总了C++中Db::set_re_len方法的典型用法代码示例。如果您正苦于以下问题:C++ Db::set_re_len方法的具体用法?C++ Db::set_re_len怎么用?C++ Db::set_re_len使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db
的用法示例。
在下文中一共展示了Db::set_re_len方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: except
//
// Initialize the database to the specified number of accounts, branches,
// history records, and tellers.
//
void
TpcbExample::populate(int accounts, int branches, int history, int tellers)
{
Db *dbp;
int err;
u_int32_t balance, idnum;
u_int32_t end_anum, end_bnum, end_tnum;
u_int32_t start_anum, start_bnum, start_tnum;
idnum = BEGID;
balance = 500000;
dbp = new Db(this, 0);
dbp->set_h_nelem((unsigned int)accounts);
if ((err = dbp->open(NULL, "account", NULL, DB_HASH,
DB_CREATE, 0644)) != 0) {
DbException except("Account file create failed", err);
throw except;
}
start_anum = idnum;
populateTable(dbp, idnum, balance, accounts, "account");
idnum += accounts;
end_anum = idnum - 1;
if ((err = dbp->close(0)) != 0) {
DbException except("Account file close failed", err);
throw except;
}
delete dbp;
if (verbose)
cout << "Populated accounts: "
<< (long)start_anum << " - " << (long)end_anum << "\n";
dbp = new Db(this, 0);
//
// Since the number of branches is very small, we want to use very
// small pages and only 1 key per page. This is the poor-man's way
// of getting key locking instead of page locking.
//
dbp->set_h_ffactor(1);
dbp->set_h_nelem((unsigned int)branches);
dbp->set_pagesize(512);
if ((err = dbp->open(NULL, "branch", NULL, DB_HASH,
DB_CREATE, 0644)) != 0) {
DbException except("Branch file create failed", err);
throw except;
}
start_bnum = idnum;
populateTable(dbp, idnum, balance, branches, "branch");
idnum += branches;
end_bnum = idnum - 1;
if ((err = dbp->close(0)) != 0) {
DbException except("Close of branch file failed", err);
throw except;
}
delete dbp;
if (verbose)
cout << "Populated branches: "
<< (long)start_bnum << " - " << (long)end_bnum << "\n";
dbp = new Db(this, 0);
//
// In the case of tellers, we also want small pages, but we'll let
// the fill factor dynamically adjust itself.
//
dbp->set_h_ffactor(0);
dbp->set_h_nelem((unsigned int)tellers);
dbp->set_pagesize(512);
if ((err = dbp->open(NULL, "teller", NULL, DB_HASH,
DB_CREATE, 0644)) != 0) {
DbException except("Teller file create failed", err);
throw except;
}
start_tnum = idnum;
populateTable(dbp, idnum, balance, tellers, "teller");
idnum += tellers;
end_tnum = idnum - 1;
if ((err = dbp->close(0)) != 0) {
DbException except("Close of teller file failed", err);
throw except;
}
delete dbp;
if (verbose)
cout << "Populated tellers: "
<< (long)start_tnum << " - " << (long)end_tnum << "\n";
dbp = new Db(this, 0);
dbp->set_re_len(HISTORY_LEN);
if ((err = dbp->open(NULL, "history", NULL, DB_RECNO,
DB_CREATE, 0644)) != 0) {
//.........这里部分代码省略.........
示例2: except
//.........这里部分代码省略.........
idnum = BEGID;
balance = 500000;
oflags = DB_CREATE;
dbp = new Db(this, DB_CXX_NO_EXCEPTIONS);
dbp->set_h_nelem((unsigned int)accounts);
if ((err = dbp->open(NULL, "account", NULL,
DB_HASH, oflags, 0644)) != 0) {
DbException except("Account file create failed", err);
throw except;
}
dbstl::register_db(dbp);
accounts_map = new DefrecMap(dbp, this);
start_anum = idnum;
populateTable(accounts_map, idnum, balance, accounts, "account");
idnum += accounts;
end_anum = idnum - 1;
// Automatically closes the underlying database.
delete accounts_map;
dbstl::close_db(dbp);
delete dbp;
if (verbose)
cout << "Populated accounts: "
<< (long)start_anum << " - " << (long)end_anum << "\n";
dbp = new Db(this, DB_CXX_NO_EXCEPTIONS);
//
// Since the number of branches is very small, we want to use very
// small pages and only 1 key per page. This is the poor-man's way
// of getting key locking instead of page locking.
//
dbp->set_h_ffactor(1);
dbp->set_h_nelem((unsigned int)branches);
dbp->set_pagesize(512);
if ((err = dbp->open(NULL,
"branch", NULL, DB_HASH, oflags, 0644)) != 0) {
DbException except("Branch file create failed", err);
throw except;
}
dbstl::register_db(dbp);
branches_map = new DefrecMap(dbp, this);
start_bnum = idnum;
populateTable(branches_map, idnum, balance, branches, "branch");
idnum += branches;
end_bnum = idnum - 1;
delete branches_map;
dbstl::close_db(dbp);
delete dbp;
if (verbose)
cout << "Populated branches: "
<< (long)start_bnum << " - " << (long)end_bnum << "\n";
dbp = new Db(this, DB_CXX_NO_EXCEPTIONS);
//
// In the case of tellers, we also want small pages, but we'll let
// the fill factor dynamically adjust itself.
//
dbp->set_h_ffactor(0);
dbp->set_h_nelem((unsigned int)tellers);
dbp->set_pagesize(512);
if ((err = dbp->open(NULL,
"teller", NULL, DB_HASH, oflags, 0644)) != 0) {
DbException except("Teller file create failed", err);
throw except;
}
dbstl::register_db(dbp);
tellers_map = new DefrecMap(dbp, this);
start_tnum = idnum;
populateTable(tellers_map, idnum, balance, tellers, "teller");
idnum += tellers;
end_tnum = idnum - 1;
delete tellers_map;
dbstl::close_db(dbp);
delete dbp;
if (verbose)
cout << "Populated tellers: "
<< (long)start_tnum << " - " << (long)end_tnum << "\n";
dbp = new Db(this, DB_CXX_NO_EXCEPTIONS);
dbp->set_re_len(HISTORY_LEN);
if ((err = dbp->open(NULL,
"history", NULL, DB_RECNO, oflags, 0644)) != 0) {
DbException except("Create of history file failed", err);
throw except;
}
dbstl::register_db(dbp);
history_vector = new HistrecVector(dbp, this);
populateHistory(history_vector, history, accounts, branches, tellers);
delete history_vector;
dbstl::close_db(dbp);
delete dbp;
}