I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2007-05-30 14:18:05-07 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 2007-05-31 18:38:50-07 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
Direct Responses: Write a response