Using locking with BerkeleyDB

Posted on 2009-02-20
Last Modified: 2012-06-21
I am using the BerkeleyDB Perl module on Windows using ActivePerl.

I am trying to get it to work with locking.

The documentation is quite light on this and just tells you how to initalise locking,

I read through the documentation provided by Oracle for the database and am trying to mimic that to implement locking in Perl.

This is where Oracle tell you to use locking:

I have attached the code that I'm using which gives me the error:
"Can't call method "lock_id" on an undefined value at line 10."

I also tried calling lock_id() on $dbEnv and got this error:
"Can't locate object method "lock_id" via package "BerkeleyDB::Env" at l
ine 10."

Does anyone know how I should be doing it so that I can use this module with locking.
use strict;

use BerkeleyDB;

my %tData;

my $dbEnv = BerkeleyDB::Env -> new ( -Flags => DB_CREATE | DB_INIT_LOCK );

my $hDb = tie %tData , 'BerkeleyDB::Hash' , { -Env => $dbEnv , -Filename => 'tData.db' , -Flags => DB_CREATE };

#get a locker id

$hDb -> lock_id();

Open in new window

Question by:intechfs
    LVL 39

    Accepted Solution


    #To lock
    my $lock = $hDb->cds_lock();
    #To unlock
    #either $lock goes out of scope, or

    Open in new window


    Author Closing Comment

    Thanks for this.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now