Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "db_map.h" // Berkeley DB's STL Map support
- using namespace dbstl;
- main()
- {
- std::string key = "hello";
- int value = 1234;
- Db *dbp = NULL;
- DbEnv *envp = NULL;
- typedef db_multimap<char *, int, ElementHolder<int> > strmap_t;
- envp = new DbEnv( ... );
- dbp = new Db(envp, ... );
- dbstl::dbstl_startup();
- dbstl::register_db(dbp);
- dbstl::register_db_env(envp);
- strmap_t *strmap = new strmap_t(dbp, envp);
- txn = dbstl::begin_txn(0, envp);
- strmap->insert(key, value);
- try {
- dbstl::commit_txn(envp);
- } catch (DbException &e) {
- std::cout << "Error on txn commit: " << e.what() << std::endl;
- dbstl::abort_txn(envp);
- return FAILURE;
- }
- dbstl::commit_txn(envp);
- return SUCCESS;
- }
- int
- count_records(strmap_t *strmap)
- {
- int count = 0;
- strmap_t::iterator itr;
- try {
- for (itr = strmap->begin(); itr != strmap->end(); ++itr)
- count++;
- } catch (DbDeadlockException &de) {
- std::cerr << "countRecords: deadlock" << std::endl;
- throw de;
- } catch (DbException &e) {
- std::cerr << "countRecords: error" << std::endl;
- std::cerr << e.what() << std::endl;
- }
- // itr's DB cursor is closed when the itr is destructed
- return (count);
- }
Add Comment
Please, Sign In to add comment