Skip to Main Content

Berkeley DB Family

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Segmentation fault error in simple program. Please help

695543Apr 9 2009 — edited Apr 15 2009
Hello!
I'm getting a Segmentation fault error on Linux and have no idea why. Please, could someone help me?

<code>

#include <db_cxx.h>
#include <iostream>
#include <string>


using namespace std;

int main() {

try {
Db db(NULL, 0);
u_int32_t oFlags = DB_CREATE;

db.open(NULL,"test.db",NULL,DB_BTREE,oFlags,0);

string keystring("klucz");
string datastring("wartosc");

Dbt key((void*)keystring.c_str(),sizeof(keystring.c_str())+1);
Dbt data(&datastring,sizeof(datastring));
int ret;
ret = db.put(NULL, &key, &data, DB_NOOVERWRITE);

if (ret == DB_KEYEXIST) {
cout << "Key exist." << endl;
}

Dbc *cursorp;
db.cursor(NULL,&cursorp,0);

Dbt Key_;
Dbt Elem_;

while ((ret = cursorp->get(&Key_, &Elem_, DB_NEXT)) == 0) {
string str =(string )Elem_.get_data();
cout << *str << endl;
}

if(cursorp != NULL)
cursorp->close();

db.close(0);
} catch(DbException &e) {

} catch(exception &e) {
cout << e.what();
}

return 0;
}

</code>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 13 2009
Added on Apr 9 2009
3 comments
1,933 views