Thread

Posted on Wed May 30 17:18:05 2007 by sambayer
How to use transactions with cursors?

Hi all -

I'm looking at the source code for the Perl BerkeleyDB module distributed with Berkeley DB 4.5.20 (version 0.30), and I can't figure out for the life of me how to duplicate the idiom

txn_begin() db_cursor(...txn...) do some stuff close cursor txn_commit()

in Perl. The db_cursor() function appears to use the txn associated with the DB object, which can't be right - this txn appears only to be set internally in my_db_open, and doesn't appear to be accessible, and txn_commit() is never called on it. What's up?

Thanks in advance -

Sam Bayer

Direct Responses: 5287 | Write a response
Posted on Thu May 31 21:38:50 2007 by pmarquess in response to 5272
Re: How to use transactions with cursors?
Here is the idiom translated
$env = new BerkeleyDB::Env... $db = tie %hash, BerkeleyDB::Hash,... -Env => $env, ... $txn = $env->txn_begin() $db->Txn($txn); $cursor = $db->create_cursor(); # do some stuff undef $cursor; $txn->commit();
The secret is this line
$db->Txn($txn);
It will assocuiate the transaction with all operations on the database behind the scenes.
Paul
Write a response