Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: can't manage to use BerkeleyDB::Env

by Anonymous Monk
on Aug 23, 2012 at 10:23 UTC ( [id://989263]=note: print w/replies, xml ) Need Help??


in reply to can't manage to use BerkeleyDB::Env

What am I missing?

Don't mix DB_File with BerkeleyDB, DB_File doesn't use any Env

  • Comment on Re: can't manage to use BerkeleyDB::Env

Replies are listed 'Best First'.
Re^2: can't manage to use BerkeleyDB::Env
by grondilu (Friar) on Aug 23, 2012 at 10:34 UTC

    Ok. Well, to tell the whole story I only used DB_File in this simple example.

    The thing is that I already have a db which I know has an environnement in it (I've already opened it with an other perl program). What I wanted to do was to retrieve some data from its Env, so I wanted to explore a bit the structure of an BerkeleyDB::Env class.

    So I tried to create a "detached" env:

    use BerkeleyDB; my $env = new BerkeleyDB::Env -Home => "/tmp" or die "could not create env";

    And then I do raise the "could not create" exception.

    Shouldn't it be possible to create a brand new environnement, detached from any database?

      Well, according to the docs, it is, provided you follow the docs (use flags)
      #!/usr/bin/perl -- use strict; use warnings; use Data::Dump; use BerkeleyDB; for my $opts ( [], [-Flags => DB_CREATE| DB_INIT_CDB | DB_INIT_MPOOL] + ){ my $env = BerkeleyDB::Env->new( -Home => './home', @$opts, ) or warn "cannot open environment: $BerkeleyDB::Error\n"; dd $env, [ glob './home/*' ]; } __END__

      On first run it doesn't exist, so first try, without flags, fails -- you need flags to initialize

      $ perl berkeleydb.env.pl cannot open environment: No such file or directory (undef, []) ( bless([12346044], "BerkeleyDB::Env"), [ "./home/__db.001", "./home/__db.002", "./home/__db.003", "./home/__db.004", ], )

      On second run both tries work, because its already initialized

      $ perl berkeleydb.env.pl ( bless([10087228], "BerkeleyDB::Env"), [ "./home/__db.001", "./home/__db.002", "./home/__db.003", "./home/__db.004", ], ) ( bless([12336228], "BerkeleyDB::Env"), [ "./home/__db.001", "./home/__db.002", "./home/__db.003", "./home/__db.004", ], )

        Ok, thanks.

        I was mis-leaded by the following statement in the BerkeleyDB man page:

        « All the parameters to the BerkeleyDB::Env constructor are optional. »

        Well, not so true then.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://989263]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 17:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found