dbTalk Databases Forums  

Is this ok?help,where are the errors?

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


Discuss Is this ok?help,where are the errors? 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 Is this ok?help,where are the errors? - 05-07-2006 , 12:01 AM






//lwu.h
class BDB
{
public:
Db db;
char *keyword[N];
private:
u_int32_t oFlags;
void close();
Dbt key[N],data[N];//表示最多只能有N对数据对

public:
BDB();
~BDB() { close(); }
char* get(int g);
xiugai(char* xindata,int x );
add(char* ndata,int a);
};

BDB :: BDB()
: db(NULL, 0),
oFlags(DB_CREATE)
{
int j;
for(j=0;j<N;j++)//keyword[]跟key[]
{
char tmp[100];
itoa(j,tmp,10);
keyword[j]=strcat(tmp,"keyword");
key[j].set_data(keyword[j]);
key[j].set_size(strlen(keyword[j]) + 1);
key[j].set_flags(DB_DBT_USERMEM);
}
try
{
db.open(NULL, // Transaction pointer
"bdb.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)
{
std::cerr << e.what() << std::endl;
}
catch(std::exception &e)
{
std::cerr << e.what() << std::endl;
}
}
void BDB::close()
{
try
{
db.close(0);
}
catch(DbException &e)
{
std::cerr << e.what() << std::endl;
}
catch(std::exception &e)
{
std::cerr << e.what() << std::endl;
}
}

char *BDB::get(int g)
{
key[g].set_flags(DB_DBT_USERMEM);

int rett= db.get(NULL, &key[g], &data[g], 0);
char *x=(char*)data[g].get_data();
//printf("db: %s and %s: data stored.\n", data[g].get_data(),keyword[g]);
return x;
}

BDB::xiugai(char* xindata,int x)
{
key[x].set_flags(DB_DBT_USERMEM);
int rettt=db.del(NULL, &key[x], 0);
data[x].set_data(xindata);
data[x].set_size(strlen(xindata) + 1);
data[x].set_flags(DB_DBT_USERMEM);

db.put(NULL, &key[x], &data[x], DB_NOOVERWRITE);
// printf("db: %s and %s: data stored.\n", data[x].get_data(),keyword[x]);
}
BDB::add(char* ndata,int a)

{
key[a].set_flags(DB_DBT_USERMEM);

//Dbt data[a](ndata, strlen(ndata) + 1);
data[a].set_data(ndata);
data[a].set_size(strlen(ndata) + 1);
data[a].set_flags(DB_DBT_USERMEM);
int ret=db.put(NULL, &key[a], &data[a], DB_NOOVERWRITE);

}

Reply With Quote
  #2  
Old   
Alex
 
Posts: n/a

Default Re: Is this ok?help,where are the errors? - 05-08-2006 , 10:08 PM






What is the problem exactly? Does your code sample compile?

If so and it is a runtime problem, what behavior do you expect? What
behavior do you see?


Reply With Quote
  #3  
Old   
lwu321 (Offline)
Junior Member
 
Posts: 6
Join Date: Apr 2006

Default 05-10-2006 , 09:28 AM



Quote:
Originally Posted by Alex
What is the problem exactly? Does your code sample compile?

If so and it is a runtime problem, what behavior do you expect? What
behavior do you see?
compiling was no error!I want to use "key[N],data[N]" to record N pare datas.But the code couldn't get it.

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 - 2010, Jelsoft Enterprises Ltd.