4 unshift @INC, '../lib' if -d '../lib' ;
5 require Config; import Config;
6 if ($Config{'extensions'} !~ /\bDB_File\b/) {
7 print "1..0 # Skip: DB_File was not built\n";
22 print "not " unless $result ;
28 my(@a) = unpack ("C*", $a) ;
29 my(@b) = unpack ("C*", $b) ;
31 my $len = (@a > @b ? @b : @a) ;
34 foreach $i ( 0 .. $len -1) {
35 return $a[$i] - $b[$i] if $a[$i] != $b[$i] ;
48 my $filename = shift ;
50 open ($fh, ">$filename") || die "Cannot open $filename: $!" ;
51 my $real_stdout = select($fh) ;
52 return bless [$fh, $real_stdout ] ;
66 #local $/ = undef unless wantarray ;
67 open(CAT,$file) || die "Cannot open $file: $!";
70 wantarray ? @result : join("", @result) ;
76 #local $/ = undef unless wantarray ;
77 open(CAT,$file) || die "Cannot open $file: $!";
81 wantarray ? @result : join("", @result) ;
85 my $Dfile = "dbbtree.tmp";
90 # Check the interface to BTREEINFO
92 my $dbh = new DB_File::BTREEINFO ;
93 ok(1, ! defined $dbh->{flags}) ;
94 ok(2, ! defined $dbh->{cachesize}) ;
95 ok(3, ! defined $dbh->{psize}) ;
96 ok(4, ! defined $dbh->{lorder}) ;
97 ok(5, ! defined $dbh->{minkeypage}) ;
98 ok(6, ! defined $dbh->{maxkeypage}) ;
99 ok(7, ! defined $dbh->{compare}) ;
100 ok(8, ! defined $dbh->{prefix}) ;
102 $dbh->{flags} = 3000 ;
103 ok(9, $dbh->{flags} == 3000) ;
105 $dbh->{cachesize} = 9000 ;
106 ok(10, $dbh->{cachesize} == 9000);
108 $dbh->{psize} = 400 ;
109 ok(11, $dbh->{psize} == 400) ;
111 $dbh->{lorder} = 65 ;
112 ok(12, $dbh->{lorder} == 65) ;
114 $dbh->{minkeypage} = 123 ;
115 ok(13, $dbh->{minkeypage} == 123) ;
117 $dbh->{maxkeypage} = 1234 ;
118 ok(14, $dbh->{maxkeypage} == 1234 );
120 $dbh->{compare} = 1234 ;
121 ok(15, $dbh->{compare} == 1234) ;
123 $dbh->{prefix} = 1234 ;
124 ok(16, $dbh->{prefix} == 1234 );
126 # Check that an invalid entry is caught both for store & fetch
127 eval '$dbh->{fred} = 1234' ;
128 ok(17, $@ =~ /^DB_File::BTREEINFO::STORE - Unknown element 'fred' at/ ) ;
129 eval '$q = $dbh->{fred}' ;
130 ok(18, $@ =~ /^DB_File::BTREEINFO::FETCH - Unknown element 'fred' at/ ) ;
132 # Now check the interface to BTREE
134 ok(19, $X = tie(%h, 'DB_File',$Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE )) ;
136 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
137 $blksize,$blocks) = stat($Dfile);
138 ok(20, ($mode & 0777) == ($^O eq 'os2' ? 0666 : 0640) || $^O eq 'amigaos' || $^O eq 'MSWin32');
140 while (($key,$value) = each(%h)) {
145 $h{'goner1'} = 'snork';
148 ok(22, $h{'abc'} eq 'ABC' );
149 ok(23, ! defined $h{'jimmy'} ) ;
150 ok(24, ! exists $h{'jimmy'} ) ;
151 ok(25, defined $h{'abc'} ) ;
154 $h{'jkl','mno'} = "JKL\034MNO";
155 $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
159 $X->STORE('b', 'B') ;
172 $h{'goner2'} = 'snork';
176 # IMPORTANT - $X must be undefined before the untie otherwise the
177 # underlying DB close routine will not get called.
181 # tie to the same file again
182 ok(26, $X = tie(%h,'DB_File',$Dfile, O_RDWR, 0640, $DB_BTREE)) ;
184 # Modify an entry from the previous tie
205 $h{'goner3'} = 'snork';
208 $X->DELETE('goner3');
211 @values = values(%h);
213 ok(27, $#keys == 29 && $#values == 29) ;
216 while (($key,$value) = each(%h)) {
217 if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
219 $i++ if $key eq $value;
225 @keys = ('blurfl', keys(%h), 'dyick');
226 ok(29, $#keys == 31) ;
228 #Check that the keys can be retrieved in order
230 my @c = sort lexical @b ;
231 ok(30, ArrayCompare(\@b, \@c)) ;
234 ok(31, $h{'foo'} eq '' ) ;
237 #ok(32, $h{''} eq 'bar' );
240 # check cache overflow and numeric keys and contents
242 for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
243 for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
246 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
247 $blksize,$blocks) = stat($Dfile);
250 @h{0..200} = 200..400;
252 ok(35, join(':',200..400) eq join(':',@foo) );
254 # Now check all the non-tie specific stuff
257 # Check R_NOOVERWRITE flag will make put fail when attempting to overwrite
258 # an existing record.
260 $status = $X->put( 'x', 'newvalue', R_NOOVERWRITE) ;
261 ok(36, $status == 1 );
263 # check that the value of the key 'x' has not been changed by the
265 ok(37, $h{'x'} eq 'X' );
268 $status = $X->put('key', 'value') ;
269 ok(38, $status == 0 );
271 #check that previous put can be retrieved
273 $status = $X->get('key', $value) ;
274 ok(39, $status == 0 );
275 ok(40, $value eq 'value' );
277 # Attempting to delete an existing key should work
279 $status = $X->del('q') ;
280 ok(41, $status == 0 );
281 #$status = $X->del('') ;
282 #ok(42, $status == 0 );
285 # Make sure that the key deleted, cannot be retrieved
286 ok(43, ! defined $h{'q'}) ;
287 ok(44, ! defined $h{''}) ;
292 ok(45, $X = tie(%h, 'DB_File',$Dfile, O_RDWR, 0640, $DB_BTREE ));
294 # Attempting to delete a non-existant key should fail
296 $status = $X->del('joe') ;
297 ok(46, $status == 1 );
299 # Check the get interface
301 # First a non-existing key
302 $status = $X->get('aaaa', $value) ;
303 ok(47, $status == 1 );
305 # Next an existing key
306 $status = $X->get('a', $value) ;
307 ok(48, $status == 0 );
308 ok(49, $value eq 'A' );
313 # use seq to find an approximate match
316 $status = $X->seq($key, $value, R_CURSOR) ;
317 ok(50, $status == 0 );
318 ok(51, $key eq 'key' );
319 ok(52, $value eq 'value' );
321 # seq when the key does not match
324 $status = $X->seq($key, $value, R_CURSOR) ;
325 ok(53, $status == 1 );
328 # use seq to set the cursor, then delete the record @ the cursor.
332 $status = $X->seq($key, $value, R_CURSOR) ;
333 ok(54, $status == 0 );
334 ok(55, $key eq 'x' );
335 ok(56, $value eq 'X' );
336 $status = $X->del(0, R_CURSOR) ;
337 ok(57, $status == 0 );
338 $status = $X->get('x', $value) ;
339 ok(58, $status == 1 );
341 # ditto, but use put to replace the key/value pair.
344 $status = $X->seq($key, $value, R_CURSOR) ;
345 ok(59, $status == 0 );
346 ok(60, $key eq 'y' );
347 ok(61, $value eq 'Y' );
349 $key = "replace key" ;
350 $value = "replace value" ;
351 $status = $X->put($key, $value, R_CURSOR) ;
352 ok(62, $status == 0 );
353 ok(63, $key eq 'replace key' );
354 ok(64, $value eq 'replace value' );
355 $status = $X->get('y', $value) ;
356 ok(65, 1) ; # hard-wire to always pass. the previous test ($status == 1)
357 # only worked because of a bug in 1.85/6
359 # use seq to walk forwards through a file
361 $status = $X->seq($key, $value, R_FIRST) ;
362 ok(66, $status == 0 );
366 while (($status = $X->seq($key, $value, R_NEXT)) == 0)
368 ($ok = 0), last if ($previous cmp $key) == 1 ;
371 ok(67, $status == 1 );
374 # use seq to walk backwards through a file
375 $status = $X->seq($key, $value, R_LAST) ;
376 ok(69, $status == 0 );
380 while (($status = $X->seq($key, $value, R_PREV)) == 0)
382 ($ok = 0), last if ($previous cmp $key) == -1 ;
383 #print "key = [$key] value = [$value]\n" ;
386 ok(70, $status == 1 );
390 # check seq FIRST/LAST
396 ok(72, $status == 0 );
403 ok(73, $status != 0 );
411 # Now try an in memory file
412 ok(74, $Y = tie(%h, 'DB_File',undef, O_RDWR|O_CREAT, 0640, $DB_BTREE ));
414 # fd with an in memory file should return failure
416 ok(75, $status == -1 );
423 my $bt = new DB_File::BTREEINFO ;
424 $bt->{flags} = R_DUP ;
425 ok(76, $YY = tie(%hh, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $bt )) ;
427 $hh{'Wall'} = 'Larry' ;
428 $hh{'Wall'} = 'Stone' ; # Note the duplicate key
429 $hh{'Wall'} = 'Brick' ; # Note the duplicate key
430 $hh{'Wall'} = 'Brick' ; # Note the duplicate key and value
431 $hh{'Smith'} = 'John' ;
432 $hh{'mouse'} = 'mickey' ;
434 # first work in scalar context
435 ok(77, scalar $YY->get_dup('Unknown') == 0 );
436 ok(78, scalar $YY->get_dup('Smith') == 1 );
437 ok(79, scalar $YY->get_dup('Wall') == 4 );
439 # now in list context
440 my @unknown = $YY->get_dup('Unknown') ;
441 ok(80, "@unknown" eq "" );
443 my @smith = $YY->get_dup('Smith') ;
444 ok(81, "@smith" eq "John" );
447 my @wall = $YY->get_dup('Wall') ;
449 @wall{@wall} = @wall ;
450 ok(82, (@wall == 4 && $wall{'Larry'} && $wall{'Stone'} && $wall{'Brick'}) );
454 my %unknown = $YY->get_dup('Unknown', 1) ;
455 ok(83, keys %unknown == 0 );
457 my %smith = $YY->get_dup('Smith', 1) ;
458 ok(84, keys %smith == 1 && $smith{'John'}) ;
460 my %wall = $YY->get_dup('Wall', 1) ;
461 ok(85, keys %wall == 3 && $wall{'Larry'} == 1 && $wall{'Stone'} == 1
462 && $wall{'Brick'} == 2);
469 # test multiple callbacks
474 $dbh1 = new DB_File::BTREEINFO ;
476 $dbh1->{compare} = sub { $_[0] <=> $_[1] } ; }
478 $dbh2 = new DB_File::BTREEINFO ;
479 $dbh2->{compare} = sub { $_[0] cmp $_[1] } ;
481 $dbh3 = new DB_File::BTREEINFO ;
482 $dbh3->{compare} = sub { length $_[0] <=> length $_[1] } ;
485 tie(%h, 'DB_File',$Dfile1, O_RDWR|O_CREAT, 0640, $dbh1 ) ;
486 tie(%g, 'DB_File',$Dfile2, O_RDWR|O_CREAT, 0640, $dbh2 ) ;
487 tie(%k, 'DB_File',$Dfile3, O_RDWR|O_CREAT, 0640, $dbh3 ) ;
489 @Keys = qw( 0123 12 -1234 9 987654321 def ) ;
491 @srt_1 = sort { $a <=> $b } @Keys ; }
492 @srt_2 = sort { $a cmp $b } @Keys ;
493 @srt_3 = sort { length $a <=> length $b } @Keys ;
506 return 0 if @$a != @$b ;
508 foreach (1 .. length @$a)
510 return 0 unless $$a[$_] eq $$b[$_] ;
516 ok(86, ArrayCompare (\@srt_1, [keys %h]) );
517 ok(87, ArrayCompare (\@srt_2, [keys %g]) );
518 ok(88, ArrayCompare (\@srt_3, [keys %k]) );
523 unlink $Dfile1, $Dfile2, $Dfile3 ;
528 ok(89, tie(%h, 'DB_File', $Dfile1, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
530 { $h{$_} = $_ * 100 }
532 # check that there are 10 elements in the hash
534 while (($key,$value) = each(%h)) {
544 while (($key,$value) = each(%h)) {
553 # check that attempting to tie an array to a DB_BTREE will fail
555 my $filename = "xyz" ;
557 eval { tie @x, 'DB_File', $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE ; } ;
558 ok(92, $@ =~ /^DB_File can only tie an associative array to a DB_BTREE database/) ;
569 open(FILE, ">SubDB.pm") or die "Cannot open SubDB.pm: $!\n" ;
575 use vars qw( @ISA @EXPORT) ;
580 @EXPORT = @DB_File::EXPORT ;
586 $self->SUPER::STORE($key, $value * 2) ;
592 $self->SUPER::FETCH($key) - 1 ;
599 $self->SUPER::put($key, $value * 3) ;
604 $self->SUPER::get($_[0], $_[1]) ;
612 my $value = $self->FETCH($key) ;
613 return "[[$value]]" ;
621 BEGIN { push @INC, '.'; }
623 main::ok(93, $@ eq "") ;
627 $X = tie(%h, "SubDB","dbbtree.tmp", O_RDWR|O_CREAT, 0640, $DB_BTREE );
630 main::ok(94, $@ eq "") ;
632 my $ret = eval '$h{"fred"} = 3 ; return $h{"fred"} ' ;
633 main::ok(95, $@ eq "") ;
634 main::ok(96, $ret == 5) ;
637 $ret = eval '$X->put("joe", 4) ; $X->get("joe", $value) ; return $value' ;
638 main::ok(97, $@ eq "") ;
639 main::ok(98, $ret == 10) ;
641 $ret = eval ' R_NEXT eq main::R_NEXT ' ;
642 main::ok(99, $@ eq "" ) ;
643 main::ok(100, $ret == 1) ;
645 $ret = eval '$X->A_new_method("joe") ' ;
646 main::ok(101, $@ eq "") ;
647 main::ok(102, $ret eq "[[11]]") ;
651 unlink "SubDB.pm", "dbbtree.tmp" ;
659 my ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
664 my($fk, $sk, $fv, $sv) = @_ ;
666 $fetch_key eq $fk && $store_key eq $sk &&
667 $fetch_value eq $fv && $store_value eq $sv &&
671 ok(103, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
673 $db->filter_fetch_key (sub { $fetch_key = $_ }) ;
674 $db->filter_store_key (sub { $store_key = $_ }) ;
675 $db->filter_fetch_value (sub { $fetch_value = $_}) ;
676 $db->filter_store_value (sub { $store_value = $_ }) ;
682 ok(104, checkOutput( "", "fred", "", "joe")) ;
684 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
685 ok(105, $h{"fred"} eq "joe");
687 ok(106, checkOutput( "", "fred", "joe", "")) ;
689 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
690 ok(107, $db->FIRSTKEY() eq "fred") ;
692 ok(108, checkOutput( "fred", "", "", "")) ;
694 # replace the filters, but remember the previous set
695 my ($old_fk) = $db->filter_fetch_key
696 (sub { $_ = uc $_ ; $fetch_key = $_ }) ;
697 my ($old_sk) = $db->filter_store_key
698 (sub { $_ = lc $_ ; $store_key = $_ }) ;
699 my ($old_fv) = $db->filter_fetch_value
700 (sub { $_ = "[$_]"; $fetch_value = $_ }) ;
701 my ($old_sv) = $db->filter_store_value
702 (sub { s/o/x/g; $store_value = $_ }) ;
704 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
707 ok(109, checkOutput( "", "fred", "", "Jxe")) ;
709 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
710 ok(110, $h{"Fred"} eq "[Jxe]");
712 ok(111, checkOutput( "", "fred", "[Jxe]", "")) ;
714 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
715 ok(112, $db->FIRSTKEY() eq "FRED") ;
717 ok(113, checkOutput( "FRED", "", "", "")) ;
719 # put the original filters back
720 $db->filter_fetch_key ($old_fk);
721 $db->filter_store_key ($old_sk);
722 $db->filter_fetch_value ($old_fv);
723 $db->filter_store_value ($old_sv);
725 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
727 ok(114, checkOutput( "", "fred", "", "joe")) ;
729 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
730 ok(115, $h{"fred"} eq "joe");
731 ok(116, checkOutput( "", "fred", "joe", "")) ;
733 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
734 ok(117, $db->FIRSTKEY() eq "fred") ;
735 ok(118, checkOutput( "fred", "", "", "")) ;
738 $db->filter_fetch_key (undef);
739 $db->filter_store_key (undef);
740 $db->filter_fetch_value (undef);
741 $db->filter_store_value (undef);
743 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
745 ok(119, checkOutput( "", "", "", "")) ;
747 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
748 ok(120, $h{"fred"} eq "joe");
749 ok(121, checkOutput( "", "", "", "")) ;
751 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
752 ok(122, $db->FIRSTKEY() eq "fred") ;
753 ok(123, checkOutput( "", "", "", "")) ;
761 # DBM Filter with a closure
767 ok(124, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
777 return sub { ++$count ;
779 $result{$name} = "$name - $count: [@kept]" ;
783 $db->filter_store_key(Closure("store key")) ;
784 $db->filter_store_value(Closure("store value")) ;
785 $db->filter_fetch_key(Closure("fetch key")) ;
786 $db->filter_fetch_value(Closure("fetch value")) ;
791 ok(125, $result{"store key"} eq "store key - 1: [fred]");
792 ok(126, $result{"store value"} eq "store value - 1: [joe]");
793 ok(127, ! defined $result{"fetch key"} );
794 ok(128, ! defined $result{"fetch value"} );
795 ok(129, $_ eq "original") ;
797 ok(130, $db->FIRSTKEY() eq "fred") ;
798 ok(131, $result{"store key"} eq "store key - 1: [fred]");
799 ok(132, $result{"store value"} eq "store value - 1: [joe]");
800 ok(133, $result{"fetch key"} eq "fetch key - 1: [fred]");
801 ok(134, ! defined $result{"fetch value"} );
802 ok(135, $_ eq "original") ;
805 ok(136, $result{"store key"} eq "store key - 2: [fred jim]");
806 ok(137, $result{"store value"} eq "store value - 2: [joe john]");
807 ok(138, $result{"fetch key"} eq "fetch key - 1: [fred]");
808 ok(139, ! defined $result{"fetch value"} );
809 ok(140, $_ eq "original") ;
811 ok(141, $h{"fred"} eq "joe");
812 ok(142, $result{"store key"} eq "store key - 3: [fred jim fred]");
813 ok(143, $result{"store value"} eq "store value - 2: [joe john]");
814 ok(144, $result{"fetch key"} eq "fetch key - 1: [fred]");
815 ok(145, $result{"fetch value"} eq "fetch value - 1: [joe]");
816 ok(146, $_ eq "original") ;
824 # DBM Filter recursion detection
829 ok(147, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
831 $db->filter_store_key (sub { $_ = $h{$_} }) ;
833 eval '$h{1} = 1234' ;
834 ok(148, $@ =~ /^recursion detected in filter_store_key at/ );
843 # Examples from the POD
848 my $redirect = new Redirect $file ;
860 my ($key1, $key2) = @_ ;
861 "\L$key1" cmp "\L$key2" ;
864 # specify the Perl sub that will do the comparison
865 $DB_BTREE->{'compare'} = \&Compare ;
868 tie %h, "DB_File", "tree", O_RDWR|O_CREAT, 0640, $DB_BTREE
869 or die "Cannot open file 'tree': $!\n" ;
871 # Add a key/value pair to the file
872 $h{'Wall'} = 'Larry' ;
873 $h{'Smith'} = 'John' ;
874 $h{'mouse'} = 'mickey' ;
875 $h{'duck'} = 'donald' ;
880 # Cycle through the keys printing them in order.
881 # Note it is not necessary to sort the keys as
882 # the btree will have kept them in order automatically.
891 delete $DB_BTREE->{'compare'} ;
893 ok(149, docat_del($file) eq <<'EOM') ;
900 my $redirect = new Redirect $file ;
908 use vars qw($filename %h ) ;
913 # Enable duplicate records
914 $DB_BTREE->{'flags'} = R_DUP ;
916 tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
917 or die "Cannot open $filename: $!\n";
919 # Add some key/value pairs to the file
920 $h{'Wall'} = 'Larry' ;
921 $h{'Wall'} = 'Brick' ; # Note the duplicate key
922 $h{'Wall'} = 'Brick' ; # Note the duplicate key and value
923 $h{'Smith'} = 'John' ;
924 $h{'mouse'} = 'mickey' ;
926 # iterate through the associative array
927 # and print each key/value pair.
929 { print "$_ -> $h{$_}\n" }
936 ok(150, docat_del($file) eq ($DB_File::db_version == 1 ? <<'EOM' : <<'EOM') ) ;
951 my $redirect = new Redirect $file ;
959 use vars qw($filename $x %h $status $key $value) ;
964 # Enable duplicate records
965 $DB_BTREE->{'flags'} = R_DUP ;
967 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
968 or die "Cannot open $filename: $!\n";
970 # Add some key/value pairs to the file
971 $h{'Wall'} = 'Larry' ;
972 $h{'Wall'} = 'Brick' ; # Note the duplicate key
973 $h{'Wall'} = 'Brick' ; # Note the duplicate key and value
974 $h{'Smith'} = 'John' ;
975 $h{'mouse'} = 'mickey' ;
977 # iterate through the btree using seq
978 # and print each key/value pair.
980 for ($status = $x->seq($key, $value, R_FIRST) ;
982 $status = $x->seq($key, $value, R_NEXT) )
983 { print "$key -> $value\n" }
990 ok(151, docat_del($file) eq ($DB_File::db_version == 1 ? <<'EOM' : <<'EOM') ) ;
1006 my $redirect = new Redirect $file ;
1014 use vars qw($filename $x %h ) ;
1016 $filename = "tree" ;
1018 # Enable duplicate records
1019 $DB_BTREE->{'flags'} = R_DUP ;
1021 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1022 or die "Cannot open $filename: $!\n";
1024 my $cnt = $x->get_dup("Wall") ;
1025 print "Wall occurred $cnt times\n" ;
1027 my %hash = $x->get_dup("Wall", 1) ;
1028 print "Larry is there\n" if $hash{'Larry'} ;
1029 print "There are $hash{'Brick'} Brick Walls\n" ;
1031 my @list = sort $x->get_dup("Wall") ;
1032 print "Wall => [@list]\n" ;
1034 @list = $x->get_dup("Smith") ;
1035 print "Smith => [@list]\n" ;
1037 @list = $x->get_dup("Dog") ;
1038 print "Dog => [@list]\n" ;
1044 ok(152, docat_del($file) eq <<'EOM') ;
1045 Wall occurred 3 times
1047 There are 2 Brick Walls
1048 Wall => [Brick Brick Larry]
1054 my $redirect = new Redirect $file ;
1062 use vars qw($filename $x %h $found) ;
1064 my $filename = "tree" ;
1066 # Enable duplicate records
1067 $DB_BTREE->{'flags'} = R_DUP ;
1069 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1070 or die "Cannot open $filename: $!\n";
1072 $found = ( $x->find_dup("Wall", "Larry") == 0 ? "" : "not") ;
1073 print "Larry Wall is $found there\n" ;
1075 $found = ( $x->find_dup("Wall", "Harry") == 0 ? "" : "not") ;
1076 print "Harry Wall is $found there\n" ;
1082 ok(153, docat_del($file) eq <<'EOM') ;
1084 Harry Wall is not there
1088 my $redirect = new Redirect $file ;
1096 use vars qw($filename $x %h $found) ;
1098 my $filename = "tree" ;
1100 # Enable duplicate records
1101 $DB_BTREE->{'flags'} = R_DUP ;
1103 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1104 or die "Cannot open $filename: $!\n";
1106 $x->del_dup("Wall", "Larry") ;
1108 $found = ( $x->find_dup("Wall", "Larry") == 0 ? "" : "not") ;
1109 print "Larry Wall is $found there\n" ;
1117 ok(154, docat_del($file) eq <<'EOM') ;
1118 Larry Wall is not there
1122 my $redirect = new Redirect $file ;
1131 use vars qw($filename $x %h $st $key $value) ;
1137 my $orig_key = $key ;
1138 $x->seq($key, $value, R_CURSOR) ;
1139 print "$orig_key\t-> $key\t-> $value\n" ;
1142 $filename = "tree" ;
1145 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1146 or die "Cannot open $filename: $!\n";
1148 # Add some key/value pairs to the file
1149 $h{'mouse'} = 'mickey' ;
1150 $h{'Wall'} = 'Larry' ;
1151 $h{'Walls'} = 'Brick' ;
1152 $h{'Smith'} = 'John' ;
1156 print "IN ORDER\n" ;
1157 for ($st = $x->seq($key, $value, R_FIRST) ;
1159 $st = $x->seq($key, $value, R_NEXT) )
1161 { print "$key -> $value\n" }
1163 print "\nPARTIAL MATCH\n" ;
1176 ok(155, docat_del($file) eq <<'EOM') ;
1186 a -> mouse -> mickey
1197 # ok(156, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
1200 # my $k = "newest" ;
1202 # my $status = $db->put($k, $v, R_SETCURSOR) ;
1203 # print "status = [$status]\n" ;
1204 # ok(157, $status == 0) ;
1205 # $status = $db->del($k, R_CURSOR) ;
1206 # print "status = [$status]\n" ;
1207 # ok(158, $status == 0) ;
1209 # ok(159, $db->get($k, $v, R_CURSOR)) ;
1211 # ok(160, keys %h == 1) ;