dbTalk Databases Forums  

does cursor.putCurrent work?

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


Discuss does cursor.putCurrent work? in the comp.databases.berkeley-db forum.



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

Default does cursor.putCurrent work? - 11-09-2005 , 06:48 PM






Hi,

I have a table with sorted duplicates. I would like to be able to
overwrite an existing record without having to first delete it and then
add it again. A plain:

db.put(null, key, value)

does nothing and complains that "Duplicate data items are not supported
with sorted data". Makes sense, but then I tried:

cursor = db.openCursor(null, null);
if (cursor.getSearchBoth(key, value, LockMode.DEFAULT) ==
OperationStatus.SUCCESS)
cursor.putCurrent(value);
else
db.put(null, key, value);

now there is no error, but the record does NOT get overwritten. Any
idea?

Thanks
Boris


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

Default Re: does cursor.putCurrent work? - 11-11-2005 , 12:43 PM






Hi Boris,

Since this is a table with sorted duplicates your first case above is
expected since you are trying to append (db.put is append).

In the second case I would expect the db.put to complete successfully
since you are doing a put on the current record in the cursor set.
Since you are writing the same value, why do you think the write
operation did not complete?

Ron


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

Default Re: does cursor.putCurrent work? - 11-14-2005 , 09:37 AM



You are right, it's actually because I'm writing the same value. But I
was trying to be clever: my secondary comparator works only on part of
the actual value. So I was initializing the byte buffer that I needed
to write, doing lookup (based only on a portion of it that is the same
in the old and new buffer) and then writing. However, 'getSearchBoth'
populates the 'value' DatabaseEntry with whatever is in the database,
which makes sense..

so, my bug, thanks a lot!


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.