dbTalk Databases Forums  

Why this code won't work?

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


Discuss Why this code won't work? in the comp.databases.berkeley-db forum.



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

Default Why this code won't work? - 03-01-2006 , 10:25 PM






double buff = (double )inventoryData.getPrice();
size_t size = sizeof(double)+1;
Dbt key(&buff, (u_int32_t)size);

buff = inventoryData.getBuffer();
size = inventoryData.getBufferSize();
Dbt data(buff, (u_int32_t)size);
inventoryDB.getDb().put(NULL, &key, &data, 0);

The constructor must be Dbt:bt (const Dbt&) or (void *)
but why I saw an example from sleepycat's manual which does this pg 20
of C++ reference manual

float money = 122.45;
char *description = "Grocery bill."

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


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

Default Re: Why this code won't work? - 03-01-2006 , 10:39 PM






I changed it to Dbt key((void*)&buff, sizeof(float));
and it worked okay

Is there any way that I can use a float as the key?
Thanks
Jack


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

Default Re: Why this code won't work? - 03-02-2006 , 09:10 AM



Jack,

Please use this example where money is used as a floating point key:

http://www.sleepycat.com/docs/gsg/C/...#databaseWrite

Ron


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

Default Re: Why this code won't work? - 03-02-2006 , 09:28 AM



Jack,

A couple more things:

In your code you are setting size to:
size_t size = sizeof(double)+1;

I'm not sure why you wanted to do that. I'm also not sure what you
mean by won't work.

Floats do indeed work as keys so you'll need to debug your code if you
are having problems. But you should be able to use the example in the
documentation to help you find your problem. Running though both the
example and your code through the debugger may help.

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.