dbTalk Databases Forums  

Re: Berkeley DB: opening and closing with functions

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


Discuss Re: Berkeley DB: opening and closing with functions in the comp.databases.berkeley-db forum.



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

Default Re: Berkeley DB: opening and closing with functions - 11-05-2003 , 10:32 PM






Your problem is simple - you are calling db_create() with the
address of a stack argument. So the DB* that you pass in to
the function DB_Open() is not changed. In other words,
change it to something like this:

int DB_Open(DB **dbHandle, char *DATABASE)
{
DB *db;

// Create the handle.
int ret = db_create(&db, NULL, 0);

if (ret==0) {
// Open the database for read only.
ret = db->open(db, NULL, DATABASE, NULL,
DB_BTREE, DB_RDONLY, 0664);
}
*dbHandle = db;
return(0);
}

Hope this helps,
--Sarge


"Anon" <usenet33 (AT) yahoo (DOT) com> wrote

Quote:
I'm writing an application that will use either a single Berkeley
database, or multiple databases, to simply access data. The
database(s) will not be modified at all.

What I'm having trouble with is that I'm trying to pass database
handles to functions that will, among other things, open and close a
database, retrieve elements from a database, etc. But I'm getting
segmentation faults when actions are performed with these passed-in
handles, and I'm not sure why. Below are my DB_Open() and DB_Close()
functions (without the full checking of the "ret" variable to keep
this post small). The DB_Open() seems to work fine, but when the
DB_Close() attempts to close the dbHandle, the app crashes.
Additionally, if I pull the contents of these functions out and place
them in-line in the main() procedure, they work fine. Any insight
would be greatly appreciated. Thank you.

/************************************************** ********
************************************************** ********/
int DB_Open(DB *dbHandle, char *DATABASE) {
// Create the handle.
int ret = db_create(&dbHandle, NULL, 0);

if (ret==0) {
// Open the database for read only.
ret = dbHandle->open(dbHandle, NULL, DATABASE, NULL,
DB_BTREE, DB_RDONLY, 0664);
}
return(0);
}

/************************************************** ********
************************************************** ********/
int DB_Close(DB *dbHandle) {
int ret = 0;

ret = dbHandle->close(dbHandle, 0);

return(0);
}



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.