dbTalk Databases Forums  

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

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss HELP!!why n="基于berkeley db的个人资料管理系统"? in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
lwu321 (Offline)
Junior Member
 
Posts: 6
Join Date: Apr 2006

Default HELP!!why n="基于berkeley db的个人资料管理系统"? - 04-23-2006 , 04:09 AM






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;
}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 );
};

//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;
}
}
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;
}
}

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;
}

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);
}


void main()
{
BDB ceshi;
wen[0].name="伯克力数据库";
wen[0].direct="c:\\bdb\\lwu1";
wen[0].miaoshu="基于berkeley db的个人资料管理系统";
ceshi.xiugai(wen[0]);
char* x0=ceshi.get();

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

}

Last edited by lwu321 : 04-23-2006 at 04:13 AM .

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.