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 $db185mode = ($DB_File::db_version == 1 && ! $DB_File::db_185_compat) ;
87 my $Dfile = "dbbtree.tmp";
92 # Check the interface to BTREEINFO
94 my $dbh = new DB_File::BTREEINFO ;
95 ok(1, ! defined $dbh->{flags}) ;
96 ok(2, ! defined $dbh->{cachesize}) ;
97 ok(3, ! defined $dbh->{psize}) ;
98 ok(4, ! defined $dbh->{lorder}) ;
99 ok(5, ! defined $dbh->{minkeypage}) ;
100 ok(6, ! defined $dbh->{maxkeypage}) ;
101 ok(7, ! defined $dbh->{compare}) ;
102 ok(8, ! defined $dbh->{prefix}) ;
104 $dbh->{flags} = 3000 ;
105 ok(9, $dbh->{flags} == 3000) ;
107 $dbh->{cachesize} = 9000 ;
108 ok(10, $dbh->{cachesize} == 9000);
110 $dbh->{psize} = 400 ;
111 ok(11, $dbh->{psize} == 400) ;
113 $dbh->{lorder} = 65 ;
114 ok(12, $dbh->{lorder} == 65) ;
116 $dbh->{minkeypage} = 123 ;
117 ok(13, $dbh->{minkeypage} == 123) ;
119 $dbh->{maxkeypage} = 1234 ;
120 ok(14, $dbh->{maxkeypage} == 1234 );
122 $dbh->{compare} = 1234 ;
123 ok(15, $dbh->{compare} == 1234) ;
125 $dbh->{prefix} = 1234 ;
126 ok(16, $dbh->{prefix} == 1234 );
128 # Check that an invalid entry is caught both for store & fetch
129 eval '$dbh->{fred} = 1234' ;
130 ok(17, $@ =~ /^DB_File::BTREEINFO::STORE - Unknown element 'fred' at/ ) ;
131 eval '$q = $dbh->{fred}' ;
132 ok(18, $@ =~ /^DB_File::BTREEINFO::FETCH - Unknown element 'fred' at/ ) ;
134 # Now check the interface to BTREE
136 ok(19, $X = tie(%h, 'DB_File',$Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE )) ;
138 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
139 $blksize,$blocks) = stat($Dfile);
140 ok(20, ($mode & 0777) == ($^O eq 'os2' ? 0666 : 0640) || $^O eq 'amigaos' || $^O eq 'MSWin32');
142 while (($key,$value) = each(%h)) {
147 $h{'goner1'} = 'snork';
150 ok(22, $h{'abc'} eq 'ABC' );
151 ok(23, ! defined $h{'jimmy'} ) ;
152 ok(24, ! exists $h{'jimmy'} ) ;
153 ok(25, defined $h{'abc'} ) ;
156 $h{'jkl','mno'} = "JKL\034MNO";
157 $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
161 $X->STORE('b', 'B') ;
174 $h{'goner2'} = 'snork';
178 # IMPORTANT - $X must be undefined before the untie otherwise the
179 # underlying DB close routine will not get called.
183 # tie to the same file again
184 ok(26, $X = tie(%h,'DB_File',$Dfile, O_RDWR, 0640, $DB_BTREE)) ;
186 # Modify an entry from the previous tie
207 $h{'goner3'} = 'snork';
210 $X->DELETE('goner3');
213 @values = values(%h);
215 ok(27, $#keys == 29 && $#values == 29) ;
218 while (($key,$value) = each(%h)) {
219 if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
221 $i++ if $key eq $value;
227 @keys = ('blurfl', keys(%h), 'dyick');
228 ok(29, $#keys == 31) ;
230 #Check that the keys can be retrieved in order
232 my @c = sort lexical @b ;
233 ok(30, ArrayCompare(\@b, \@c)) ;
236 ok(31, $h{'foo'} eq '' ) ;
239 #ok(32, $h{''} eq 'bar' );
242 # check cache overflow and numeric keys and contents
244 for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
245 for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
248 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
249 $blksize,$blocks) = stat($Dfile);
252 @h{0..200} = 200..400;
254 ok(35, join(':',200..400) eq join(':',@foo) );
256 # Now check all the non-tie specific stuff
259 # Check R_NOOVERWRITE flag will make put fail when attempting to overwrite
260 # an existing record.
262 $status = $X->put( 'x', 'newvalue', R_NOOVERWRITE) ;
263 ok(36, $status == 1 );
265 # check that the value of the key 'x' has not been changed by the
267 ok(37, $h{'x'} eq 'X' );
270 $status = $X->put('key', 'value') ;
271 ok(38, $status == 0 );
273 #check that previous put can be retrieved
275 $status = $X->get('key', $value) ;
276 ok(39, $status == 0 );
277 ok(40, $value eq 'value' );
279 # Attempting to delete an existing key should work
281 $status = $X->del('q') ;
282 ok(41, $status == 0 );
283 #$status = $X->del('') ;
284 #ok(42, $status == 0 );
287 # Make sure that the key deleted, cannot be retrieved
288 ok(43, ! defined $h{'q'}) ;
289 ok(44, ! defined $h{''}) ;
294 ok(45, $X = tie(%h, 'DB_File',$Dfile, O_RDWR, 0640, $DB_BTREE ));
296 # Attempting to delete a non-existant key should fail
298 $status = $X->del('joe') ;
299 ok(46, $status == 1 );
301 # Check the get interface
303 # First a non-existing key
304 $status = $X->get('aaaa', $value) ;
305 ok(47, $status == 1 );
307 # Next an existing key
308 $status = $X->get('a', $value) ;
309 ok(48, $status == 0 );
310 ok(49, $value eq 'A' );
315 # use seq to find an approximate match
318 $status = $X->seq($key, $value, R_CURSOR) ;
319 ok(50, $status == 0 );
320 ok(51, $key eq 'key' );
321 ok(52, $value eq 'value' );
323 # seq when the key does not match
326 $status = $X->seq($key, $value, R_CURSOR) ;
327 ok(53, $status == 1 );
330 # use seq to set the cursor, then delete the record @ the cursor.
334 $status = $X->seq($key, $value, R_CURSOR) ;
335 ok(54, $status == 0 );
336 ok(55, $key eq 'x' );
337 ok(56, $value eq 'X' );
338 $status = $X->del(0, R_CURSOR) ;
339 ok(57, $status == 0 );
340 $status = $X->get('x', $value) ;
341 ok(58, $status == 1 );
343 # ditto, but use put to replace the key/value pair.
346 $status = $X->seq($key, $value, R_CURSOR) ;
347 ok(59, $status == 0 );
348 ok(60, $key eq 'y' );
349 ok(61, $value eq 'Y' );
351 $key = "replace key" ;
352 $value = "replace value" ;
353 $status = $X->put($key, $value, R_CURSOR) ;
354 ok(62, $status == 0 );
355 ok(63, $key eq 'replace key' );
356 ok(64, $value eq 'replace value' );
357 $status = $X->get('y', $value) ;
358 ok(65, 1) ; # hard-wire to always pass. the previous test ($status == 1)
359 # only worked because of a bug in 1.85/6
361 # use seq to walk forwards through a file
363 $status = $X->seq($key, $value, R_FIRST) ;
364 ok(66, $status == 0 );
368 while (($status = $X->seq($key, $value, R_NEXT)) == 0)
370 ($ok = 0), last if ($previous cmp $key) == 1 ;
373 ok(67, $status == 1 );
376 # use seq to walk backwards through a file
377 $status = $X->seq($key, $value, R_LAST) ;
378 ok(69, $status == 0 );
382 while (($status = $X->seq($key, $value, R_PREV)) == 0)
384 ($ok = 0), last if ($previous cmp $key) == -1 ;
385 #print "key = [$key] value = [$value]\n" ;
388 ok(70, $status == 1 );
392 # check seq FIRST/LAST
398 ok(72, $status == 0 );
405 ok(73, $status != 0 );
413 # Now try an in memory file
414 ok(74, $Y = tie(%h, 'DB_File',undef, O_RDWR|O_CREAT, 0640, $DB_BTREE ));
416 # fd with an in memory file should return failure
418 ok(75, $status == -1 );
425 my $bt = new DB_File::BTREEINFO ;
426 $bt->{flags} = R_DUP ;
427 ok(76, $YY = tie(%hh, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $bt )) ;
429 $hh{'Wall'} = 'Larry' ;
430 $hh{'Wall'} = 'Stone' ; # Note the duplicate key
431 $hh{'Wall'} = 'Brick' ; # Note the duplicate key
432 $hh{'Wall'} = 'Brick' ; # Note the duplicate key and value
433 $hh{'Smith'} = 'John' ;
434 $hh{'mouse'} = 'mickey' ;
436 # first work in scalar context
437 ok(77, scalar $YY->get_dup('Unknown') == 0 );
438 ok(78, scalar $YY->get_dup('Smith') == 1 );
439 ok(79, scalar $YY->get_dup('Wall') == 4 );
441 # now in list context
442 my @unknown = $YY->get_dup('Unknown') ;
443 ok(80, "@unknown" eq "" );
445 my @smith = $YY->get_dup('Smith') ;
446 ok(81, "@smith" eq "John" );
449 my @wall = $YY->get_dup('Wall') ;
451 @wall{@wall} = @wall ;
452 ok(82, (@wall == 4 && $wall{'Larry'} && $wall{'Stone'} && $wall{'Brick'}) );
456 my %unknown = $YY->get_dup('Unknown', 1) ;
457 ok(83, keys %unknown == 0 );
459 my %smith = $YY->get_dup('Smith', 1) ;
460 ok(84, keys %smith == 1 && $smith{'John'}) ;
462 my %wall = $YY->get_dup('Wall', 1) ;
463 ok(85, keys %wall == 3 && $wall{'Larry'} == 1 && $wall{'Stone'} == 1
464 && $wall{'Brick'} == 2);
471 # test multiple callbacks
476 $dbh1 = new DB_File::BTREEINFO ;
478 $dbh1->{compare} = sub { $_[0] <=> $_[1] } ; }
480 $dbh2 = new DB_File::BTREEINFO ;
481 $dbh2->{compare} = sub { $_[0] cmp $_[1] } ;
483 $dbh3 = new DB_File::BTREEINFO ;
484 $dbh3->{compare} = sub { length $_[0] <=> length $_[1] } ;
487 tie(%h, 'DB_File',$Dfile1, O_RDWR|O_CREAT, 0640, $dbh1 ) ;
488 tie(%g, 'DB_File',$Dfile2, O_RDWR|O_CREAT, 0640, $dbh2 ) ;
489 tie(%k, 'DB_File',$Dfile3, O_RDWR|O_CREAT, 0640, $dbh3 ) ;
491 @Keys = qw( 0123 12 -1234 9 987654321 def ) ;
493 @srt_1 = sort { $a <=> $b } @Keys ; }
494 @srt_2 = sort { $a cmp $b } @Keys ;
495 @srt_3 = sort { length $a <=> length $b } @Keys ;
508 return 0 if @$a != @$b ;
510 foreach (1 .. length @$a)
512 return 0 unless $$a[$_] eq $$b[$_] ;
518 ok(86, ArrayCompare (\@srt_1, [keys %h]) );
519 ok(87, ArrayCompare (\@srt_2, [keys %g]) );
520 ok(88, ArrayCompare (\@srt_3, [keys %k]) );
525 unlink $Dfile1, $Dfile2, $Dfile3 ;
530 ok(89, tie(%h, 'DB_File', $Dfile1, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
532 { $h{$_} = $_ * 100 }
534 # check that there are 10 elements in the hash
536 while (($key,$value) = each(%h)) {
546 while (($key,$value) = each(%h)) {
555 # check that attempting to tie an array to a DB_BTREE will fail
557 my $filename = "xyz" ;
559 eval { tie @x, 'DB_File', $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE ; } ;
560 ok(92, $@ =~ /^DB_File can only tie an associative array to a DB_BTREE database/) ;
571 open(FILE, ">SubDB.pm") or die "Cannot open SubDB.pm: $!\n" ;
577 use vars qw( @ISA @EXPORT) ;
582 @EXPORT = @DB_File::EXPORT ;
588 $self->SUPER::STORE($key, $value * 2) ;
594 $self->SUPER::FETCH($key) - 1 ;
601 $self->SUPER::put($key, $value * 3) ;
606 $self->SUPER::get($_[0], $_[1]) ;
614 my $value = $self->FETCH($key) ;
615 return "[[$value]]" ;
623 BEGIN { push @INC, '.'; }
625 main::ok(93, $@ eq "") ;
629 $X = tie(%h, "SubDB","dbbtree.tmp", O_RDWR|O_CREAT, 0640, $DB_BTREE );
632 main::ok(94, $@ eq "") ;
634 my $ret = eval '$h{"fred"} = 3 ; return $h{"fred"} ' ;
635 main::ok(95, $@ eq "") ;
636 main::ok(96, $ret == 5) ;
639 $ret = eval '$X->put("joe", 4) ; $X->get("joe", $value) ; return $value' ;
640 main::ok(97, $@ eq "") ;
641 main::ok(98, $ret == 10) ;
643 $ret = eval ' R_NEXT eq main::R_NEXT ' ;
644 main::ok(99, $@ eq "" ) ;
645 main::ok(100, $ret == 1) ;
647 $ret = eval '$X->A_new_method("joe") ' ;
648 main::ok(101, $@ eq "") ;
649 main::ok(102, $ret eq "[[11]]") ;
653 unlink "SubDB.pm", "dbbtree.tmp" ;
661 my ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
666 my($fk, $sk, $fv, $sv) = @_ ;
668 $fetch_key eq $fk && $store_key eq $sk &&
669 $fetch_value eq $fv && $store_value eq $sv &&
673 ok(103, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
675 $db->filter_fetch_key (sub { $fetch_key = $_ }) ;
676 $db->filter_store_key (sub { $store_key = $_ }) ;
677 $db->filter_fetch_value (sub { $fetch_value = $_}) ;
678 $db->filter_store_value (sub { $store_value = $_ }) ;
684 ok(104, checkOutput( "", "fred", "", "joe")) ;
686 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
687 ok(105, $h{"fred"} eq "joe");
689 ok(106, checkOutput( "", "fred", "joe", "")) ;
691 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
692 ok(107, $db->FIRSTKEY() eq "fred") ;
694 ok(108, checkOutput( "fred", "", "", "")) ;
696 # replace the filters, but remember the previous set
697 my ($old_fk) = $db->filter_fetch_key
698 (sub { $_ = uc $_ ; $fetch_key = $_ }) ;
699 my ($old_sk) = $db->filter_store_key
700 (sub { $_ = lc $_ ; $store_key = $_ }) ;
701 my ($old_fv) = $db->filter_fetch_value
702 (sub { $_ = "[$_]"; $fetch_value = $_ }) ;
703 my ($old_sv) = $db->filter_store_value
704 (sub { s/o/x/g; $store_value = $_ }) ;
706 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
709 ok(109, checkOutput( "", "fred", "", "Jxe")) ;
711 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
712 ok(110, $h{"Fred"} eq "[Jxe]");
714 ok(111, checkOutput( "", "fred", "[Jxe]", "")) ;
716 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
717 ok(112, $db->FIRSTKEY() eq "FRED") ;
719 ok(113, checkOutput( "FRED", "", "", "")) ;
721 # put the original filters back
722 $db->filter_fetch_key ($old_fk);
723 $db->filter_store_key ($old_sk);
724 $db->filter_fetch_value ($old_fv);
725 $db->filter_store_value ($old_sv);
727 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
729 ok(114, checkOutput( "", "fred", "", "joe")) ;
731 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
732 ok(115, $h{"fred"} eq "joe");
733 ok(116, checkOutput( "", "fred", "joe", "")) ;
735 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
736 ok(117, $db->FIRSTKEY() eq "fred") ;
737 ok(118, checkOutput( "fred", "", "", "")) ;
740 $db->filter_fetch_key (undef);
741 $db->filter_store_key (undef);
742 $db->filter_fetch_value (undef);
743 $db->filter_store_value (undef);
745 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
747 ok(119, checkOutput( "", "", "", "")) ;
749 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
750 ok(120, $h{"fred"} eq "joe");
751 ok(121, checkOutput( "", "", "", "")) ;
753 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
754 ok(122, $db->FIRSTKEY() eq "fred") ;
755 ok(123, checkOutput( "", "", "", "")) ;
763 # DBM Filter with a closure
769 ok(124, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
779 return sub { ++$count ;
781 $result{$name} = "$name - $count: [@kept]" ;
785 $db->filter_store_key(Closure("store key")) ;
786 $db->filter_store_value(Closure("store value")) ;
787 $db->filter_fetch_key(Closure("fetch key")) ;
788 $db->filter_fetch_value(Closure("fetch value")) ;
793 ok(125, $result{"store key"} eq "store key - 1: [fred]");
794 ok(126, $result{"store value"} eq "store value - 1: [joe]");
795 ok(127, ! defined $result{"fetch key"} );
796 ok(128, ! defined $result{"fetch value"} );
797 ok(129, $_ eq "original") ;
799 ok(130, $db->FIRSTKEY() eq "fred") ;
800 ok(131, $result{"store key"} eq "store key - 1: [fred]");
801 ok(132, $result{"store value"} eq "store value - 1: [joe]");
802 ok(133, $result{"fetch key"} eq "fetch key - 1: [fred]");
803 ok(134, ! defined $result{"fetch value"} );
804 ok(135, $_ eq "original") ;
807 ok(136, $result{"store key"} eq "store key - 2: [fred jim]");
808 ok(137, $result{"store value"} eq "store value - 2: [joe john]");
809 ok(138, $result{"fetch key"} eq "fetch key - 1: [fred]");
810 ok(139, ! defined $result{"fetch value"} );
811 ok(140, $_ eq "original") ;
813 ok(141, $h{"fred"} eq "joe");
814 ok(142, $result{"store key"} eq "store key - 3: [fred jim fred]");
815 ok(143, $result{"store value"} eq "store value - 2: [joe john]");
816 ok(144, $result{"fetch key"} eq "fetch key - 1: [fred]");
817 ok(145, $result{"fetch value"} eq "fetch value - 1: [joe]");
818 ok(146, $_ eq "original") ;
826 # DBM Filter recursion detection
831 ok(147, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
833 $db->filter_store_key (sub { $_ = $h{$_} }) ;
835 eval '$h{1} = 1234' ;
836 ok(148, $@ =~ /^recursion detected in filter_store_key at/ );
845 # Examples from the POD
850 my $redirect = new Redirect $file ;
862 my ($key1, $key2) = @_ ;
863 "\L$key1" cmp "\L$key2" ;
866 # specify the Perl sub that will do the comparison
867 $DB_BTREE->{'compare'} = \&Compare ;
870 tie %h, "DB_File", "tree", O_RDWR|O_CREAT, 0640, $DB_BTREE
871 or die "Cannot open file 'tree': $!\n" ;
873 # Add a key/value pair to the file
874 $h{'Wall'} = 'Larry' ;
875 $h{'Smith'} = 'John' ;
876 $h{'mouse'} = 'mickey' ;
877 $h{'duck'} = 'donald' ;
882 # Cycle through the keys printing them in order.
883 # Note it is not necessary to sort the keys as
884 # the btree will have kept them in order automatically.
893 delete $DB_BTREE->{'compare'} ;
895 ok(149, docat_del($file) eq <<'EOM') ;
902 my $redirect = new Redirect $file ;
910 use vars qw($filename %h ) ;
915 # Enable duplicate records
916 $DB_BTREE->{'flags'} = R_DUP ;
918 tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
919 or die "Cannot open $filename: $!\n";
921 # Add some key/value pairs to the file
922 $h{'Wall'} = 'Larry' ;
923 $h{'Wall'} = 'Brick' ; # Note the duplicate key
924 $h{'Wall'} = 'Brick' ; # Note the duplicate key and value
925 $h{'Smith'} = 'John' ;
926 $h{'mouse'} = 'mickey' ;
928 # iterate through the associative array
929 # and print each key/value pair.
931 { print "$_ -> $h{$_}\n" }
938 ok(150, docat_del($file) eq ($db185mode ? <<'EOM' : <<'EOM') ) ;
953 my $redirect = new Redirect $file ;
961 use vars qw($filename $x %h $status $key $value) ;
966 # Enable duplicate records
967 $DB_BTREE->{'flags'} = R_DUP ;
969 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
970 or die "Cannot open $filename: $!\n";
972 # Add some key/value pairs to the file
973 $h{'Wall'} = 'Larry' ;
974 $h{'Wall'} = 'Brick' ; # Note the duplicate key
975 $h{'Wall'} = 'Brick' ; # Note the duplicate key and value
976 $h{'Smith'} = 'John' ;
977 $h{'mouse'} = 'mickey' ;
979 # iterate through the btree using seq
980 # and print each key/value pair.
982 for ($status = $x->seq($key, $value, R_FIRST) ;
984 $status = $x->seq($key, $value, R_NEXT) )
985 { print "$key -> $value\n" }
992 ok(151, docat_del($file) eq ($db185mode == 1 ? <<'EOM' : <<'EOM') ) ;
1008 my $redirect = new Redirect $file ;
1016 use vars qw($filename $x %h ) ;
1018 $filename = "tree" ;
1020 # Enable duplicate records
1021 $DB_BTREE->{'flags'} = R_DUP ;
1023 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1024 or die "Cannot open $filename: $!\n";
1026 my $cnt = $x->get_dup("Wall") ;
1027 print "Wall occurred $cnt times\n" ;
1029 my %hash = $x->get_dup("Wall", 1) ;
1030 print "Larry is there\n" if $hash{'Larry'} ;
1031 print "There are $hash{'Brick'} Brick Walls\n" ;
1033 my @list = sort $x->get_dup("Wall") ;
1034 print "Wall => [@list]\n" ;
1036 @list = $x->get_dup("Smith") ;
1037 print "Smith => [@list]\n" ;
1039 @list = $x->get_dup("Dog") ;
1040 print "Dog => [@list]\n" ;
1046 ok(152, docat_del($file) eq <<'EOM') ;
1047 Wall occurred 3 times
1049 There are 2 Brick Walls
1050 Wall => [Brick Brick Larry]
1056 my $redirect = new Redirect $file ;
1064 use vars qw($filename $x %h $found) ;
1066 my $filename = "tree" ;
1068 # Enable duplicate records
1069 $DB_BTREE->{'flags'} = R_DUP ;
1071 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1072 or die "Cannot open $filename: $!\n";
1074 $found = ( $x->find_dup("Wall", "Larry") == 0 ? "" : "not") ;
1075 print "Larry Wall is $found there\n" ;
1077 $found = ( $x->find_dup("Wall", "Harry") == 0 ? "" : "not") ;
1078 print "Harry Wall is $found there\n" ;
1084 ok(153, docat_del($file) eq <<'EOM') ;
1086 Harry Wall is not there
1090 my $redirect = new Redirect $file ;
1098 use vars qw($filename $x %h $found) ;
1100 my $filename = "tree" ;
1102 # Enable duplicate records
1103 $DB_BTREE->{'flags'} = R_DUP ;
1105 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1106 or die "Cannot open $filename: $!\n";
1108 $x->del_dup("Wall", "Larry") ;
1110 $found = ( $x->find_dup("Wall", "Larry") == 0 ? "" : "not") ;
1111 print "Larry Wall is $found there\n" ;
1119 ok(154, docat_del($file) eq <<'EOM') ;
1120 Larry Wall is not there
1124 my $redirect = new Redirect $file ;
1133 use vars qw($filename $x %h $st $key $value) ;
1139 my $orig_key = $key ;
1140 $x->seq($key, $value, R_CURSOR) ;
1141 print "$orig_key\t-> $key\t-> $value\n" ;
1144 $filename = "tree" ;
1147 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1148 or die "Cannot open $filename: $!\n";
1150 # Add some key/value pairs to the file
1151 $h{'mouse'} = 'mickey' ;
1152 $h{'Wall'} = 'Larry' ;
1153 $h{'Walls'} = 'Brick' ;
1154 $h{'Smith'} = 'John' ;
1158 print "IN ORDER\n" ;
1159 for ($st = $x->seq($key, $value, R_FIRST) ;
1161 $st = $x->seq($key, $value, R_NEXT) )
1163 { print "$key -> $value\n" }
1165 print "\nPARTIAL MATCH\n" ;
1178 ok(155, docat_del($file) eq <<'EOM') ;
1188 a -> mouse -> mickey
1199 # ok(156, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
1202 # my $k = "newest" ;
1204 # my $status = $db->put($k, $v, R_SETCURSOR) ;
1205 # print "status = [$status]\n" ;
1206 # ok(157, $status == 0) ;
1207 # $status = $db->del($k, R_CURSOR) ;
1208 # print "status = [$status]\n" ;
1209 # ok(158, $status == 0) ;
1211 # ok(159, $db->get($k, $v, R_CURSOR)) ;
1213 # ok(160, keys %h == 1) ;