DB_File and seq function (using MLDBM) 
Author Message
 DB_File and seq function (using MLDBM)

Hi,

I really do not see how this works (I mean internally)

  use DB_File ;
  $X = tie %hash, DB_File, $filename, $flags, $mode, $DB_BTREE ;
  $status = $X->seq($key, $value , $flags);

What I understood is that seq is the C function but it appears
nowhere (even for prototyping) in DB_File.pm. So where is the magic?

What I am trying to do is to have MLDBM work with db_btree so
I can play with ordered hash of hashes.
And it works fine with simple stuff but could not use
any of these OO-like functions (seq, put, .....)

  my( $X) = tie( %db, "MLDBM", 'foo', O_CREAT|O_RDWR, 0644, $DB_File::DB_BTREE)
   or die "Cannot tie foo ($!)";
  my( $key, $value, $status);
  $key = 'b';
  $status = $X->DB_File::seq( $key, $value,  R_CURSOR ); #this line 45
  print " $key, $value\n";

And I obtain the error
   db is not of type DB_File at ./foo.pl line 45.

Any help appreciated. Thanx in advance.

Frederic



Sat, 04 Jul 1998 03:00:00 GMT  
 DB_File and seq function (using MLDBM)
  [ mailed and posted ]



Quote:

>What I understood is that seq is the C function but it appears
>nowhere (even for prototyping) in DB_File.pm. So where is the magic?

Should be XSsive code.

Quote:
>  my( $X) = tie( %db, "MLDBM", 'foo', O_CREAT|O_RDWR, 0644, $DB_File::DB_BTREE)
>   or die "Cannot tie foo ($!)";
>  my( $key, $value, $status);
>  $key = 'b';
>  $status = $X->DB_File::seq( $key, $value,  R_CURSOR ); #this line 45
>  print " $key, $value\n";

>And I obtain the error
>   db is not of type DB_File at ./foo.pl line 45.


hardcodes its name in the check leading to that error, so it effectively
*prevents* inheritance.

The only other means of elegantly getting what you want is to implement some
code to do the delegation in MLDBM.  Something along the lines of
an AUTOLOAD sub that will forward the DB_File sub requests.

That said, if you relish inelegance, making the alleged line 45 into:

   $status = $X->{db}->seq(...)

should work flawlessly, but violates every modicum of OO responsibility.

 - Sarathy.



Sun, 05 Jul 1998 03:00:00 GMT  
 DB_File and seq function (using MLDBM)
: Hi,

: I really do not see how this works (I mean internally)

:   use DB_File ;
:   $X = tie %hash, DB_File, $filename, $flags, $mode, $DB_BTREE ;
:   $status = $X->seq($key, $value , $flags);

: What I understood is that seq is the C function but it appears
: nowhere (even for prototyping) in DB_File.pm. So where is the magic?

It is defined in DB_File.xs. As seq should only be accessed as a method
via the $X object it is not necessary to mention it in DB_File.pm

: What I am trying to do is to have MLDBM work with db_btree so
: I can play with ordered hash of hashes.

What is MLDBM?

: And it works fine with simple stuff but could not use
: any of these OO-like functions (seq, put, .....)

:   my( $X) = tie( %db, "MLDBM", 'foo', O_CREAT|O_RDWR, 0644, $DB_File::DB_BTREE)
                         ^^^^^ ???

What are you doing here? Changing "MLDBM" to "DB_File" makes the script
work.

:    or die "Cannot tie foo ($!)";
:   my( $key, $value, $status);
:   $key = 'b';
:   $status = $X->DB_File::seq( $key, $value,  R_CURSOR ); #this line 45
:   print " $key, $value\n";

: And I obtain the error
:    db is not of type DB_File at ./foo.pl line 45.

That is because $X has been blessed into the "MLDBM" package, not the
DB_File package.

: Any help appreciated. Thanx in advance.

: Frederic

Paul



Sun, 05 Jul 1998 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. persistence problems using DB_File and MLDBM

2. DB_File: how to use seq() on a btree?

3. MLDBM qw(DB_File Storable) & concurrent access

4. MLDBM qw(DB_File Storable) & concurrent access

5. MLDBM/DB_File, file size, deleting records

6. DB_file, MLDBM and core dumped

7. MLDBM and each/keys functions

8. Using the hash DB_File uses, after untie it??

9. taint error using MLDBM::Sync

10. Using another dbm with MLDBM.pm

11. Problem using MLDBM

12. Using MLDBM

 

 
Powered by phpBB® Forum Software