18 |
use DB_File; |
use DB_File; |
19 |
use Fcntl; |
use Fcntl; |
20 |
|
|
|
sub fail { |
|
|
$@ .= join "\n", @_; |
|
|
return undef; |
|
|
} |
|
|
|
|
21 |
sub new { |
sub new { |
22 |
my $type = shift; |
my $type = shift; |
23 |
my $index = shift; |
my $index = shift; |
25 |
my ($first, $tid) = ('', ''); |
my ($first, $tid) = ('', ''); |
26 |
|
|
27 |
# find the first key |
# find the first key |
28 |
$index->{dbh}->seq($first, $tid, R_FIRST) |
if ($index->{dbh}->seq($first, $tid, R_FIRST)) { |
29 |
and return fail("Could not open scan"); |
require Carp; |
30 |
|
Carp::croak("Could not open scan"); |
31 |
|
} |
32 |
# Not sure about this. R_FIRST sets $tid to no-of-records? |
# Not sure about this. R_FIRST sets $tid to no-of-records? |
33 |
# $index->{dbh}->seq($first, $tid, R_NEXT); |
# $index->{dbh}->seq($first, $tid, R_NEXT); |
34 |
# register to avoid unnecessary position calls |
# register to avoid unnecessary position calls |
44 |
my ($key, $tid, $ntid); |
my ($key, $tid, $ntid); |
45 |
|
|
46 |
if (defined $self->{nextk}) { |
if (defined $self->{nextk}) { |
47 |
fail("Cannot scan closed index"),return unless $dbh; |
unless ($dbh){ |
48 |
|
require Carp; |
49 |
|
Carp::croak("Cannot scan closed index"); |
50 |
|
} |
51 |
$key = $self->{nextk}; |
$key = $self->{nextk}; |
52 |
|
|
53 |
if ($self->{Index}->{scans} > 1) { |
if ($self->{Index}->{scans} > 1) { |
54 |
# Another scan is open. Reset the cursor |
# Another scan is open. Reset the cursor |
55 |
$dbh->seq($key, $tid, R_CURSOR); |
$dbh->seq($key, $tid, R_CURSOR); |
60 |
# current tuple is last one |
# current tuple is last one |
61 |
delete $self->{nextk}; |
delete $self->{nextk}; |
62 |
} |
} |
63 |
|
|
64 |
my @tuple = split /$;/, $key; |
my @tuple = split /$;/, $key; |
65 |
my %tuple = (_id => $tid); |
my %tuple = (_id => $tid); |
66 |
for (@{$self->{Index}->{attr}}) { |
for (@{$self->{Index}->{attr}}) { |