dbTalk Databases Forums  

getting data

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


Discuss getting data in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ale
 
Posts: n/a

Default getting data - 06-08-2006 , 02:44 AM






Hi, this code:
Db berk(NULL,0);
if (berk.open(NULL,"/tmp/mybase.db",NULL,DB_BTREE,DB_CREATE,0))
std::cout << "error opening" << std::endl;


char * c_data ="fun";
int i_key = 777;

Dbt key(&i_key,sizeof(i_key)),
data(c_data,sizeof(char) * (strlen(c_data)+1));
if (berk.put(NULL,&key,&data,NULL)!=0)
std::cout << "error putting" << std::endl;

if (berk.sync(NULL)!=0)
std::cout << "error sync" << std::endl;

if (berk.close(NULL)!=0)
std::cout << "error close" << std::endl;


Db berk2(NULL,0);

if (berk2.open(NULL,"/tmp/mybase.db",NULL,DB_BTREE,NULL,0))
std::cout << "error opening" << std::endl;

c_data = "nuf";

Dbt key_r, data_r;
key_r.set_data(&i_key);
key_r.set_ulen(sizeof(i_key));
int res;
try {
res =berk2.get(NULL,&key_r,&data_r,0);
} catch (DbException &e) {
std::cout << "except " <<e.what() << std::endl;
}
if (res == DB_NOTFOUND)
std::cout << "error getting" << std::endl;
else {
c_data = (char *) data_r.get_data();
std::cout << "value: " <<c_data <<std::endl;
}

berk2.close(NULL);

always return "error getting", without throwing any exception. Why?


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