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' ? 0666 : 0640) || $^O eq 'amigaos' || $^O eq 'MSWin32' || $^O eq 'NetWare');
147 my ($key, $value, $i);
148 while (($key,$value) = each(%h)) {
153 $h{'goner1'} = 'snork';
156 ok(22, $h{'abc'} eq 'ABC' );
157 ok(23, ! defined $h{'jimmy'} ) ;
158 ok(24, ! exists $h{'jimmy'} ) ;
159 ok(25, defined $h{'abc'} ) ;
162 $h{'jkl','mno'} = "JKL\034MNO";
163 $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
167 $X->STORE('b', 'B') ;
180 $h{'goner2'} = 'snork';
184 # IMPORTANT - $X must be undefined before the untie otherwise the
185 # underlying DB close routine will not get called.
189 # tie to the same file again
190 ok(26, $X = tie(%h,'DB_File',$Dfile, O_RDWR, 0640, $DB_BTREE)) ;
192 # Modify an entry from the previous tie
213 $h{'goner3'} = 'snork';
216 $X->DELETE('goner3');
219 my @values = values(%h);
221 ok(27, $#keys == 29 && $#values == 29) ;
224 while (($key,$value) = each(%h)) {
225 if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
227 $i++ if $key eq $value;
233 @keys = ('blurfl', keys(%h), 'dyick');
234 ok(29, $#keys == 31) ;
236 #Check that the keys can be retrieved in order
238 my @c = sort lexical @b ;
239 ok(30, ArrayCompare(\@b, \@c)) ;
242 ok(31, $h{'foo'} eq '' ) ;
244 # Berkeley DB from version 2.4.10 to 3.0 does not allow null keys.
245 # This feature was reenabled in version 3.1 of Berkeley DB.
247 if ($null_keys_allowed) {
249 $result = ( $h{''} eq 'bar' );
255 # check cache overflow and numeric keys and contents
257 for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
258 for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
261 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
262 $blksize,$blocks) = stat($Dfile);
265 @h{0..200} = 200..400;
266 my @foo = @h{0..200};
267 ok(35, join(':',200..400) eq join(':',@foo) );
269 # Now check all the non-tie specific stuff
272 # Check R_NOOVERWRITE flag will make put fail when attempting to overwrite
273 # an existing record.
275 my $status = $X->put( 'x', 'newvalue', R_NOOVERWRITE) ;
276 ok(36, $status == 1 );
278 # check that the value of the key 'x' has not been changed by the
280 ok(37, $h{'x'} eq 'X' );
283 $status = $X->put('key', 'value') ;
284 ok(38, $status == 0 );
286 #check that previous put can be retrieved
288 $status = $X->get('key', $value) ;
289 ok(39, $status == 0 );
290 ok(40, $value eq 'value' );
292 # Attempting to delete an existing key should work
294 $status = $X->del('q') ;
295 ok(41, $status == 0 );
296 if ($null_keys_allowed) {
297 $status = $X->del('') ;
301 ok(42, $status == 0 );
303 # Make sure that the key deleted, cannot be retrieved
304 ok(43, ! defined $h{'q'}) ;
305 ok(44, ! defined $h{''}) ;
310 ok(45, $X = tie(%h, 'DB_File',$Dfile, O_RDWR, 0640, $DB_BTREE ));
312 # Attempting to delete a non-existant key should fail
314 $status = $X->del('joe') ;
315 ok(46, $status == 1 );
317 # Check the get interface
319 # First a non-existing key
320 $status = $X->get('aaaa', $value) ;
321 ok(47, $status == 1 );
323 # Next an existing key
324 $status = $X->get('a', $value) ;
325 ok(48, $status == 0 );
326 ok(49, $value eq 'A' );
331 # use seq to find an approximate match
334 $status = $X->seq($key, $value, R_CURSOR) ;
335 ok(50, $status == 0 );
336 ok(51, $key eq 'key' );
337 ok(52, $value eq 'value' );
339 # seq when the key does not match
342 $status = $X->seq($key, $value, R_CURSOR) ;
343 ok(53, $status == 1 );
346 # use seq to set the cursor, then delete the record @ the cursor.
350 $status = $X->seq($key, $value, R_CURSOR) ;
351 ok(54, $status == 0 );
352 ok(55, $key eq 'x' );
353 ok(56, $value eq 'X' );
354 $status = $X->del(0, R_CURSOR) ;
355 ok(57, $status == 0 );
356 $status = $X->get('x', $value) ;
357 ok(58, $status == 1 );
359 # ditto, but use put to replace the key/value pair.
362 $status = $X->seq($key, $value, R_CURSOR) ;
363 ok(59, $status == 0 );
364 ok(60, $key eq 'y' );
365 ok(61, $value eq 'Y' );
367 $key = "replace key" ;
368 $value = "replace value" ;
369 $status = $X->put($key, $value, R_CURSOR) ;
370 ok(62, $status == 0 );
371 ok(63, $key eq 'replace key' );
372 ok(64, $value eq 'replace value' );
373 $status = $X->get('y', $value) ;
374 ok(65, 1) ; # hard-wire to always pass. the previous test ($status == 1)
375 # only worked because of a bug in 1.85/6
377 # use seq to walk forwards through a file
379 $status = $X->seq($key, $value, R_FIRST) ;
380 ok(66, $status == 0 );
381 my $previous = $key ;
384 while (($status = $X->seq($key, $value, R_NEXT)) == 0)
386 ($ok = 0), last if ($previous cmp $key) == 1 ;
389 ok(67, $status == 1 );
392 # use seq to walk backwards through a file
393 $status = $X->seq($key, $value, R_LAST) ;
394 ok(69, $status == 0 );
398 while (($status = $X->seq($key, $value, R_PREV)) == 0)
400 ($ok = 0), last if ($previous cmp $key) == -1 ;
401 #print "key = [$key] value = [$value]\n" ;
404 ok(70, $status == 1 );
408 # check seq FIRST/LAST
414 ok(72, $status == 0 );
421 ok(73, $status != 0 );
429 # Now try an in memory file
431 ok(74, $Y = tie(%h, 'DB_File',undef, O_RDWR|O_CREAT, 0640, $DB_BTREE ));
433 # fd with an in memory file should return failure
435 ok(75, $status == -1 );
442 my $bt = new DB_File::BTREEINFO ;
443 $bt->{flags} = R_DUP ;
445 ok(76, $YY = tie(%hh, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $bt )) ;
447 $hh{'Wall'} = 'Larry' ;
448 $hh{'Wall'} = 'Stone' ; # Note the duplicate key
449 $hh{'Wall'} = 'Brick' ; # Note the duplicate key
450 $hh{'Wall'} = 'Brick' ; # Note the duplicate key and value
451 $hh{'Smith'} = 'John' ;
452 $hh{'mouse'} = 'mickey' ;
454 # first work in scalar context
455 ok(77, scalar $YY->get_dup('Unknown') == 0 );
456 ok(78, scalar $YY->get_dup('Smith') == 1 );
457 ok(79, scalar $YY->get_dup('Wall') == 4 );
459 # now in list context
460 my @unknown = $YY->get_dup('Unknown') ;
461 ok(80, "@unknown" eq "" );
463 my @smith = $YY->get_dup('Smith') ;
464 ok(81, "@smith" eq "John" );
467 my @wall = $YY->get_dup('Wall') ;
469 @wall{@wall} = @wall ;
470 ok(82, (@wall == 4 && $wall{'Larry'} && $wall{'Stone'} && $wall{'Brick'}) );
474 my %unknown = $YY->get_dup('Unknown', 1) ;
475 ok(83, keys %unknown == 0 );
477 my %smith = $YY->get_dup('Smith', 1) ;
478 ok(84, keys %smith == 1 && $smith{'John'}) ;
480 my %wall = $YY->get_dup('Wall', 1) ;
481 ok(85, keys %wall == 3 && $wall{'Larry'} == 1 && $wall{'Stone'} == 1
482 && $wall{'Brick'} == 2);
489 # test multiple callbacks
490 my $Dfile1 = "btree1" ;
491 my $Dfile2 = "btree2" ;
492 my $Dfile3 = "btree3" ;
494 my $dbh1 = new DB_File::BTREEINFO ;
495 $dbh1->{compare} = sub {
496 no warnings 'numeric' ;
499 my $dbh2 = new DB_File::BTREEINFO ;
500 $dbh2->{compare} = sub { $_[0] cmp $_[1] } ;
502 my $dbh3 = new DB_File::BTREEINFO ;
503 $dbh3->{compare} = sub { length $_[0] <=> length $_[1] } ;
507 tie(%h, 'DB_File',$Dfile1, O_RDWR|O_CREAT, 0640, $dbh1 ) ;
508 tie(%g, 'DB_File',$Dfile2, O_RDWR|O_CREAT, 0640, $dbh2 ) ;
509 tie(%k, 'DB_File',$Dfile3, O_RDWR|O_CREAT, 0640, $dbh3 ) ;
511 my @Keys = qw( 0123 12 -1234 9 987654321 def ) ;
512 my (@srt_1, @srt_2, @srt_3);
514 no warnings 'numeric' ;
515 @srt_1 = sort { $a <=> $b } @Keys ;
517 @srt_2 = sort { $a cmp $b } @Keys ;
518 @srt_3 = sort { length $a <=> length $b } @Keys ;
530 return 0 if @$a != @$b ;
532 foreach (1 .. length @$a)
534 return 0 unless $$a[$_] eq $$b[$_] ;
540 ok(86, ArrayCompare (\@srt_1, [keys %h]) );
541 ok(87, ArrayCompare (\@srt_2, [keys %g]) );
542 ok(88, ArrayCompare (\@srt_3, [keys %k]) );
547 unlink $Dfile1, $Dfile2, $Dfile3 ;
552 ok(89, tie(%h, 'DB_File', $Dfile1, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
554 { $h{$_} = $_ * 100 }
556 # check that there are 10 elements in the hash
558 while (($key,$value) = each(%h)) {
568 while (($key,$value) = each(%h)) {
577 # check that attempting to tie an array to a DB_BTREE will fail
579 my $filename = "xyz" ;
581 eval { tie @x, 'DB_File', $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE ; } ;
582 ok(92, $@ =~ /^DB_File can only tie an associative array to a DB_BTREE database/) ;
594 open(FILE, ">SubDB.pm") or die "Cannot open SubDB.pm: $!\n" ;
601 use vars qw( @ISA @EXPORT) ;
606 @EXPORT = @DB_File::EXPORT ;
612 $self->SUPER::STORE($key, $value * 2) ;
618 $self->SUPER::FETCH($key) - 1 ;
625 $self->SUPER::put($key, $value * 3) ;
630 $self->SUPER::get($_[0], $_[1]) ;
638 my $value = $self->FETCH($key) ;
639 return "[[$value]]" ;
647 BEGIN { push @INC, '.'; }
649 main::ok(93, $@ eq "") ;
653 $X = tie(%h, "SubDB","dbbtree.tmp", O_RDWR|O_CREAT, 0640, $DB_BTREE );
656 main::ok(94, $@ eq "") ;
658 my $ret = eval '$h{"fred"} = 3 ; return $h{"fred"} ' ;
659 main::ok(95, $@ eq "") ;
660 main::ok(96, $ret == 5) ;
663 $ret = eval '$X->put("joe", 4) ; $X->get("joe", $value) ; return $value' ;
664 main::ok(97, $@ eq "") ;
665 main::ok(98, $ret == 10) ;
667 $ret = eval ' R_NEXT eq main::R_NEXT ' ;
668 main::ok(99, $@ eq "" ) ;
669 main::ok(100, $ret == 1) ;
671 $ret = eval '$X->A_new_method("joe") ' ;
672 main::ok(101, $@ eq "") ;
673 main::ok(102, $ret eq "[[11]]") ;
677 unlink "SubDB.pm", "dbbtree.tmp" ;
686 my ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
691 my($fk, $sk, $fv, $sv) = @_ ;
693 $fetch_key eq $fk && $store_key eq $sk &&
694 $fetch_value eq $fv && $store_value eq $sv &&
698 ok(103, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
700 $db->filter_fetch_key (sub { $fetch_key = $_ }) ;
701 $db->filter_store_key (sub { $store_key = $_ }) ;
702 $db->filter_fetch_value (sub { $fetch_value = $_}) ;
703 $db->filter_store_value (sub { $store_value = $_ }) ;
709 ok(104, checkOutput( "", "fred", "", "joe")) ;
711 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
712 ok(105, $h{"fred"} eq "joe");
714 ok(106, checkOutput( "", "fred", "joe", "")) ;
716 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
717 ok(107, $db->FIRSTKEY() eq "fred") ;
719 ok(108, checkOutput( "fred", "", "", "")) ;
721 # replace the filters, but remember the previous set
722 my ($old_fk) = $db->filter_fetch_key
723 (sub { $_ = uc $_ ; $fetch_key = $_ }) ;
724 my ($old_sk) = $db->filter_store_key
725 (sub { $_ = lc $_ ; $store_key = $_ }) ;
726 my ($old_fv) = $db->filter_fetch_value
727 (sub { $_ = "[$_]"; $fetch_value = $_ }) ;
728 my ($old_sv) = $db->filter_store_value
729 (sub { s/o/x/g; $store_value = $_ }) ;
731 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
734 ok(109, checkOutput( "", "fred", "", "Jxe")) ;
736 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
737 ok(110, $h{"Fred"} eq "[Jxe]");
739 ok(111, checkOutput( "", "fred", "[Jxe]", "")) ;
741 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
742 ok(112, $db->FIRSTKEY() eq "FRED") ;
744 ok(113, checkOutput( "FRED", "", "", "")) ;
746 # put the original filters back
747 $db->filter_fetch_key ($old_fk);
748 $db->filter_store_key ($old_sk);
749 $db->filter_fetch_value ($old_fv);
750 $db->filter_store_value ($old_sv);
752 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
754 ok(114, checkOutput( "", "fred", "", "joe")) ;
756 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
757 ok(115, $h{"fred"} eq "joe");
758 ok(116, checkOutput( "", "fred", "joe", "")) ;
760 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
761 ok(117, $db->FIRSTKEY() eq "fred") ;
762 ok(118, checkOutput( "fred", "", "", "")) ;
765 $db->filter_fetch_key (undef);
766 $db->filter_store_key (undef);
767 $db->filter_fetch_value (undef);
768 $db->filter_store_value (undef);
770 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
772 ok(119, checkOutput( "", "", "", "")) ;
774 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
775 ok(120, $h{"fred"} eq "joe");
776 ok(121, checkOutput( "", "", "", "")) ;
778 ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
779 ok(122, $db->FIRSTKEY() eq "fred") ;
780 ok(123, checkOutput( "", "", "", "")) ;
788 # DBM Filter with a closure
795 ok(124, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
805 return sub { ++$count ;
807 $result{$name} = "$name - $count: [@kept]" ;
811 $db->filter_store_key(Closure("store key")) ;
812 $db->filter_store_value(Closure("store value")) ;
813 $db->filter_fetch_key(Closure("fetch key")) ;
814 $db->filter_fetch_value(Closure("fetch value")) ;
819 ok(125, $result{"store key"} eq "store key - 1: [fred]");
820 ok(126, $result{"store value"} eq "store value - 1: [joe]");
821 ok(127, ! defined $result{"fetch key"} );
822 ok(128, ! defined $result{"fetch value"} );
823 ok(129, $_ eq "original") ;
825 ok(130, $db->FIRSTKEY() eq "fred") ;
826 ok(131, $result{"store key"} eq "store key - 1: [fred]");
827 ok(132, $result{"store value"} eq "store value - 1: [joe]");
828 ok(133, $result{"fetch key"} eq "fetch key - 1: [fred]");
829 ok(134, ! defined $result{"fetch value"} );
830 ok(135, $_ eq "original") ;
833 ok(136, $result{"store key"} eq "store key - 2: [fred jim]");
834 ok(137, $result{"store value"} eq "store value - 2: [joe john]");
835 ok(138, $result{"fetch key"} eq "fetch key - 1: [fred]");
836 ok(139, ! defined $result{"fetch value"} );
837 ok(140, $_ eq "original") ;
839 ok(141, $h{"fred"} eq "joe");
840 ok(142, $result{"store key"} eq "store key - 3: [fred jim fred]");
841 ok(143, $result{"store value"} eq "store value - 2: [joe john]");
842 ok(144, $result{"fetch key"} eq "fetch key - 1: [fred]");
843 ok(145, $result{"fetch value"} eq "fetch value - 1: [joe]");
844 ok(146, $_ eq "original") ;
852 # DBM Filter recursion detection
858 ok(147, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
860 $db->filter_store_key (sub { $_ = $h{$_} }) ;
862 eval '$h{1} = 1234' ;
863 ok(148, $@ =~ /^recursion detected in filter_store_key at/ );
872 # Examples from the POD
877 my $redirect = new Redirect $file ;
882 use warnings FATAL => qw(all) ;
890 my ($key1, $key2) = @_ ;
891 "\L$key1" cmp "\L$key2" ;
894 # specify the Perl sub that will do the comparison
895 $DB_BTREE->{'compare'} = \&Compare ;
898 tie %h, "DB_File", "tree", O_RDWR|O_CREAT, 0640, $DB_BTREE
899 or die "Cannot open file 'tree': $!\n" ;
901 # Add a key/value pair to the file
902 $h{'Wall'} = 'Larry' ;
903 $h{'Smith'} = 'John' ;
904 $h{'mouse'} = 'mickey' ;
905 $h{'duck'} = 'donald' ;
910 # Cycle through the keys printing them in order.
911 # Note it is not necessary to sort the keys as
912 # the btree will have kept them in order automatically.
921 delete $DB_BTREE->{'compare'} ;
923 ok(149, docat_del($file) eq <<'EOM') ;
930 my $redirect = new Redirect $file ;
935 use warnings FATAL => qw(all) ;
939 use vars qw($filename %h ) ;
944 # Enable duplicate records
945 $DB_BTREE->{'flags'} = R_DUP ;
947 tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
948 or die "Cannot open $filename: $!\n";
950 # Add some key/value pairs to the file
951 $h{'Wall'} = 'Larry' ;
952 $h{'Wall'} = 'Brick' ; # Note the duplicate key
953 $h{'Wall'} = 'Brick' ; # Note the duplicate key and value
954 $h{'Smith'} = 'John' ;
955 $h{'mouse'} = 'mickey' ;
957 # iterate through the associative array
958 # and print each key/value pair.
960 { print "$_ -> $h{$_}\n" }
967 ok(150, docat_del($file) eq ($db185mode ? <<'EOM' : <<'EOM') ) ;
982 my $redirect = new Redirect $file ;
987 use warnings FATAL => qw(all) ;
991 use vars qw($filename $x %h $status $key $value) ;
996 # Enable duplicate records
997 $DB_BTREE->{'flags'} = R_DUP ;
999 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1000 or die "Cannot open $filename: $!\n";
1002 # Add some key/value pairs to the file
1003 $h{'Wall'} = 'Larry' ;
1004 $h{'Wall'} = 'Brick' ; # Note the duplicate key
1005 $h{'Wall'} = 'Brick' ; # Note the duplicate key and value
1006 $h{'Smith'} = 'John' ;
1007 $h{'mouse'} = 'mickey' ;
1009 # iterate through the btree using seq
1010 # and print each key/value pair.
1012 for ($status = $x->seq($key, $value, R_FIRST) ;
1014 $status = $x->seq($key, $value, R_NEXT) )
1015 { print "$key -> $value\n" }
1022 ok(151, docat_del($file) eq ($db185mode == 1 ? <<'EOM' : <<'EOM') ) ;
1038 my $redirect = new Redirect $file ;
1043 use warnings FATAL => qw(all) ;
1047 use vars qw($filename $x %h ) ;
1049 $filename = "tree" ;
1051 # Enable duplicate records
1052 $DB_BTREE->{'flags'} = R_DUP ;
1054 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1055 or die "Cannot open $filename: $!\n";
1057 my $cnt = $x->get_dup("Wall") ;
1058 print "Wall occurred $cnt times\n" ;
1060 my %hash = $x->get_dup("Wall", 1) ;
1061 print "Larry is there\n" if $hash{'Larry'} ;
1062 print "There are $hash{'Brick'} Brick Walls\n" ;
1064 my @list = sort $x->get_dup("Wall") ;
1065 print "Wall => [@list]\n" ;
1067 @list = $x->get_dup("Smith") ;
1068 print "Smith => [@list]\n" ;
1070 @list = $x->get_dup("Dog") ;
1071 print "Dog => [@list]\n" ;
1077 ok(152, docat_del($file) eq <<'EOM') ;
1078 Wall occurred 3 times
1080 There are 2 Brick Walls
1081 Wall => [Brick Brick Larry]
1087 my $redirect = new Redirect $file ;
1092 use warnings FATAL => qw(all) ;
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 $found = ( $x->find_dup("Wall", "Larry") == 0 ? "" : "not") ;
1107 print "Larry Wall is $found there\n" ;
1109 $found = ( $x->find_dup("Wall", "Harry") == 0 ? "" : "not") ;
1110 print "Harry Wall is $found there\n" ;
1116 ok(153, docat_del($file) eq <<'EOM') ;
1118 Harry Wall is not there
1122 my $redirect = new Redirect $file ;
1127 use warnings FATAL => qw(all) ;
1131 use vars qw($filename $x %h $found) ;
1133 my $filename = "tree" ;
1135 # Enable duplicate records
1136 $DB_BTREE->{'flags'} = R_DUP ;
1138 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1139 or die "Cannot open $filename: $!\n";
1141 $x->del_dup("Wall", "Larry") ;
1143 $found = ( $x->find_dup("Wall", "Larry") == 0 ? "" : "not") ;
1144 print "Larry Wall is $found there\n" ;
1152 ok(154, docat_del($file) eq <<'EOM') ;
1153 Larry Wall is not there
1157 my $redirect = new Redirect $file ;
1162 use warnings FATAL => qw(all) ;
1167 use vars qw($filename $x %h $st $key $value) ;
1173 my $orig_key = $key ;
1174 $x->seq($key, $value, R_CURSOR) ;
1175 print "$orig_key\t-> $key\t-> $value\n" ;
1178 $filename = "tree" ;
1181 $x = tie %h, "DB_File", $filename, O_RDWR|O_CREAT, 0640, $DB_BTREE
1182 or die "Cannot open $filename: $!\n";
1184 # Add some key/value pairs to the file
1185 $h{'mouse'} = 'mickey' ;
1186 $h{'Wall'} = 'Larry' ;
1187 $h{'Walls'} = 'Brick' ;
1188 $h{'Smith'} = 'John' ;
1192 print "IN ORDER\n" ;
1193 for ($st = $x->seq($key, $value, R_FIRST) ;
1195 $st = $x->seq($key, $value, R_NEXT) )
1197 { print "$key -> $value\n" }
1199 print "\nPARTIAL MATCH\n" ;
1212 ok(155, docat_del($file) eq <<'EOM') ;
1222 a -> mouse -> mickey
1233 # ok(156, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) );
1236 # my $k = "newest" ;
1238 # my $status = $db->put($k, $v, R_SETCURSOR) ;
1239 # print "status = [$status]\n" ;
1240 # ok(157, $status == 0) ;
1241 # $status = $db->del($k, R_CURSOR) ;
1242 # print "status = [$status]\n" ;
1243 # ok(158, $status == 0) ;
1245 # ok(159, $db->get($k, $v, R_CURSOR)) ;
1247 # ok(160, keys %h == 1) ;
1255 # Bug ID 20001013.009
1257 # test that $hash{KEY} = undef doesn't produce the warning
1258 # Use of uninitialized value in null operation
1266 local $SIG{__WARN__} = sub {$a = $_[0]} ;
1268 tie %h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0664, $DB_BTREE
1269 or die "Can't open file: $!\n" ;
1277 # test that %hash = () doesn't produce the warning
1278 # Argument "" isn't numeric in entersub
1286 local $SIG{__WARN__} = sub {$a = $_[0]} ;
1288 tie %h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0664, $DB_BTREE
1289 or die "Can't open file: $!\n" ;