dbTalk Databases Forums  

Db::put() throws win32 unhandled exception

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


Discuss Db::put() throws win32 unhandled exception in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ryoungdev@gmail.com
 
Posts: n/a

Default Db::put() throws win32 unhandled exception - 03-10-2006 , 07:32 AM






Hello all,

Win2003, VS2005, BerkeleyDb 4.4 recompiled with VS2005

I have some pretty simple code here based on the BerkeleyDb docs:

int main()
{
char *pathtoDb = "c:\\dev\\dbenv\\mydb.db";
char *description = "Grocery bill";
float money = 123.45;

Db mydb(NULL, 0);
mydb.set_error_stream(&std::cerr);
mydb.open(NULL, pathToDb, NULL, DB_BTREE, 0, 0);

Dbt key(&money, sizeof(float));
Dbt data(description, strlen(description) + 1);

try
{
int retcode = mydb.put(NULL, &key, &data, DB_NOOVERWRITE);
if ( DB_KEYEXIST == retcode )
db.err(retcode, "Duplicate key" );
}
catch ( DbException &e )
{
std::cout << "Error: " << e.what() << std::endl;
}
catch ( std::exception &e )
{
// output e.what()
}

mydb.close(0);
return (0);
}

mydb.db started off with no data in it. I run the app once and the call
to Db:ut() is 0. I run it twice so that the duplicate key exception
will be caught, but an unhandled exception is thrown "Access violation
writing location.."

Changing the "flags" parameter in Db:ut() from DB_NOOVERWRITE to 0
and the application runs fine. So I'm assuming the duplicate key
detection specified by DB_NOOVERWRITE is functioning correctly - and
that I can't catch the exception correctly.

Any help here is appreciated,
Ron


Reply With Quote
  #2  
Old   
Joseph Bruni
 
Posts: n/a

Default Re: Db::put() throws win32 unhandled exception - 03-28-2006 , 11:23 PM







Did your database already exist? Or did you forget to add the DB_CREATE
flag to your call to DB->open?
-Joe




"ryoungdev (AT) gmail (DOT) com" <ryoungdev (AT) gmail (DOT) com> wrote:
Quote:

Hello all,

Win2003, VS2005, BerkeleyDb 4.4 recompiled with VS2005

I have some pretty simple code here based on the BerkeleyDb docs:

int main()
{
char *pathtoDb = "c:\\dev\\dbenv\\mydb.db";
char *description = "Grocery bill";
float money = 123.45;

Db mydb(NULL, 0);
mydb.set_error_stream(&std::cerr);
mydb.open(NULL, pathToDb, NULL, DB_BTREE, 0, 0);

Dbt key(&money, sizeof(float));
Dbt data(description, strlen(description) + 1);

try
{
int retcode = mydb.put(NULL, &key, &data, DB_NOOVERWRITE);
if ( DB_KEYEXIST == retcode )
db.err(retcode, "Duplicate key" );
}
catch ( DbException &e )
{
std::cout << "Error: " << e.what() << std::endl;
}
catch ( std::exception &e )
{
// output e.what()
}

mydb.close(0);
return (0);
}

mydb.db started off with no data in it. I run the app once and the call
to Db:ut() is 0. I run it twice so that the duplicate key exception
will be caught, but an unhandled exception is thrown "Access violation
writing location.."

Changing the "flags" parameter in Db:ut() from DB_NOOVERWRITE to 0
and the application runs fine. So I'm assuming the duplicate key
detection specified by DB_NOOVERWRITE is functioning correctly - and
that I can't catch the exception correctly.

Any help here is appreciated,
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.