This file is indexed.

/usr/share/perl5/DBIx/Recordset/DBSeq.pm is in libdbix-recordset-perl 0.26-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
###################################################################################
#
#   DBIx::Recordset - Copyright (c) 1997-2000 Gerald Richter / ECOS
#
#   You may distribute under the terms of either the GNU General Public
#   License or the Artistic License, as specified in the Perl README file.
#
#   THIS IS BETA SOFTWARE!
#
#   THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
#   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
#   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
#   $Id: DBSeq.pm,v 1.5 2000/06/26 05:16:18 richter Exp $
#
###################################################################################


package DBIx::Recordset::DBSeq ;

use strict 'vars' ;



## ----------------------------------------------------------------------------
##
## new
##
## creates a new DBIx::Recordset::DBSeq object. 
##
## $dbh          = Database handle
## $table        = table where to keep sequences
##

sub new

    {
    my ($class, $dbh, $table, $min, $max) = @_ ;
    


    my $self = {
                '*Debug'      => $DBIx::Recordset::Debug,
                '*dbh'        => $dbh,
                '*table'      => $table,
                '*DefaultMin' => $min || 1,
                '*DefaultMax' => $max || 'NULL',
               } ;

    bless ($self, $class) ;

    return $self ;
    }



## ----------------------------------------------------------------------------
##
## NextVal
##
## get next value from counter
##
## in   $name = counter name
##


sub NextVal 

    {
    my ($self, $name) = @_ ;

    my $dbh = $self -> {'*dbh'} ;
    
    $dbh -> do ("lock table $self->{'*table'} write") or die "Cannot lock $self->{'*table'} ($DBI::errstr)" ;



    my $sth = $dbh -> prepare ("select cnt,maxcnt from $self->{'*table'} where name=?") or die "Cannot prepare select for $self->{'*table'} ($DBI::errstr)" ;

    $sth -> execute ($name) ;

    my $row = $sth -> fetchrow_arrayref ;
    my $cnt ;
    my $max ;
    
    if (!$row)
        {
        $cnt = $self->{'*DefaultMin'} ;
        $max = $self->{'*DefaultMax'} ;
        my $cnt1 = $cnt + 1 ;
        $dbh -> do ("insert into $self->{'*table'} (name,cnt,maxcnt) values ('$name',$cnt1,$max)") or die "Cannot insert $self->{'*table'} ($DBI::errstr)" ;
        }
    else
        {
        $cnt = $row -> [0] ;
        die "Max count reached for sequence $name" if (defined ($row->[1]) && $cnt+1 > $row->[1]) ;
        $dbh -> do ("update $self->{'*table'} set cnt=cnt+1 where name='$name'") or die "Cannot update $self->{'*table'} ($DBI::errstr)" ;
        }

    $dbh -> do ("unlock table") or die "Cannot unlock $self->{'*table'} ($DBI::errstr)" ;
    
    return $cnt ;
    }

1;

__END__


=pod

=head1 NAME

DBIx::Recordset::DBSeq - Sequence generator in DBI database

=head1 SYNOPSIS

 use DBIx::Recordset::DBSeq ;

 $self = DBIx::Recordset::DBSeq ($dbh, 'sequences', $min, $max) ;
 
 $val1 = $self -> NextVal ('foo') ;
 $val2 = $self -> NextVal ('foo') ;
 $val3 = $self -> NextVal ('bar') ;
 

=head1 DESCRIPTION

DBIx::Recordset::FileSeq generates unique numbers. State is kept in the
one table of a database accessible via DBI. With the new constructor you
give an open database handle and specify the the table where state should be kept.
Optionaly you can give a min and
a max values, which will be used for new sequences.

With B<NextVal> you can get the next value
for the sequence of the given name.

The table must created in the following form:

create table
    (
    name    varchar (32),
    cnt     integer,
    maxcnt  integer,
    primary key name
    ) ;


If the sequence value reaches the maxcnt value, NextVal will die with an
error message. If maxcnt contains C<null> there is no limit.



=head1 AUTHOR

G.Richter (richter@dev.ecos.de)

=head1 SEE ALSO

=over

=item DBIx::Recordset

=back

=cut