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.
182 # tie to the same file again
183 ok(26, $X = tie(%h,'DB_File',$Dfile, O_RDWR, 0640, $DB_BTREE)) ;
185 # Modify an entry from the previous tie
206 $h{'goner3'} = 'snork';
209 $X->DELETE('goner3');
212 @values = values(%h);
214 ok(27, $#keys == 29 && $#values == 29) ;
217 while (($key,$value) = each(%h)) {
218 if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
220 $i++ if $key eq $value;
226 @keys = ('blurfl', keys(%h), 'dyick');
227 ok(29, $#keys == 31) ;
229 #Check that the keys can be retrieved in order
231 my @c = sort lexical @b ;
232 ok(30, ArrayCompare(\@b, \@c)) ;
235 ok(31, $h{'foo'} eq '' ) ;
238 #ok(32, $h{''} eq 'bar' );
241 # check cache overflow and numeric keys and contents
243 for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
244 for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
247 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
248 $blksize,$blocks) = stat($Dfile);
251 @h{0..200} = 200..400;
253 ok(35, join(':',200..400) eq join(':',@foo) );
255 # Now check all the non-tie specific stuff
258 # Check R_NOOVERWRITE flag will make put fail when attempting to overwrite
259 # an existing record.
261 $status = $X->put( 'x', 'newvalue', R_NOOVERWRITE) ;
262 ok(36, $status == 1 );
264 # check that the value of the key 'x' has not been changed by the
266 ok(37, $h{'x'} eq 'X' );
269 $status = $X->put('key', 'value') ;
270 ok(38, $status == 0 );
272 #check that previous put can be retrieved
274 $status = $X->get('key', $value) ;
275 ok(39, $status == 0 );
276 ok(40, $value eq 'value' );
278 # Attempting to delete an existing key should work
280 $status = $X->del('q') ;
281 ok(41, $status == 0 );
282 #$status = $X->del('') ;
283 #ok(42, $status == 0 );
286 # Make sure that the key deleted, cannot be retrieved
287 ok(43, ! defined $h{'q'}) ;
288 ok(44, ! defined $h{''}) ;
293 ok(45, $X = tie(%h, 'DB_File',$Dfile, O_RDWR, 0640, $DB_BTREE ));
295 # Attempting to delete a non-existant key should fail
297 $status = $X->del('joe') ;
298 ok(46, $status == 1 );
300 # Check the get interface
302 # First a non-existing key
303 $status = $X->get('aaaa', $value) ;
304 ok(47, $status == 1 );
306 # Next an existing key
307 $status = $X->get('a', $value) ;
308 ok(48, $status == 0 );
309 ok(49, $value eq 'A' );
314 # use seq to find an approximate match
317 $status = $X->seq($key, $value, R_CURSOR) ;
318 ok(50, $status == 0 );
319 ok(51, $key eq 'key' );
320 ok(52, $value eq 'value' );
322 # seq when the key does not match
325 $status = $X->seq($key, $value, R_CURSOR) ;
326 ok(53, $status == 1 );
329 # use seq to set the cursor, then delete the record @ the cursor.
333 $status = $X->seq($key, $value, R_CURSOR) ;
334 ok(54, $status == 0 );
335 ok(55, $key eq 'x' );
336 ok(56, $value eq 'X' );
337 $status = $X->del(0, R_CURSOR) ;
338 ok(57, $status == 0 );
339 $status = $X->get('x', $value) ;
340 ok(58, $status == 1 );
342 # ditto, but use put to replace the key/value pair.
345 $status = $X->seq($key, $value, R_CURSOR) ;
346 ok(59, $status == 0 );
347 ok(60, $key eq 'y' );
348 ok(61, $value eq 'Y' );
350 $key = "replace key" ;
351 $value = "replace value" ;
352 $status = $X->put($key, $value, R_CURSOR) ;
353 ok(62, $status == 0 );
354 ok(63, $key eq 'replace key' );
355 ok(64, $value eq 'replace value' );
356 $status = $X->get('y', $value) ;
357 ok(65, 1) ; # hard-wire to always pass. the previous test ($status == 1)
358 # only worked because of a bug in 1.85/6
360 # use seq to walk forwards through a file
362 $status = $X->seq($key, $value, R_FIRST) ;
363 ok(66, $status == 0 );
367 while (($status = $X->seq($key, $value, R_NEXT)) == 0)
369 ($ok = 0), last if ($previous cmp $key) == 1 ;
372 ok(67, $status == 1 );
375 # use seq to walk backwards through a file
376 $status = $X->seq($key, $value, R_LAST) ;
377 ok(69, $status == 0 );
381 while (($status = $X->seq($key, $value, R_PREV)) == 0)
383 ($ok = 0), last if ($previous cmp $key) == -1 ;
384 #print "key = [$key] value = [$value]\n" ;
387 ok(70, $status == 1 );
391 # check seq FIRST/LAST
397 ok(72, $status == 0 );
404 ok(73, $status != 0 );
412 # Now try an in memory file
413 ok(74, $Y = tie(%h, 'DB_File',undef, O_RDWR|O_CREAT, 0640, $DB_BTREE ));
415 # fd with an in memory file should return failure
417 ok(75, $status == -1 );
424 my $bt = new DB_File::BTREEINFO ;
425 $bt->{flags} = R_DUP ;
426 ok(76, $YY = tie(%hh, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $bt )) ;
428 $hh{'Wall'} = 'Larry' ;
429 $hh{'Wall'} = 'Stone' ; # Note the duplicate key
430 $hh{'Wall'} = 'Brick' ; # Note the duplicate key
431 $hh{'Wall'} = 'Brick' ; # Note the duplicate key and value
432 $hh{'Smith'} = 'John' ;
433 $hh{'mouse'} = 'mickey' ;
435 # first work in scalar context
436 ok(77, scalar $YY->get_dup('Unknown') == 0 );
437 ok(78, scalar $YY->get_dup('Smith') == 1 );
438 ok(79, scalar $YY->get_dup('Wall') == 4 );
440 # now in list context
441 my @unknown = $YY->get_dup('Unknown') ;
442 ok(80, "@unknown" eq "" );
444 my @smith = $YY->get_dup('Smith') ;
445 ok(81, "@smith" eq "John" );
448 my @wall = $YY->get_dup('Wall') ;
450 @wall{@wall} = @wall ;
451 ok(82, (@wall == 4 && $wall{'Larry'} && $wall{'Stone'} && $wall{'Brick'}) );
455 my %unknown = $YY->get_dup('Unknown', 1) ;
456 ok(83, keys %unknown == 0 );
458 my %smith = $YY->get_dup('Smith', 1) ;
459 ok(84, keys %smith == 1 && $smith{'John'}) ;
461 my %wall = $YY->get_dup('Wall', 1) ;
462 ok(85, keys %wall == 3 && $wall{'Larry'} == 1 && $wall{'Stone'} == 1
463 && $wall{'Brick'} == 2);
470 # test multiple callbacks
475 $dbh1 = new DB_File::BTREEINFO ;
477 $dbh1->{compare} = sub { $_[0] <=> $_[1] } ; }
479 $dbh2 = new DB_File::BTREEINFO ;
480 $dbh2->{compare} = sub { $_[0] cmp $_[1] } ;
482 $dbh3 = new DB_File::BTREEINFO ;
483 $dbh3->{compare} = sub { length $_[0] <=> length $_[1] } ;
486 tie(%h, 'DB_File',$Dfile1, O_RDWR|O_CREAT, 0640, $dbh1 ) ;
487 tie(%g, 'DB_File',$Dfile2, O_RDWR|O_CREAT, 0640, $dbh2 ) ;
488 tie(%k, 'DB_File',$Dfile3, O_RDWR|O_CREAT, 0640, $dbh3 ) ;
490 @Keys = qw( 0123 12 -1234 9 987654321 def ) ;
492 @srt_1 = sort { $a <=> $b } @Keys ; }
493 @srt_2 = sort { $a cmp $b } @Keys ;
494 @srt_3 = sort { length $a <=> length $b } @Keys ;
507 return 0 if @$a != @$b ;
509 foreach (1 .. length @$a)
511 return 0 unless $$a[$_] eq $$b[$_] ;
517 ok(86, ArrayCompare (\@srt_1, [keys %h]) );
518 ok(87, ArrayCompare (\@srt_2, [keys %g]) );
519 ok(88, ArrayCompare (\@srt_3, [keys %k]) );
524 unlink $Dfile1, $Dfile2, $Dfile3 ;
529 ok(89, tie(%h, 'DB_File', $Dfile1, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
531 { $h{$_} = $_ * 100 }
533 # check that there are 10 elements in the hash
535 while (($key,$value) = each(%h)) {
545 while (($key,$value) = each(%h)) {
554 # check that attempting to tie an array to a DB_BTREE will fail
556 my $filename = "xyz" ;
558 eval { tie @x, 'DB_File', $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE ; } ;
559 ok(92, $@ =~ /^DB_File can only tie an associative array to a DB_BTREE database/) ;
570 open(FILE, ">SubDB.pm") or die "Cannot open SubDB.pm: $!\n" ;
576 use vars qw( @ISA @EXPORT) ;
581 @EXPORT = @DB_File::EXPORT ;
587 $self->SUPER::STORE($key, $value * 2) ;
593 $self->SUPER::FETCH($key) - 1 ;
600 $self->SUPER::put($key, $value * 3) ;
605 $self->SUPER::get($_[0], $_[1]) ;
613 my $value = $self->FETCH($key) ;
614 return "[[$value]]" ;
622 BEGIN { push @INC, '.'; }
624 main::ok(93, $@ eq "") ;
628 $X = tie(%h, "SubDB","dbbtree.tmp", O_RDWR|O_CREAT, 0640, $DB_BTREE );
631 main::ok(94, $@ eq "") ;
633 my $ret = eval '$h{"fred"} = 3 ; return $h{"fred"} ' ;
634 main::ok(95, $@ eq "") ;
635 main::ok(96, $ret == 5) ;
638 $ret = eval '$X->put("joe", 4) ; $X->get("joe", $value) ; return $value' ;
639 main::ok(97, $@ eq "") ;
640 main::ok(98, $ret == 10) ;
642 $ret = eval ' R_NEXT eq main::R_NEXT ' ;
643 main::ok(99, $@ eq "" ) ;
644 main::ok(100, $ret == 1) ;
646 $ret = eval '$X->A_new_method("joe") ' ;
647 main::ok(101, $@ eq "") ;
648 main::ok(102, $ret eq "[[11]]") ;
652 unlink "SubDB.pm", "dbbtree.tmp" ;
660 my ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
665 my($fk, $sk, $fv, $sv) = @_ ;
667 $fetch_key eq $fk && $store_key eq $sk &&
668 $fetch_value eq $fv && $store_value eq $sv &&
672 ok(103, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
674 $db->filter_fetch_key (sub { $fetch_key = $_ }) ;
675 $db->filter_store_key (sub { $store_key = $_ }) ;
676 $db->filter_fetch_value (sub { $fetch_value = $_}) ;
677 $db->filter_store_value (sub { $store_value = $_ }) ;
683 ok(104, checkOutput( "", "fred", "", "joe")) ;
685 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
686 ok(105, $h{"fred"} eq "joe");
688 ok(106, checkOutput( "", "fred", "joe", "")) ;
690 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
691 ok(107, $db->FIRSTKEY() eq "fred") ;
693 ok(108, checkOutput( "fred", "", "", "")) ;
695 # replace the filters, but remember the previous set
696 my ($old_fk) = $db->filter_fetch_key
697 (sub { $_ = uc $_ ; $fetch_key = $_ }) ;
698 my ($old_sk) = $db->filter_store_key
699 (sub { $_ = lc $_ ; $store_key = $_ }) ;
700 my ($old_fv) = $db->filter_fetch_value
701 (sub { $_ = "[$_]"; $fetch_value = $_ }) ;
702 my ($old_sv) = $db->filter_store_value
703 (sub { s/o/x/g; $store_value = $_ }) ;
705 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
708 ok(109, checkOutput( "", "fred", "", "Jxe")) ;
710 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
711 ok(110, $h{"Fred"} eq "[Jxe]");
713 ok(111, checkOutput( "", "fred", "[Jxe]", "")) ;
715 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
716 ok(112, $db->FIRSTKEY() eq "FRED") ;
718 ok(113, checkOutput( "FRED", "", "", "")) ;
720 # put the original filters back
721 $db->filter_fetch_key ($old_fk);
722 $db->filter_store_key ($old_sk);
723 $db->filter_fetch_value ($old_fv);
724 $db->filter_store_value ($old_sv);
726 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
728 ok(114, checkOutput( "", "fred", "", "joe")) ;
730 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
731 ok(115, $h{"fred"} eq "joe");
732 ok(116, checkOutput( "", "fred", "joe", "")) ;
734 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
735 ok(117, $db->FIRSTKEY() eq "fred") ;
736 ok(118, checkOutput( "fred", "", "", "")) ;
739 $db->filter_fetch_key (undef);
740 $db->filter_store_key (undef);
741 $db->filter_fetch_value (undef);
742 $db->filter_store_value (undef);
744 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
746 ok(119, checkOutput( "", "", "", "")) ;
748 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
749 ok(120, $h{"fred"} eq "joe");
750 ok(121, checkOutput( "", "", "", "")) ;
752 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
753 ok(122, $db->FIRSTKEY() eq "fred") ;
754 ok(123, checkOutput( "", "", "", "")) ;
762 # DBM Filter with a closure
768 ok(124, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
778 return sub { ++$count ;
780 $result{$name} = "$name - $count: [@kept]" ;
784 $db->filter_store_key(Closure("store key")) ;
785 $db->filter_store_value(Closure("store value")) ;
786 $db->filter_fetch_key(Closure("fetch key")) ;
787 $db->filter_fetch_value(Closure("fetch value")) ;
792 ok(125, $result{"store key"} eq "store key - 1: [fred]");
793 ok(126, $result{"store value"} eq "store value - 1: [joe]");
794 ok(127, ! defined $result{"fetch key"} );
795 ok(128, ! defined $result{"fetch value"} );
796 ok(129, $_ eq "original") ;
798 ok(130, $db->FIRSTKEY() eq "fred") ;
799 ok(131, $result{"store key"} eq "store key - 1: [fred]");
800 ok(132, $result{"store value"} eq "store value - 1: [joe]");
801 ok(133, $result{"fetch key"} eq "fetch key - 1: [fred]");
802 ok(134, ! defined $result{"fetch value"} );
803 ok(135, $_ eq "original") ;
806 ok(136, $result{"store key"} eq "store key - 2: [fred jim]");
807 ok(137, $result{"store value"} eq "store value - 2: [joe john]");
808 ok(138, $result{"fetch key"} eq "fetch key - 1: [fred]");
809 ok(139, ! defined $result{"fetch value"} );
810 ok(140, $_ eq "original") ;
812 ok(141, $h{"fred"} eq "joe");
813 ok(142, $result{"store key"} eq "store key - 3: [fred jim fred]");
814 ok(143, $result{"store value"} eq "store value - 2: [joe john]");
815 ok(144, $result{"fetch key"} eq "fetch key - 1: [fred]");
816 ok(145, $result{"fetch value"} eq "fetch value - 1: [joe]");
817 ok(146, $_ eq "original") ;
825 # DBM Filter recursion detection
830 ok(147, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
832 $db->filter_store_key (sub { $_ = $h{$_} }) ;
834 eval '$h{1} = 1234' ;
835 ok(148, $@ =~ /^recursion detected in filter_store_key at/ );
844 # Examples from the POD
849 my $redirect = new Redirect $file ;
861 my ($key1, $key2) = @_ ;
862 "\L$key1" cmp "\L$key2" ;
865 # specify the Perl sub that will do the comparison
866 $DB_BTREE->{'compare'} = \&Compare ;
869 tie %h, "DB_File", "tree", O_RDWR|O_CREAT, 0640, $DB_BTREE
870 or die "Cannot open file 'tree': $!\n" ;
872 # Add a key/value pair to the file
873 $h{'Wall'} = 'Larry' ;
874 $h{'Smith'} = 'John' ;
875 $h{'mouse'} = 'mickey' ;
876 $h{'duck'} = 'donald' ;
881 # Cycle through the keys printing them in order.
882 # Note it is not necessary to sort the keys as
883 # the btree will have kept them in order automatically.
892 delete $DB_BTREE->{'compare'} ;
894 ok(149, docat_del($file) eq <<'EOM') ;
901 my $redirect = new Redirect $file ;
909 use vars qw($filename %h ) ;
914 # Enable duplicate records
915 $DB_BTREE->{'flags'} = R_DUP ;
917 tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
918 or die "Cannot open $filename: $!\n";
920 # Add some key/value pairs to the file
921 $h{'Wall'} = 'Larry' ;
922 $h{'Wall'} = 'Brick' ; # Note the duplicate key
923 $h{'Wall'} = 'Brick' ; # Note the duplicate key and value
924 $h{'Smith'} = 'John' ;
925 $h{'mouse'} = 'mickey' ;
927 # iterate through the associative array
928 # and print each key/value pair.
930 { print "$_ -> $h{$_}\n" }
937 ok(150, docat_del($file) eq ($DB_File::db_version == 1 ? <<'EOM' : <<'EOM') ) ;
952 my $redirect = new Redirect $file ;
960 use vars qw($filename $x %h $status $key $value) ;
965 # Enable duplicate records
966 $DB_BTREE->{'flags'} = R_DUP ;
968 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
969 or die "Cannot open $filename: $!\n";
971 # Add some key/value pairs to the file
972 $h{'Wall'} = 'Larry' ;
973 $h{'Wall'} = 'Brick' ; # Note the duplicate key
974 $h{'Wall'} = 'Brick' ; # Note the duplicate key and value
975 $h{'Smith'} = 'John' ;
976 $h{'mouse'} = 'mickey' ;
978 # iterate through the btree using seq
979 # and print each key/value pair.
981 for ($status = $x->seq($key, $value, R_FIRST) ;
983 $status = $x->seq($key, $value, R_NEXT) )
984 { print "$key -> $value\n" }
991 ok(151, docat_del($file) eq ($DB_File::db_version == 1 ? <<'EOM' : <<'EOM') ) ;
1007 my $redirect = new Redirect $file ;
1015 use vars qw($filename $x %h ) ;
1017 $filename = "tree" ;
1019 # Enable duplicate records
1020 $DB_BTREE->{'flags'} = R_DUP ;
1022 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1023 or die "Cannot open $filename: $!\n";
1025 my $cnt = $x->get_dup("Wall") ;
1026 print "Wall occurred $cnt times\n" ;
1028 my %hash = $x->get_dup("Wall", 1) ;
1029 print "Larry is there\n" if $hash{'Larry'} ;
1030 print "There are $hash{'Brick'} Brick Walls\n" ;
1032 my @list = sort $x->get_dup("Wall") ;
1033 print "Wall => [@list]\n" ;
1035 @list = $x->get_dup("Smith") ;
1036 print "Smith => [@list]\n" ;
1038 @list = $x->get_dup("Dog") ;
1039 print "Dog => [@list]\n" ;
1045 ok(152, docat_del($file) eq <<'EOM') ;
1046 Wall occurred 3 times
1048 There are 2 Brick Walls
1049 Wall => [Brick Brick Larry]
1055 my $redirect = new Redirect $file ;
1063 use vars qw($filename $x %h $found) ;
1065 my $filename = "tree" ;
1067 # Enable duplicate records
1068 $DB_BTREE->{'flags'} = R_DUP ;
1070 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1071 or die "Cannot open $filename: $!\n";
1073 $found = ( $x->find_dup("Wall", "Larry") == 0 ? "" : "not") ;
1074 print "Larry Wall is $found there\n" ;
1076 $found = ( $x->find_dup("Wall", "Harry") == 0 ? "" : "not") ;
1077 print "Harry Wall is $found there\n" ;
1083 ok(153, docat_del($file) eq <<'EOM') ;
1085 Harry Wall is not there
1089 my $redirect = new Redirect $file ;
1097 use vars qw($filename $x %h $found) ;
1099 my $filename = "tree" ;
1101 # Enable duplicate records
1102 $DB_BTREE->{'flags'} = R_DUP ;
1104 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1105 or die "Cannot open $filename: $!\n";
1107 $x->del_dup("Wall", "Larry") ;
1109 $found = ( $x->find_dup("Wall", "Larry") == 0 ? "" : "not") ;
1110 print "Larry Wall is $found there\n" ;
1118 ok(154, docat_del($file) eq <<'EOM') ;
1119 Larry Wall is not there
1123 my $redirect = new Redirect $file ;
1132 use vars qw($filename $x %h $st $key $value) ;
1138 my $orig_key = $key ;
1139 $x->seq($key, $value, R_CURSOR) ;
1140 print "$orig_key\t-> $key\t-> $value\n" ;
1143 $filename = "tree" ;
1146 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1147 or die "Cannot open $filename: $!\n";
1149 # Add some key/value pairs to the file
1150 $h{'mouse'} = 'mickey' ;
1151 $h{'Wall'} = 'Larry' ;
1152 $h{'Walls'} = 'Brick' ;
1153 $h{'Smith'} = 'John' ;
1157 print "IN ORDER\n" ;
1158 for ($st = $x->seq($key, $value, R_FIRST) ;
1160 $st = $x->seq($key, $value, R_NEXT) )
1162 { print "$key -> $value\n" }
1164 print "\nPARTIAL MATCH\n" ;
1177 ok(155, docat_del($file) eq <<'EOM') ;
1187 a -> mouse -> mickey