dbTalk Databases Forums  

Another newbie's question (please help)

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


Discuss Another newbie's question (please help) in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
YAN (Yet Another Newbie)
 
Posts: n/a

Default Another newbie's question (please help) - 12-16-2005 , 04:00 AM






Hello,

I have created 4 databases (main db, and 3 secondary db)
3 secondary db is used to search on spesific "column" (book's title,
book's author, and book's ISBN).
I have problem in creating "log", i can't get/see the error on the
spesified file (err.log).
I tried to create the error just to see if it's being written to the
spesified file, i deleted title.db.
i was supposed to see the error on the err.log and then the application
prompt me with a dialog box, but the application just crashed.
what's wrong with this code ?

thanks in advance, and sorry for my poor english.

----------------------------------------------------------------------------------------------------------------------
ret = db_env_create(&dbenv, 0);
if (ret != 0) {
MessageBox(NULL, "Error Creating Environment!", "Error!", MB_OK);
return (ret);
}

ret = dbenv->open(dbenv, 0, DB_INIT_LOCK | DB_INIT_MPOOL | DB_CREATE |
DB_PRIVATE, 0);
if (ret != 0) {
MessageBox(NULL, "Error Opening Environment!", "Error!", MB_OK);
return (ret);
}

ret = db_create(&title_dbp, NULL, 0);
if (ret != 0) {
MessageBox(NULL, "Error Creating Primary Database!", "Error!", MB_OK);
return (ret);
}

error_file_pointer = fopen("err.log", "rw+");
if (error_file_pointer == NULL) {
MessageBox(NULL, "Error Opening Log File!", "Error!", MB_OK);
return (-1);
}

/* Set up error handling for this database */
dbenv->set_errfile(dbenv, error_file_pointer);
dbenv->set_errpfx(dbenv, "error: ");

/* Database open flags */
flags = DB_CREATE; /* If the database does not exist, create it.*/

/* open the database */
ret = title_dbp->open(title_dbp, /* DB structure pointer */
NULL, /* Transaction pointer */
"title.db", /* On-disk file that holds the database. */
NULL, /* Optional logical database name */
DB_BTREE, /* Database access method */
flags, /* Open flags */
0); /* File mode (using defaults) */
if (ret != 0) {
dbenv->err(dbenv, ret, "Error Opening Database!");
MessageBox(NULL, "Error Opening Database!", "Error!", MB_OK);
return (ret);
}
----------------------------------------------------------------------------------------------------------------------


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

Default Re: Another newbie's question (please help) - 12-19-2005 , 08:31 AM






I'm not sure what you are asking?

It looks like you have set up verbose error messages. What is
error_file_pointer defined as? If you explain again what the problem
is and
post your code here, I'll take a look at it.

Are you saying that you are not getting any error conditions when you
delete the
database and try to open it after removing it?

Have you looked at the sample applications to see how this is set up?

Ron


Reply With Quote
  #3  
Old   
YAN (Yet Another Newbie)
 
Posts: n/a

Default Re: Another newbie's question (please help) - 12-20-2005 , 12:58 AM



Hello Mr. Ron,
Thank you very much for your response.

i'm sorry i didn't include variable declaration in my code,
error_file_pointer is:
FILE *error_file_pointer;

my situation is like this, i want my application to write all error to
error_file_pointer (which is err.log).
i use dbenv->err to do this, but before that i already set this up:

error_file_pointer = fopen("err.log", "rw+");
if (error_file_pointer == NULL) {
MessageBox(NULL, "Error Opening Log File!", "Error!", MB_OK);
return (-1);


}

dbenv->set_errfile(dbenv, error_file_pointer);
dbenv->set_errpfx(dbenv, "error: ");

the problem is i never get the error log, file err.log contains
nothing. my application just went crashing whenever there's an error.
i try to isolate the problem and i found out that the line
dbenv->set_errfile(dbenv, error_file_pointer); causing the problem.
i have tried to change error_file_pointer to stderr, but the same.. my
application just crashed.
i write this function to replace dbenv->err:

void err_handler(DB_ENV *dbenv, FILE *error_file_pointer, char *err)
{
SYSTEMTIME sysTime;
GetLocalTime(&sysTime);

MessageBox(NULL, err, "Error", MB_OK);

fprintf(error_file_pointer, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d:%2.2d\t
%s\n",
sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour,
sysTime.wMinute, sysTime.wSecond, err);
_fcloseall();

dbenv->close(dbenv, 0);
dbenv = NULL;
}

with this function i can get error log like this:
20/12/2005 13:22:21 DB_NOTFOUND: No matching key/data pair found

but still this is not what i want. i want to use all existing functions
provided by BerkeleyDB as i believe it's much better than mine.

i have read documentations and sample applications about this, but find
nothing. i tried to copy and paste all the code spesified in the sample
code,
but didn't fix my problem (for example this one:
http://www.sleepycat.com/docs/ref/env/create.html)

Please help me to resolve my problem.
Again thank you very much Mr. Ron.


Reply With Quote
  #4  
Old   
YAN (Yet Another Newbie)
 
Posts: n/a

Default Re: Another newbie's question (please help) - 12-27-2005 , 10:03 PM



The problem is fixed now.
As suggested by Mr. Keith last night, i check the Berkeley DB's library
being linked by my application, and changed it to a compiled db_small's
lib.
Everything runs exactly what i want now.

Thanks a lot Mr. Keith & Mr. Ron!


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.