热门关键字:  ubuntu  分区  Fedora  linux系统进程  函数

Berkeley DB C++使用实例(2)

来源: 作者: 时间:2007-12-02 Tag: 点击:

下面是主函数:
// TestBerkeleyDB.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "TestBerkeleyDB.h"
#include "db_cxx.h"
#include "icqtypes.h"
#include "icqdb.h"
#include "Person.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

//using namespace std;

bool delPeople(char *fileName, string index)
{
 Db db(NULL, 0); // Instantiate the Db object
 u_int32_t oFlags = DB_CREATE; // Open flags;
 try {
 // Open the database
 db.open(NULL, // Transaction pointer
   fileName, // Database file name
   NULL, // Optional logical database name
   DB_BTREE, // Database access method
   oFlags, // Open flags
   0); // File mode (using defaults)
   // DbException is not subclassed from std::exception, so
   // need to catch both of these.
  } catch(DbException &e) {
  // Error handling code goes here
  } catch(std::exception &e) {
  // Error handling code goes here
  }
 Dbc *cursorp;
 try {
  // Database open omitted
  // Get the cursor
  db.cursor(NULL, &cursorp, 0);
  // Set up our DBTs
  Dbt data;
  Dbt key;
  key.set_data((void*)index.c_str());
  key.set_size(index.length()+1);
 
  // Iterate over the database, deleting each record in turn.
  int ret;
  while ((ret = cursorp->get(&key, &data,
   DB_SET)) == 0) {
   cursorp->del(0);
  }
 } catch(DbException &e) {
  db.err(e.get_errno(), "Error!");
 } catch(std::exception &e) {
  db.errx("Error! %s", e.what());
 }
  // Cursors must be closed
 if (cursorp != NULL)
   cursorp->close();
 db.close(0);
 return true;
}

bool delPeople(char *fileName, uint32 index)
{
 Db db(NULL, 0); // Instantiate the Db object
 u_int32_t oFlags = DB_CREATE; // Open flags;
 try {
  // Open the database
  db.open(NULL, // Transaction pointer
   fileName, // Database file name
   NULL, // Optional logical database name
   DB_BTREE, // Database access method
   oFlags, // Open flags
   0); // File mode (using defaults)
  // DbException is not subclassed from std::exception, so
  // need to catch both of these.
 } catch(DbException &e) {
  // Error handling code goes here
 } catch(std::exception &e) {
  // Error handling code goes here
 }
 Dbc *cursorp;
 try {
  // Database open omitted
  // Get the cursor
  db.cursor(NULL, &cursorp, 0);
  // Set up our DBTs
  Dbt data;
  Dbt key;
  key.set_data(&index);
  key.set_size(sizeof(index));
 
  // Iterate over the database, deleting each record in turn.
  int ret;
  while ((ret = cursorp->get(&key, &data,
   DB_SET)) == 0) {
   cursorp->del(0);
  }
 } catch(DbException &e) {
  db.err(e.get_errno(), "Error!");
 } catch(std::exception &e) {
  db.errx("Error! %s", e.what());
 }
 // Cursors must be closed
 if (cursorp != NULL)
  cursorp->close();
 db.close(0);
 return true;
}



相关文章:
SQLite3 C/C++ 开发接口简介(API函数) 二
SQLite3 使用教学
Scaling out MySQL - Hardware today and tomorro
SQLite适用的范围
sybase cursor declare
SQL语句大全精要
用户配额
decode函数
Oracle 数据库创建表空间、创建用户指定表空间
MySQL教会我使用GnuPG验证软件包
MySQL中MyISAM引擎与InnoDB引擎性能简单测试
initdb
mysqladmin在线帮助文档
CentOS 4.7 安装Oracle 9.2.0.4的一些问题
文本如何导入oracle(sqlldr 的用法)
ORA-00600: 内部错误代码,自变量: [16201], [],
分布式Oracle的database link
install a MySQL source distribution
Mysql备份脚本(未验证)
oracle 9.2.0.1 update 9.2.0.5
每小时Dump所有mysql数据库到NAS存储设备上
Oracle SCN机制解析
Account LOCKED(TIMED)
MySQL数据库5.0的my.cnf配置选项
oracle存储过程中调用其他用户的表
修改sqlplus提示符
MYSQL建表实例
一些对Mysql DBA有用的脚本
Oracle DBA 强悍挑战OS 64位 Solaris 10-真正休
[Bugzilla]由Mysql迁移到Oracle的方法