--- cvs-head/lib/WAIT/Index.pm 2002/04/22 10:09:34 82 +++ cvs-head/lib/WAIT/Index.pm 2002/05/03 16:16:10 85 @@ -4,9 +4,9 @@ # Author : Ulrich Pfeifer # Created On : Thu Aug 8 13:05:10 1996 # Last Modified By: Ulrich Pfeifer -# Last Modified On: Sun Nov 22 18:44:43 1998 +# Last Modified On: Sat Apr 27 18:06:47 2002 # Language : CPerl -# Update Count : 107 +# Update Count : 128 # Status : Unknown, Use with caution! # # Copyright (c) 1996-1997, Ulrich Pfeifer @@ -15,7 +15,7 @@ package WAIT::Index; use WAIT::IndexScan; use strict; -use DB_File; +use BerkeleyDB; use Fcntl; use vars qw($VERSION); @@ -30,6 +30,10 @@ require Carp; Carp::croak("No file specified"); } + unless ($self->{name} = $parm{name}) { + require Carp; + Carp::croak("No name specified"); + } unless ($self->{attr} = $parm{attr}) { require Carp; Carp::croak("No attributes specified"); @@ -52,11 +56,15 @@ my $self = shift; my $file = $self->{file}; - if (exists $self->{dbh}) { + if ($self->{dbh}) { $self->{dbh}; } else { - $self->{dbh} = tie(%{$self->{db}}, 'DB_File', $file, - $self->{mode}, 0664, $DB_BTREE); + my $dbmode = ($self->{mode} & O_CREAT) ? DB_CREATE : 0; + $self->{dbh} = tie(%{$self->{db}}, 'BerkeleyDB::Btree', + -Filename => $self->{file}, + -Subname => 'records', + -Flags => $dbmode, + -Mode => 0664); } } @@ -73,6 +81,7 @@ # duplicate entry return undef; } + print STDERR "$tuple => $key\n"; $self->{db}->{$tuple} = $key; } @@ -84,6 +93,7 @@ my $tuple = join($;, map($parm{$_}, @{$self->{attr}})); + print STDERR "$tuple <= ", $self->{db}->{$tuple}, "\n"; $self->{db}->{$tuple}; } @@ -112,7 +122,7 @@ sub sync { my $self = shift; - $self->{dbh}->sync if $self->{dbh}; + $self->{dbh}->db_sync if $self->{dbh}; } sub close { @@ -122,8 +132,8 @@ if ($self->{dbh}) { delete $self->{dbh}; - untie %{$self->{db}}; delete $self->{db}; + #untie %{$self->{db}}; } }