/[wait]/trunk/lib/WAIT/Index.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/WAIT/Index.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 82 by ulpfr, Mon Apr 22 10:09:34 2002 UTC revision 85 by ulpfr, Fri May 3 16:16:10 2002 UTC
# Line 4  Line 4 
4  # Author          : Ulrich Pfeifer  # Author          : Ulrich Pfeifer
5  # Created On      : Thu Aug  8 13:05:10 1996  # Created On      : Thu Aug  8 13:05:10 1996
6  # Last Modified By: Ulrich Pfeifer  # Last Modified By: Ulrich Pfeifer
7  # Last Modified On: Sun Nov 22 18:44:43 1998  # Last Modified On: Sat Apr 27 18:06:47 2002
8  # Language        : CPerl  # Language        : CPerl
9  # Update Count    : 107  # Update Count    : 128
10  # Status          : Unknown, Use with caution!  # Status          : Unknown, Use with caution!
11  #  #
12  # Copyright (c) 1996-1997, Ulrich Pfeifer  # Copyright (c) 1996-1997, Ulrich Pfeifer
# Line 15  Line 15 
15  package WAIT::Index;  package WAIT::Index;
16  use WAIT::IndexScan;  use WAIT::IndexScan;
17  use strict;  use strict;
18  use DB_File;  use BerkeleyDB;
19  use Fcntl;  use Fcntl;
20  use vars qw($VERSION);  use vars qw($VERSION);
21    
# Line 30  sub new { Line 30  sub new {
30      require Carp;      require Carp;
31      Carp::croak("No file specified");      Carp::croak("No file specified");
32    }    }
33      unless ($self->{name} = $parm{name}) {
34        require Carp;
35        Carp::croak("No name specified");
36      }
37    unless ($self->{attr} = $parm{attr}) {    unless ($self->{attr} = $parm{attr}) {
38      require Carp;      require Carp;
39      Carp::croak("No attributes specified");      Carp::croak("No attributes specified");
# Line 52  sub open { Line 56  sub open {
56    my $self = shift;    my $self = shift;
57    my $file = $self->{file};    my $file = $self->{file};
58    
59    if (exists $self->{dbh}) {    if ($self->{dbh}) {
60      $self->{dbh};      $self->{dbh};
61    } else {    } else {
62      $self->{dbh} = tie(%{$self->{db}}, 'DB_File', $file,      my $dbmode = ($self->{mode} & O_CREAT) ? DB_CREATE : 0;
63                         $self->{mode}, 0664, $DB_BTREE);      $self->{dbh} = tie(%{$self->{db}}, 'BerkeleyDB::Btree',
64                           -Filename => $self->{file},
65                           -Subname  => 'records',
66                           -Flags    => $dbmode,
67                           -Mode     => 0664);
68    }    }
69  }  }
70    
# Line 73  sub insert { Line 81  sub insert {
81      # duplicate entry      # duplicate entry
82      return undef;      return undef;
83    }    }
84      print STDERR "$tuple => $key\n";
85    $self->{db}->{$tuple} = $key;    $self->{db}->{$tuple} = $key;
86  }  }
87    
# Line 84  sub have { Line 93  sub have {
93    
94    my $tuple = join($;, map($parm{$_}, @{$self->{attr}}));    my $tuple = join($;, map($parm{$_}, @{$self->{attr}}));
95    
96      print STDERR "$tuple <= ", $self->{db}->{$tuple}, "\n";
97    $self->{db}->{$tuple};    $self->{db}->{$tuple};
98  }  }
99    
# Line 112  sub delete { Line 122  sub delete {
122    
123  sub sync {  sub sync {
124    my $self = shift;    my $self = shift;
125    $self->{dbh}->sync if $self->{dbh};    $self->{dbh}->db_sync if $self->{dbh};
126  }  }
127    
128  sub close {  sub close {
# Line 122  sub close { Line 132  sub close {
132    
133    if ($self->{dbh}) {    if ($self->{dbh}) {
134      delete $self->{dbh};      delete $self->{dbh};
     untie %{$self->{db}};  
135      delete $self->{db};      delete $self->{db};
136        #untie %{$self->{db}};
137    }    }
138  }  }
139    

Legend:
Removed from v.82  
changed lines
  Added in v.85

  ViewVC Help
Powered by ViewVC 1.1.26