5 require Config; import Config;
6 if ($Config{'extensions'} !~ /\bDB_File\b/) {
7 print "1..0 # Skip: DB_File was not built\n";
24 print "not " unless $result ;
30 my(@a) = unpack ("C*", $a) ;
31 my(@b) = unpack ("C*", $b) ;
33 my $len = (@a > @b ? @b : @a) ;
36 foreach $i ( 0 .. $len -1) {
37 return $a[$i] - $b[$i] if $a[$i] != $b[$i] ;
50 my $filename = shift ;
52 open ($fh, ">$filename") || die "Cannot open $filename: $!" ;
53 my $real_stdout = select($fh) ;
54 return bless [$fh, $real_stdout ] ;
68 #local $/ = undef unless wantarray ;
69 open(CAT,$file) || die "Cannot open $file: $!";
72 wantarray ? @result : join("", @result) ;
78 #local $/ = undef unless wantarray ;
79 open(CAT,$file) || die "Cannot open $file: $!";
83 wantarray ? @result : join("", @result) ;
87 my $db185mode = ($DB_File::db_version == 1 && ! $DB_File::db_185_compat) ;
88 my $null_keys_allowed = ($DB_File::db_ver < 2.004010
89 || $DB_File::db_ver >= 3.1 );
91 my $Dfile = "dbbtree.tmp";
96 # Check the interface to BTREEINFO
98 my $dbh = new DB_File::BTREEINFO ;
99 ok(1, ! defined $dbh->{flags}) ;
100 ok(2, ! defined $dbh->{cachesize}) ;
101 ok(3, ! defined $dbh->{psize}) ;
102 ok(4, ! defined $dbh->{lorder}) ;
103 ok(5, ! defined $dbh->{minkeypage}) ;
104 ok(6, ! defined $dbh->{maxkeypage}) ;
105 ok(7, ! defined $dbh->{compare}) ;
106 ok(8, ! defined $dbh->{prefix}) ;
108 $dbh->{flags} = 3000 ;
109 ok(9, $dbh->{flags} == 3000) ;
111 $dbh->{cachesize} = 9000 ;
112 ok(10, $dbh->{cachesize} == 9000);
114 $dbh->{psize} = 400 ;
115 ok(11, $dbh->{psize} == 400) ;
117 $dbh->{lorder} = 65 ;
118 ok(12, $dbh->{lorder} == 65) ;
120 $dbh->{minkeypage} = 123 ;
121 ok(13, $dbh->{minkeypage} == 123) ;
123 $dbh->{maxkeypage} = 1234 ;
124 ok(14, $dbh->{maxkeypage} == 1234 );
126 $dbh->{compare} = 1234 ;
127 ok(15, $dbh->{compare} == 1234) ;
129 $dbh->{prefix} = 1234 ;
130 ok(16, $dbh->{prefix} == 1234 );
132 # Check that an invalid entry is caught both for store & fetch
133 eval '$dbh->{fred} = 1234' ;
134 ok(17, $@ =~ /^DB_File::BTREEINFO::STORE - Unknown element 'fred' at/ ) ;
135 eval 'my $q = $dbh->{fred}' ;
136 ok(18, $@ =~ /^DB_File::BTREEINFO::FETCH - Unknown element 'fred' at/ ) ;
138 # Now check the interface to BTREE
141 ok(19, $X = tie(%h, 'DB_File',$Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE )) ;
143 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
144 $blksize,$blocks) = stat($Dfile);
145 ok(20, ($mode & 0777) == (($^O eq 'os2' || $^O eq 'MacOS') ? 0666 : 0640)
146 || $^O eq 'amigaos' || $^O eq 'MSWin32' || $^O eq 'NetWare');
148 my ($key, $value, $i);
149 while (($key,$value) = each(%h)) {
154 $h{'goner1'} = 'snork';
157 ok(22, $h{'abc'} eq 'ABC' );
158 ok(23, ! defined $h{'jimmy'} ) ;
159 ok(24, ! exists $h{'jimmy'} ) ;
160 ok(25, defined $h{'abc'} ) ;
163 $h{'jkl','mno'} = "JKL\034MNO";
164 $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
168 $X->STORE('b', 'B') ;
181 $h{'goner2'} = 'snork';
185 # IMPORTANT - $X must be undefined before the untie otherwise the
186 # underlying DB close routine will not get called.
190 # tie to the same file again
191 ok(26, $X = tie(%h,'DB_File',$Dfile, O_RDWR, 0640, $DB_BTREE)) ;
193 # Modify an entry from the previous tie
214 $h{'goner3'} = 'snork';
217 $X->DELETE('goner3');
220 my @values = values(%h);
222 ok(27, $#keys == 29 && $#values == 29) ;
225 while (($key,$value) = each(%h)) {
226 if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
228 $i++ if $key eq $value;
234 @keys = ('blurfl', keys(%h), 'dyick');
235 ok(29, $#keys == 31) ;
237 #Check that the keys can be retrieved in order
239 my @c = sort lexical @b ;
240 ok(30, ArrayCompare(\@b, \@c)) ;
243 ok(31, $h{'foo'} eq '' ) ;
245 # Berkeley DB from version 2.4.10 to 3.0 does not allow null keys.
246 # This feature was reenabled in version 3.1 of Berkeley DB.
248 if ($null_keys_allowed) {
250 $result = ( $h{''} eq 'bar' );
256 # check cache overflow and numeric keys and contents
258 for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
259 for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
262 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
263 $blksize,$blocks) = stat($Dfile);
266 @h{0..200} = 200..400;
267 my @foo = @h{0..200};
268 ok(35, join(':',200..400) eq join(':',@foo) );
270 # Now check all the non-tie specific stuff
273 # Check R_NOOVERWRITE flag will make put fail when attempting to overwrite
274 # an existing record.
276 my $status = $X->put( 'x', 'newvalue', R_NOOVERWRITE) ;
277 ok(36, $status == 1 );
279 # check that the value of the key 'x' has not been changed by the
281 ok(37, $h{'x'} eq 'X' );
284 $status = $X->put('key', 'value') ;
285 ok(38, $status == 0 );
287 #check that previous put can be retrieved
289 $status = $X->get('key', $value) ;
290 ok(39, $status == 0 );
291 ok(40, $value eq 'value' );
293 # Attempting to delete an existing key should work
295 $status = $X->del('q') ;
296 ok(41, $status == 0 );
297 if ($null_keys_allowed) {
298 $status = $X->del('') ;
302 ok(42, $status == 0 );
304 # Make sure that the key deleted, cannot be retrieved
305 ok(43, ! defined $h{'q'}) ;
306 ok(44, ! defined $h{''}) ;
311 ok(45, $X = tie(%h, 'DB_File',$Dfile, O_RDWR, 0640, $DB_BTREE ));
313 # Attempting to delete a non-existant key should fail
315 $status = $X->del('joe') ;
316 ok(46, $status == 1 );
318 # Check the get interface
320 # First a non-existing key
321 $status = $X->get('aaaa', $value) ;
322 ok(47, $status == 1 );
324 # Next an existing key
325 $status = $X->get('a', $value) ;
326 ok(48, $status == 0 );
327 ok(49, $value eq 'A' );
332 # use seq to find an approximate match
335 $status = $X->seq($key, $value, R_CURSOR) ;
336 ok(50, $status == 0 );
337 ok(51, $key eq 'key' );
338 ok(52, $value eq 'value' );
340 # seq when the key does not match
343 $status = $X->seq($key, $value, R_CURSOR) ;
344 ok(53, $status == 1 );
347 # use seq to set the cursor, then delete the record @ the cursor.
351 $status = $X->seq($key, $value, R_CURSOR) ;
352 ok(54, $status == 0 );
353 ok(55, $key eq 'x' );
354 ok(56, $value eq 'X' );
355 $status = $X->del(0, R_CURSOR) ;
356 ok(57, $status == 0 );
357 $status = $X->get('x', $value) ;
358 ok(58, $status == 1 );
360 # ditto, but use put to replace the key/value pair.
363 $status = $X->seq($key, $value, R_CURSOR) ;
364 ok(59, $status == 0 );
365 ok(60, $key eq 'y' );
366 ok(61, $value eq 'Y' );
368 $key = "replace key" ;
369 $value = "replace value" ;
370 $status = $X->put($key, $value, R_CURSOR) ;
371 ok(62, $status == 0 );
372 ok(63, $key eq 'replace key' );
373 ok(64, $value eq 'replace value' );
374 $status = $X->get('y', $value) ;
375 ok(65, 1) ; # hard-wire to always pass. the previous test ($status == 1)
376 # only worked because of a bug in 1.85/6
378 # use seq to walk forwards through a file
380 $status = $X->seq($key, $value, R_FIRST) ;
381 ok(66, $status == 0 );
382 my $previous = $key ;
385 while (($status = $X->seq($key, $value, R_NEXT)) == 0)
387 ($ok = 0), last if ($previous cmp $key) == 1 ;
390 ok(67, $status == 1 );
393 # use seq to walk backwards through a file
394 $status = $X->seq($key, $value, R_LAST) ;
395 ok(69, $status == 0 );
399 while (($status = $X->seq($key, $value, R_PREV)) == 0)
401 ($ok = 0), last if ($previous cmp $key) == -1 ;
402 #print "key = [$key] value = [$value]\n" ;
405 ok(70, $status == 1 );
409 # check seq FIRST/LAST
415 ok(72, $status == 0 );
422 ok(73, $status != 0 );
430 # Now try an in memory file
432 ok(74, $Y = tie(%h, 'DB_File',undef, O_RDWR|O_CREAT, 0640, $DB_BTREE ));
434 # fd with an in memory file should return failure
436 ok(75, $status == -1 );
443 my $bt = new DB_File::BTREEINFO ;
444 $bt->{flags} = R_DUP ;
446 ok(76, $YY = tie(%hh, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $bt )) ;
448 $hh{'Wall'} = 'Larry' ;
449 $hh{'Wall'} = 'Stone' ; # Note the duplicate key
450 $hh{'Wall'} = 'Brick' ; # Note the duplicate key
451 $hh{'Wall'} = 'Brick' ; # Note the duplicate key and value
452 $hh{'Smith'} = 'John' ;
453 $hh{'mouse'} = 'mickey' ;
455 # first work in scalar context
456 ok(77, scalar $YY->get_dup('Unknown') == 0 );
457 ok(78, scalar $YY->get_dup('Smith') == 1 );
458 ok(79, scalar $YY->get_dup('Wall') == 4 );
460 # now in list context
461 my @unknown = $YY->get_dup('Unknown') ;
462 ok(80, "@unknown" eq "" );
464 my @smith = $YY->get_dup('Smith') ;
465 ok(81, "@smith" eq "John" );
468 my @wall = $YY->get_dup('Wall') ;
470 @wall{@wall} = @wall ;
471 ok(82, (@wall == 4 && $wall{'Larry'} && $wall{'Stone'} && $wall{'Brick'}) );
475 my %unknown = $YY->get_dup('Unknown', 1) ;
476 ok(83, keys %unknown == 0 );
478 my %smith = $YY->get_dup('Smith', 1) ;
479 ok(84, keys %smith == 1 && $smith{'John'}) ;
481 my %wall = $YY->get_dup('Wall', 1) ;
482 ok(85, keys %wall == 3 && $wall{'Larry'} == 1 && $wall{'Stone'} == 1
483 && $wall{'Brick'} == 2);
490 # test multiple callbacks
491 my $Dfile1 = "btree1" ;
492 my $Dfile2 = "btree2" ;
493 my $Dfile3 = "btree3" ;
495 my $dbh1 = new DB_File::BTREEINFO ;
496 $dbh1->{compare} = sub {
497 no warnings 'numeric' ;
500 my $dbh2 = new DB_File::BTREEINFO ;
501 $dbh2->{compare} = sub { $_[0] cmp $_[1] } ;
503 my $dbh3 = new DB_File::BTREEINFO ;
504 $dbh3->{compare} = sub { length $_[0] <=> length $_[1] } ;
508 tie(%h, 'DB_File',$Dfile1, O_RDWR|O_CREAT, 0640, $dbh1 ) ;
509 tie(%g, 'DB_File',$Dfile2, O_RDWR|O_CREAT, 0640, $dbh2 ) ;
510 tie(%k, 'DB_File',$Dfile3, O_RDWR|O_CREAT, 0640, $dbh3 ) ;
512 my @Keys = qw( 0123 12 -1234 9 987654321 def ) ;
513 my (@srt_1, @srt_2, @srt_3);
515 no warnings 'numeric' ;
516 @srt_1 = sort { $a <=> $b } @Keys ;
518 @srt_2 = sort { $a cmp $b } @Keys ;
519 @srt_3 = sort { length $a <=> length $b } @Keys ;
531 return 0 if @$a != @$b ;
533 foreach (1 .. length @$a)
535 return 0 unless $$a[$_] eq $$b[$_] ;
541 ok(86, ArrayCompare (\@srt_1, [keys %h]) );
542 ok(87, ArrayCompare (\@srt_2, [keys %g]) );
543 ok(88, ArrayCompare (\@srt_3, [keys %k]) );
548 unlink $Dfile1, $Dfile2, $Dfile3 ;
553 ok(89, tie(%h, 'DB_File', $Dfile1, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
555 { $h{$_} = $_ * 100 }
557 # check that there are 10 elements in the hash
559 while (($key,$value) = each(%h)) {
569 while (($key,$value) = each(%h)) {
578 # check that attempting to tie an array to a DB_BTREE will fail
580 my $filename = "xyz" ;
582 eval { tie @x, 'DB_File', $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE ; } ;
583 ok(92, $@ =~ /^DB_File can only tie an associative array to a DB_BTREE database/) ;
595 open(FILE, ">SubDB.pm") or die "Cannot open SubDB.pm: $!\n" ;
602 use vars qw( @ISA @EXPORT) ;
607 @EXPORT = @DB_File::EXPORT ;
613 $self->SUPER::STORE($key, $value * 2) ;
619 $self->SUPER::FETCH($key) - 1 ;
626 $self->SUPER::put($key, $value * 3) ;
631 $self->SUPER::get($_[0], $_[1]) ;
639 my $value = $self->FETCH($key) ;
640 return "[[$value]]" ;
648 BEGIN { push @INC, '.'; }
650 main::ok(93, $@ eq "") ;
654 $X = tie(%h, "SubDB","dbbtree.tmp", O_RDWR|O_CREAT, 0640, $DB_BTREE );
657 main::ok(94, $@ eq "") ;
659 my $ret = eval '$h{"fred"} = 3 ; return $h{"fred"} ' ;
660 main::ok(95, $@ eq "") ;
661 main::ok(96, $ret == 5) ;
664 $ret = eval '$X->put("joe", 4) ; $X->get("joe", $value) ; return $value' ;
665 main::ok(97, $@ eq "") ;
666 main::ok(98, $ret == 10) ;
668 $ret = eval ' R_NEXT eq main::R_NEXT ' ;
669 main::ok(99, $@ eq "" ) ;
670 main::ok(100, $ret == 1) ;
672 $ret = eval '$X->A_new_method("joe") ' ;
673 main::ok(101, $@ eq "") ;
674 main::ok(102, $ret eq "[[11]]") ;
678 unlink "SubDB.pm", "dbbtree.tmp" ;
687 my ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
692 my($fk, $sk, $fv, $sv) = @_ ;
694 $fetch_key eq $fk && $store_key eq $sk &&
695 $fetch_value eq $fv && $store_value eq $sv &&
699 ok(103, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
701 $db->filter_fetch_key (sub { $fetch_key = $_ }) ;
702 $db->filter_store_key (sub { $store_key = $_ }) ;
703 $db->filter_fetch_value (sub { $fetch_value = $_}) ;
704 $db->filter_store_value (sub { $store_value = $_ }) ;
710 ok(104, checkOutput( "", "fred", "", "joe")) ;
712 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
713 ok(105, $h{"fred"} eq "joe");
715 ok(106, checkOutput( "", "fred", "joe", "")) ;
717 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
718 ok(107, $db->FIRSTKEY() eq "fred") ;
720 ok(108, checkOutput( "fred", "", "", "")) ;
722 # replace the filters, but remember the previous set
723 my ($old_fk) = $db->filter_fetch_key
724 (sub { $_ = uc $_ ; $fetch_key = $_ }) ;
725 my ($old_sk) = $db->filter_store_key
726 (sub { $_ = lc $_ ; $store_key = $_ }) ;
727 my ($old_fv) = $db->filter_fetch_value
728 (sub { $_ = "[$_]"; $fetch_value = $_ }) ;
729 my ($old_sv) = $db->filter_store_value
730 (sub { s/o/x/g; $store_value = $_ }) ;
732 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
735 ok(109, checkOutput( "", "fred", "", "Jxe")) ;
737 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
738 ok(110, $h{"Fred"} eq "[Jxe]");
740 ok(111, checkOutput( "", "fred", "[Jxe]", "")) ;
742 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
743 ok(112, $db->FIRSTKEY() eq "FRED") ;
745 ok(113, checkOutput( "FRED", "", "", "")) ;
747 # put the original filters back
748 $db->filter_fetch_key ($old_fk);
749 $db->filter_store_key ($old_sk);
750 $db->filter_fetch_value ($old_fv);
751 $db->filter_store_value ($old_sv);
753 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
755 ok(114, checkOutput( "", "fred", "", "joe")) ;
757 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
758 ok(115, $h{"fred"} eq "joe");
759 ok(116, checkOutput( "", "fred", "joe", "")) ;
761 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
762 ok(117, $db->FIRSTKEY() eq "fred") ;
763 ok(118, checkOutput( "fred", "", "", "")) ;
766 $db->filter_fetch_key (undef);
767 $db->filter_store_key (undef);
768 $db->filter_fetch_value (undef);
769 $db->filter_store_value (undef);
771 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
773 ok(119, checkOutput( "", "", "", "")) ;
775 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
776 ok(120, $h{"fred"} eq "joe");
777 ok(121, checkOutput( "", "", "", "")) ;
779 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
780 ok(122, $db->FIRSTKEY() eq "fred") ;
781 ok(123, checkOutput( "", "", "", "")) ;
789 # DBM Filter with a closure
796 ok(124, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
806 return sub { ++$count ;
808 $result{$name} = "$name - $count: [@kept]" ;
812 $db->filter_store_key(Closure("store key")) ;
813 $db->filter_store_value(Closure("store value")) ;
814 $db->filter_fetch_key(Closure("fetch key")) ;
815 $db->filter_fetch_value(Closure("fetch value")) ;
820 ok(125, $result{"store key"} eq "store key - 1: [fred]");
821 ok(126, $result{"store value"} eq "store value - 1: [joe]");
822 ok(127, ! defined $result{"fetch key"} );
823 ok(128, ! defined $result{"fetch value"} );
824 ok(129, $_ eq "original") ;
826 ok(130, $db->FIRSTKEY() eq "fred") ;
827 ok(131, $result{"store key"} eq "store key - 1: [fred]");
828 ok(132, $result{"store value"} eq "store value - 1: [joe]");
829 ok(133, $result{"fetch key"} eq "fetch key - 1: [fred]");
830 ok(134, ! defined $result{"fetch value"} );
831 ok(135, $_ eq "original") ;
834 ok(136, $result{"store key"} eq "store key - 2: [fred jim]");
835 ok(137, $result{"store value"} eq "store value - 2: [joe john]");
836 ok(138, $result{"fetch key"} eq "fetch key - 1: [fred]");
837 ok(139, ! defined $result{"fetch value"} );
838 ok(140, $_ eq "original") ;
840 ok(141, $h{"fred"} eq "joe");
841 ok(142, $result{"store key"} eq "store key - 3: [fred jim fred]");
842 ok(143, $result{"store value"} eq "store value - 2: [joe john]");
843 ok(144, $result{"fetch key"} eq "fetch key - 1: [fred]");
844 ok(145, $result{"fetch value"} eq "fetch value - 1: [joe]");
845 ok(146, $_ eq "original") ;
853 # DBM Filter recursion detection
859 ok(147, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
861 $db->filter_store_key (sub { $_ = $h{$_} }) ;
863 eval '$h{1} = 1234' ;
864 ok(148, $@ =~ /^recursion detected in filter_store_key at/ );
873 # Examples from the POD
878 my $redirect = new Redirect $file ;
883 use warnings FATAL => qw(all) ;
891 my ($key1, $key2) = @_ ;
892 "\L$key1" cmp "\L$key2" ;
895 # specify the Perl sub that will do the comparison
896 $DB_BTREE->{'compare'} = \&Compare ;
899 tie %h, "DB_File", "tree", O_RDWR|O_CREAT, 0640, $DB_BTREE
900 or die "Cannot open file 'tree': $!\n" ;
902 # Add a key/value pair to the file
903 $h{'Wall'} = 'Larry' ;
904 $h{'Smith'} = 'John' ;
905 $h{'mouse'} = 'mickey' ;
906 $h{'duck'} = 'donald' ;
911 # Cycle through the keys printing them in order.
912 # Note it is not necessary to sort the keys as
913 # the btree will have kept them in order automatically.
922 delete $DB_BTREE->{'compare'} ;
924 ok(149, docat_del($file) eq <<'EOM') ;
931 my $redirect = new Redirect $file ;
936 use warnings FATAL => qw(all) ;
940 use vars qw($filename %h ) ;
945 # Enable duplicate records
946 $DB_BTREE->{'flags'} = R_DUP ;
948 tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
949 or die "Cannot open $filename: $!\n";
951 # Add some key/value pairs to the file
952 $h{'Wall'} = 'Larry' ;
953 $h{'Wall'} = 'Brick' ; # Note the duplicate key
954 $h{'Wall'} = 'Brick' ; # Note the duplicate key and value
955 $h{'Smith'} = 'John' ;
956 $h{'mouse'} = 'mickey' ;
958 # iterate through the associative array
959 # and print each key/value pair.
961 { print "$_ -> $h{$_}\n" }
968 ok(150, docat_del($file) eq ($db185mode ? <<'EOM' : <<'EOM') ) ;
983 my $redirect = new Redirect $file ;
988 use warnings FATAL => qw(all) ;
992 use vars qw($filename $x %h $status $key $value) ;
997 # Enable duplicate records
998 $DB_BTREE->{'flags'} = R_DUP ;
1000 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1001 or die "Cannot open $filename: $!\n";
1003 # Add some key/value pairs to the file
1004 $h{'Wall'} = 'Larry' ;
1005 $h{'Wall'} = 'Brick' ; # Note the duplicate key
1006 $h{'Wall'} = 'Brick' ; # Note the duplicate key and value
1007 $h{'Smith'} = 'John' ;
1008 $h{'mouse'} = 'mickey' ;
1010 # iterate through the btree using seq
1011 # and print each key/value pair.
1013 for ($status = $x->seq($key, $value, R_FIRST) ;
1015 $status = $x->seq($key, $value, R_NEXT) )
1016 { print "$key -> $value\n" }
1023 ok(151, docat_del($file) eq ($db185mode == 1 ? <<'EOM' : <<'EOM') ) ;
1039 my $redirect = new Redirect $file ;
1044 use warnings FATAL => qw(all) ;
1048 use vars qw($filename $x %h ) ;
1050 $filename = "tree" ;
1052 # Enable duplicate records
1053 $DB_BTREE->{'flags'} = R_DUP ;
1055 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1056 or die "Cannot open $filename: $!\n";
1058 my $cnt = $x->get_dup("Wall") ;
1059 print "Wall occurred $cnt times\n" ;
1061 my %hash = $x->get_dup("Wall", 1) ;
1062 print "Larry is there\n" if $hash{'Larry'} ;
1063 print "There are $hash{'Brick'} Brick Walls\n" ;
1065 my @list = sort $x->get_dup("Wall") ;
1066 print "Wall => [@list]\n" ;
1068 @list = $x->get_dup("Smith") ;
1069 print "Smith => [@list]\n" ;
1071 @list = $x->get_dup("Dog") ;
1072 print "Dog => [@list]\n" ;
1078 ok(152, docat_del($file) eq <<'EOM') ;
1079 Wall occurred 3 times
1081 There are 2 Brick Walls
1082 Wall => [Brick Brick Larry]
1088 my $redirect = new Redirect $file ;
1093 use warnings FATAL => qw(all) ;
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 $found = ( $x->find_dup("Wall", "Larry") == 0 ? "" : "not") ;
1108 print "Larry Wall is $found there\n" ;
1110 $found = ( $x->find_dup("Wall", "Harry") == 0 ? "" : "not") ;
1111 print "Harry Wall is $found there\n" ;
1117 ok(153, docat_del($file) eq <<'EOM') ;
1119 Harry Wall is not there
1123 my $redirect = new Redirect $file ;
1128 use warnings FATAL => qw(all) ;
1132 use vars qw($filename $x %h $found) ;
1134 my $filename = "tree" ;
1136 # Enable duplicate records
1137 $DB_BTREE->{'flags'} = R_DUP ;
1139 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1140 or die "Cannot open $filename: $!\n";
1142 $x->del_dup("Wall", "Larry") ;
1144 $found = ( $x->find_dup("Wall", "Larry") == 0 ? "" : "not") ;
1145 print "Larry Wall is $found there\n" ;
1153 ok(154, docat_del($file) eq <<'EOM') ;
1154 Larry Wall is not there
1158 my $redirect = new Redirect $file ;
1163 use warnings FATAL => qw(all) ;
1168 use vars qw($filename $x %h $st $key $value) ;
1174 my $orig_key = $key ;
1175 $x->seq($key, $value, R_CURSOR) ;
1176 print "$orig_key\t-> $key\t-> $value\n" ;
1179 $filename = "tree" ;
1182 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1183 or die "Cannot open $filename: $!\n";
1185 # Add some key/value pairs to the file
1186 $h{'mouse'} = 'mickey' ;
1187 $h{'Wall'} = 'Larry' ;
1188 $h{'Walls'} = 'Brick' ;
1189 $h{'Smith'} = 'John' ;
1193 print "IN ORDER\n" ;
1194 for ($st = $x->seq($key, $value, R_FIRST) ;
1196 $st = $x->seq($key, $value, R_NEXT) )
1198 { print "$key -> $value\n" }
1200 print "\nPARTIAL MATCH\n" ;
1213 ok(155, docat_del($file) eq <<'EOM') ;
1223 a -> mouse -> mickey
1234 # ok(156, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
1237 # my $k = "newest" ;
1239 # my $status = $db->put($k, $v, R_SETCURSOR) ;
1240 # print "status = [$status]\n" ;
1241 # ok(157, $status == 0) ;
1242 # $status = $db->del($k, R_CURSOR) ;
1243 # print "status = [$status]\n" ;
1244 # ok(158, $status == 0) ;
1246 # ok(159, $db->get($k, $v, R_CURSOR)) ;
1248 # ok(160, keys %h == 1) ;
1256 # Bug ID 20001013.009
1258 # test that $hash{KEY} = undef doesn't produce the warning
1259 # Use of uninitialized value in null operation
1267 local $SIG{__WARN__} = sub {$a = $_[0]} ;
1269 tie %h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0664, $DB_BTREE
1270 or die "Can't open file: $!\n" ;
1278 # test that %hash = () doesn't produce the warning
1279 # Argument "" isn't numeric in entersub
1287 local $SIG{__WARN__} = sub {$a = $_[0]} ;
1289 tie %h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0664, $DB_BTREE
1290 or die "Can't open file: $!\n" ;