Skip to Main Content

Berkeley DB Family

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Read-Modify-Write Cursors & Secondary Databases

562069Apr 13 2007 — edited May 9 2007
Can I use a read-modify-write cursor on a secondary database?

I have a transactional data store with a secondary database, i.e. secondary key. I want to iterate over the records using a cursor on the secondary key. When I find the record of interest I want to update the associated/current record using the cursor.

I have done the following:
1. Begin a transaction using DBenv::txn_begin specifying DB_READ_COMMITTED
2. Create a cursor using Db::cursor specifying the transaction and the DB_READ_COMMITTED flag.
3. Start iteration using DBcursor::get specifying DB_FIRST and DB_RMW flags.
4. Continue iteration using DBcursor::get specifying DB_NEXT and DB_RMW flags.
5. After finding the record of interest…
6. Update current record using DBcursor::put specifying DB_CURRENT.
7. Close the cursor.
8. Commit the transaction.
9. Close the transaction.

The above works if I use the primary database in step 3 to create the cursor. However, if I switch to using the secondary database to create the cursor (really want to iterate over secondary key), I get an error in step 7 when I try to update the record. The error message returned by the exception is “Dbc::put: Invalid argument”. However, if I use the Berkeley debug library (libdb45d.lib) and trace down into the Berkeley code I see error text “DBcursor->put forbidden on secondary indices”.

I would think many Berkeley DB clients would want to use read-modify-write cursors using a secondary key. Is there some way to do this successfully?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 6 2007
Added on Apr 13 2007
4 comments
1,983 views