HELP!!why n="基于berkeley db的个人资料管理系统"?

HELP!!why n="基于berkeley db的个人资料管理系统"?

Post by lwu32 » Mon, 24 Apr 2006 18:09:59



why n!="伯克力数据库" but
="基于berkeley
db的个人资料管理系统"?

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//only this head should include for use bdb.
#include "db_cxx.h"
#include "db.h"      

#define N 200
typedef struct wendang{
        char* name;
        char* direct;
        char* miaoshu;

Quote:}WEN;

WEN wen[3];

class BDB
{
public:
        Db db;

private:
        u_int32_t oFlags;
        void close();
        Dbt keyn;
        Dbt keyd;
        Dbt keym;
Dbt datan,datad,datam;  
public:
BDB();
// Our destructor just calls our private close method.
~BDB() { close(); }

char* get();

xiugai(WEN xindata );

Quote:};

//implementation for the constructor

BDB :: BDB()
: db(NULL, 0), // Instantiate Db object
oFlags(DB_CREATE),
           keyn("keywordn",  strlen("keywordn") + 1),
           keyd("keywordd",  strlen("keywordd") + 1),
           keym("keywordm",  strlen("keywordm") + 1)

{

try
        {
                db.open(NULL, // Transaction pointer
"wendang.db", // Database file name
NULL, // Optional logical database name
DB_BTREE, // Database access method
oFlags, // Open flags
0); // File mode (using defaults)
        }
        catch(DbException &e)
        {
// Error handling code goes here
std::cerr << e.what() << std::endl;
        }
catch(std::exception &e)
        {
// Error handling code goes here
std::cerr << e.what() << std::endl;
        }

Quote:}

void BDB::close()
{
// Close the db
try
        {
db.close(0);
// DbException is not subclassed from std::exception, so
// need to catch both of these.
        }
catch(DbException &e)
        {
std::cerr << e.what() << std::endl;
        }
catch(std::exception &e)
        {
std::cerr << e.what() << std::endl;
        }

Quote:}

char* BDB::get()
{
WEN x;
int rett=db.get(NULL, &keyn, &datan, 0);
char *n=(char*)datan.get_data();
x.name=n;
db.get(NULL, &keyd, &datad, 0);
char *d=(char*)datad.get_data();
x.direct=d;
db.get(NULL, &keym, &datam, 0);
char *m=(char*)datam.get_data();
x.miaoshu=m;
return n;

Quote:}

BDB::xiugai(WEN xindata)
{
int rettt=db.del(NULL, &keyn, 0);
db.del(NULL, &keyd, 0);
db.del(NULL, &keym, 0);
Dbt datan(xindata.name, strlen(xindata.name)+1);
Dbt datad(xindata.direct, strlen(xindata.direct)+1);
Dbt datam(xindata.miaoshu, strlen(xindata.miaoshu)+1);
// data.set_data(xindata);
// data.set_ulen(sizeof(xindata));
// data.set_flags(DB_DBT_USERMEM);  

int ret=  db.put(NULL, &keyn, &datan, DB_NOOVERWRITE);
db.put(NULL, &keyd, &datad, DB_NOOVERWRITE);
db.put(NULL, &keym, &datam, DB_NOOVERWRITE);

Quote:}

void main()
{
        BDB ceshi;
        wen[0].name="&#20271;&#20811;&#21147;&#25968;&#25454;&#24211;";
        wen[0].direct="c:\\bdb\\lwu1";
wen[0].miaoshu="&#22522;&#20110;berkeley
db&#30340;&#20010;&#20154;&#36164;&#26009;&#31649;&#29702;&#31995;&#32479;";
ceshi.xiugai(wen[0]);
char* x0=ceshi.get();

        printf("%s\n",x0);

Quote:}

--
lwu321
------------------------------------------------------------------------
lwu321's Profile: http://www.dbtalk.net/m169
View this thread: http://www.dbtalk.net/t301569