6 unless(grep /blib/, @INC) {
8 @INC = '../lib' if -d '../lib';
19 my $Dfile = "dbhash.tmp";
20 my $Dfile2 = "dbhash2.tmp";
21 my $Dfile3 = "dbhash3.tmp";
26 my $redirect = "xyzt" ;
30 my $x = $BerkeleyDB::Error;
31 my $redirect = "xyzt" ;
33 my $redirectObj = new Redirect $redirect ;
37 use vars qw( %h $k $v ) ;
39 my $filename = "fruit" ;
41 tie %h, "BerkeleyDB::Hash",
42 -Filename => $filename,
44 or die "Cannot open file $filename: $! $BerkeleyDB::Error\n" ;
46 # Add a few key/value pairs to the file
48 $h{"orange"} = "orange" ;
49 $h{"banana"} = "yellow" ;
50 $h{"tomato"} = "red" ;
52 # Check for existence of a key
53 print "Banana Exists\n\n" if $h{"banana"} ;
55 # Delete a key/value pair.
58 # print the contents of the file
59 while (($k, $v) = each %h)
60 { print "$k -> $v\n" }
66 #print "[" . docat($redirect) . "]" ;
67 is(docat_del($redirect), <<'EOM') ;
79 my $redirect = "xyzt" ;
82 my $redirectObj = new Redirect $redirect ;
87 my $filename = "fruit" ;
89 my $db = new BerkeleyDB::Hash
90 -Filename => $filename,
92 or die "Cannot open file $filename: $! $BerkeleyDB::Error\n" ;
94 # Add a few key/value pairs to the file
95 $db->db_put("apple", "red") ;
96 $db->db_put("orange", "orange") ;
97 $db->db_put("banana", "yellow") ;
98 $db->db_put("tomato", "red") ;
100 # Check for existence of a key
101 print "Banana Exists\n\n" if $db->db_get("banana", $v) == 0;
103 # Delete a key/value pair.
104 $db->db_del("apple") ;
106 # print the contents of the file
107 my ($k, $v) = ("", "") ;
108 my $cursor = $db->db_cursor() ;
109 while ($cursor->c_get($k, $v, DB_NEXT) == 0)
110 { print "$k -> $v\n" }
117 #print "[" . docat($redirect) . "]" ;
118 is(docat_del($redirect), <<'EOM') ;
129 my $redirect = "xyzt" ;
132 my $redirectObj = new Redirect $redirect ;
137 my $filename = "tree" ;
140 tie %h, 'BerkeleyDB::Btree',
141 -Filename => $filename,
143 or die "Cannot open $filename: $! $BerkeleyDB::Error\n" ;
145 # Add a key/value pair to the file
146 $h{'Wall'} = 'Larry' ;
147 $h{'Smith'} = 'John' ;
148 $h{'mouse'} = 'mickey' ;
149 $h{'duck'} = 'donald' ;
154 # Cycle through the keys printing them in order.
155 # Note it is not necessary to sort the keys as
156 # the btree will have kept them in order automatically.
164 #print "[" . docat($redirect) . "]\n" ;
165 is(docat_del($redirect), <<'EOM') ;
174 my $redirect = "xyzt" ;
177 my $redirectObj = new Redirect $redirect ;
182 my $filename = "tree" ;
185 tie %h, 'BerkeleyDB::Btree',
186 -Filename => $filename,
188 -Compare => sub { lc $_[0] cmp lc $_[1] }
189 or die "Cannot open $filename: $!\n" ;
191 # Add a key/value pair to the file
192 $h{'Wall'} = 'Larry' ;
193 $h{'Smith'} = 'John' ;
194 $h{'mouse'} = 'mickey' ;
195 $h{'duck'} = 'donald' ;
200 # Cycle through the keys printing them in order.
201 # Note it is not necessary to sort the keys as
202 # the btree will have kept them in order automatically.
210 #print "[" . docat($redirect) . "]\n" ;
211 is(docat_del($redirect), <<'EOM') ;
220 my $redirect = "xyzt" ;
223 my $redirectObj = new Redirect $redirect ;
229 my $filename = "filt.db" ;
232 my $db = tie %hash, 'BerkeleyDB::Hash',
233 -Filename => $filename,
235 or die "Cannot open $filename: $!\n" ;
237 # Install DBM Filters
238 $db->filter_fetch_key ( sub { s/\0$// } ) ;
239 $db->filter_store_key ( sub { $_ .= "\0" } ) ;
240 $db->filter_fetch_value( sub { s/\0$// } ) ;
241 $db->filter_store_value( sub { $_ .= "\0" } ) ;
243 $hash{"abc"} = "def" ;
244 my $a = $hash{"ABC"} ;
248 $db = tie %hash, 'BerkeleyDB::Hash',
249 -Filename => $filename,
251 or die "Cannot open $filename: $!\n" ;
252 while (($k, $v) = each %hash)
253 { print "$k -> $v\n" }
260 #print "[" . docat($redirect) . "]\n" ;
261 is(docat_del($redirect), <<"EOM") ;
268 my $redirect = "xyzt" ;
271 my $redirectObj = new Redirect $redirect ;
276 my $filename = "filt.db" ;
280 my $db = tie %hash, 'BerkeleyDB::Btree',
281 -Filename => $filename,
283 or die "Cannot open $filename: $!\n" ;
285 $db->filter_fetch_key ( sub { $_ = unpack("i", $_) } ) ;
286 $db->filter_store_key ( sub { $_ = pack ("i", $_) } ) ;
291 $db = tie %hash, 'BerkeleyDB::Btree',
292 -Filename => $filename,
294 or die "Cannot Open $filename: $!\n" ;
295 while (($k, $v) = each %hash)
296 { print "$k -> $v\n" }
303 my $val = pack("i", 123) ;
304 #print "[" . docat($redirect) . "]\n" ;
305 is(docat_del($redirect), <<"EOM") ;
312 my $redirect = "xyzt" ;
315 my $redirectObj = new Redirect $redirect ;
321 my $filename = "text" ;
325 tie @h, 'BerkeleyDB::Recno',
326 -Filename => $filename,
328 -Property => DB_RENUMBER
329 or die "Cannot open $filename: $!\n" ;
331 # Add a few key/value pairs to the file
336 push @h, "green", "black" ;
338 my $elements = scalar @h ;
339 print "The array contains $elements entries\n" ;
342 print "popped $last\n" ;
344 unshift @h, "white" ;
345 my $first = shift @h ;
346 print "shifted $first\n" ;
348 # Check for existence of a key
349 print "Element 1 Exists with value $h[1]\n" if $h[1] ;
357 my $filename = "text" ;
361 my $db = tie @h, 'BerkeleyDB::Recno',
362 -Filename => $filename,
364 -Property => DB_RENUMBER
365 or die "Cannot open $filename: $!\n" ;
367 # Add a few key/value pairs to the file
372 $db->push("green", "black") ;
374 my $elements = $db->length() ;
375 print "The array contains $elements entries\n" ;
377 my $last = $db->pop ;
378 print "popped $last\n" ;
380 $db->unshift("white") ;
381 my $first = $db->shift ;
382 print "shifted $first\n" ;
384 # Check for existence of a key
385 print "Element 1 Exists with value $h[1]\n" if $h[1] ;
394 #print "[" . docat($redirect) . "]\n" ;
395 is(docat_del($redirect), <<"EOM") ;
396 The array contains 5 entries
399 Element 1 Exists with value blue