/[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 88 by dpavlin, Mon May 24 13:44:01 2004 UTC revision 89 by dpavlin, Mon May 24 20:57:08 2004 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: Sat Apr 27 18:06:47 2002  # Last Modified On: Sun Nov 22 18:44:43 1998
8  # Language        : CPerl  # Language        : CPerl
9  # Update Count    : 128  # Update Count    : 107
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 BerkeleyDB;  use DB_File;
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    }    }
   unless ($self->{name} = $parm{name}) {  
     require Carp;  
     Carp::croak("No name specified");  
   }  
33    unless ($self->{attr} = $parm{attr}) {    unless ($self->{attr} = $parm{attr}) {
34      require Carp;      require Carp;
35      Carp::croak("No attributes specified");      Carp::croak("No attributes specified");
# Line 56  sub open { Line 52  sub open {
52    my $self = shift;    my $self = shift;
53    my $file = $self->{file};    my $file = $self->{file};
54    
55    if ($self->{dbh}) {    if (exists $self->{dbh}) {
56      $self->{dbh};      $self->{dbh};
57    } else {    } else {
58      my $dbmode = ($self->{mode} & O_CREAT) ? DB_CREATE : 0;      $self->{dbh} = tie(%{$self->{db}}, 'DB_File', $file,
59      $self->{dbh} = tie(%{$self->{db}}, 'BerkeleyDB::Btree',                         $self->{mode}, 0664, $DB_BTREE);
                        -Filename => $self->{file},  
                        -Subname  => 'records',  
                        -Flags    => $dbmode,  
                        -Mode     => 0664);  
60    }    }
61  }  }
62    
# Line 81  sub insert { Line 73  sub insert {
73      # duplicate entry      # duplicate entry
74      return undef;      return undef;
75    }    }
   print STDERR "$tuple => $key\n";  
76    $self->{db}->{$tuple} = $key;    $self->{db}->{$tuple} = $key;
77  }  }
78    
# Line 93  sub have { Line 84  sub have {
84    
85    my $tuple = join($;, map($parm{$_}, @{$self->{attr}}));    my $tuple = join($;, map($parm{$_}, @{$self->{attr}}));
86    
   print STDERR "$tuple <= ", $self->{db}->{$tuple}, "\n";  
87    $self->{db}->{$tuple};    $self->{db}->{$tuple};
88  }  }
89    
# Line 122  sub delete { Line 112  sub delete {
112    
113  sub sync {  sub sync {
114    my $self = shift;    my $self = shift;
115    $self->{dbh}->db_sync if $self->{dbh};    $self->{dbh}->sync if $self->{dbh};
116  }  }
117    
118  sub close {  sub close {
# Line 132  sub close { Line 122  sub close {
122    
123    if ($self->{dbh}) {    if ($self->{dbh}) {
124      delete $self->{dbh};      delete $self->{dbh};
125        untie %{$self->{db}};
126      delete $self->{db};      delete $self->{db};
     #untie %{$self->{db}};  
127    }    }
128  }  }
129    

Legend:
Removed from v.88  
changed lines
  Added in v.89

  ViewVC Help
Powered by ViewVC 1.1.26