line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BTRIEVE::FileIO; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = '0.05'; |
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
136273
|
use BTRIEVE::Native(); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub StepFirst { $_[0]->_Step( 33 ) } |
8
|
|
|
|
|
|
|
sub StepLast { $_[0]->_Step( 34 ) } |
9
|
|
|
|
|
|
|
sub StepNext { $_[0]->_Step( 24 ) } |
10
|
|
|
|
|
|
|
sub StepPrevious { $_[0]->_Step( 35 ) } |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub GetFirst { $_[0]->_Get ( 12 ) } |
13
|
|
|
|
|
|
|
sub GetLast { $_[0]->_Get ( 13 ) } |
14
|
|
|
|
|
|
|
sub GetEqual { $_[0]->_Get ( 5 ) } |
15
|
|
|
|
|
|
|
sub GetGreater { $_[0]->_Get ( 8 ) } |
16
|
|
|
|
|
|
|
sub GetNext { $_[0]->_Get ( 6 ) } |
17
|
|
|
|
|
|
|
sub GetPrevious { $_[0]->_Get ( 7 ) } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub IsOk { $_[0]->{Status} ? 0 : 1 } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
22
|
|
|
|
|
|
|
sub Create |
23
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
{ |
25
|
|
|
|
|
|
|
my $class = shift; |
26
|
|
|
|
|
|
|
my $File = shift; |
27
|
|
|
|
|
|
|
my $FSpec = shift || {}; |
28
|
|
|
|
|
|
|
my $KSpec = shift || []; |
29
|
|
|
|
|
|
|
my $self = {}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $DefFSpec = |
32
|
|
|
|
|
|
|
{ |
33
|
|
|
|
|
|
|
LogicalRecordLength => 128 |
34
|
|
|
|
|
|
|
, PageSize => 512 |
35
|
|
|
|
|
|
|
, NumberOfIndexes => scalar @$KSpec |
36
|
|
|
|
|
|
|
, FileFlags => 0 |
37
|
|
|
|
|
|
|
, NumberOfDuplicatePointersToReserve => 0 |
38
|
|
|
|
|
|
|
, Allocation => 0 |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
%$FSpec = ( %$DefFSpec, %$FSpec ); |
41
|
|
|
|
|
|
|
my @FSpec = @$FSpec |
42
|
|
|
|
|
|
|
{ |
43
|
|
|
|
|
|
|
'LogicalRecordLength' |
44
|
|
|
|
|
|
|
,'PageSize' |
45
|
|
|
|
|
|
|
,'NumberOfIndexes' |
46
|
|
|
|
|
|
|
,'FileFlags' |
47
|
|
|
|
|
|
|
,'NumberOfDuplicatePointersToReserve' |
48
|
|
|
|
|
|
|
,'Allocation' |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
my $DefKSpec = |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
KeyPosition => 1 |
53
|
|
|
|
|
|
|
, KeyLength => 1 |
54
|
|
|
|
|
|
|
, KeyFlags => 0 |
55
|
|
|
|
|
|
|
, ExtendedDataType => 0 |
56
|
|
|
|
|
|
|
, NullValue => 0 |
57
|
|
|
|
|
|
|
, ManuallyAssignedKeyNumber => 0 |
58
|
|
|
|
|
|
|
, ACSNumber => 0 |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
$self->{Pos} = "\0" x 128; |
61
|
|
|
|
|
|
|
$self->{Size} = 16 + @$KSpec * 16; |
62
|
|
|
|
|
|
|
$self->{Data} = pack 'SSSx4SCxS', @FSpec; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
for ( @$KSpec ) |
65
|
|
|
|
|
|
|
{ |
66
|
|
|
|
|
|
|
my %KSpec = ( %$DefKSpec, %$_ ); |
67
|
|
|
|
|
|
|
my @KSpec = @KSpec |
68
|
|
|
|
|
|
|
{ |
69
|
|
|
|
|
|
|
'KeyPosition' |
70
|
|
|
|
|
|
|
,'KeyLength' |
71
|
|
|
|
|
|
|
,'KeyFlags' |
72
|
|
|
|
|
|
|
,'ExtendedDataType' |
73
|
|
|
|
|
|
|
,'NullValue' |
74
|
|
|
|
|
|
|
,'ManuallyAssignedKeyNumber' |
75
|
|
|
|
|
|
|
,'ACSNumber' |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
$self->{Data} .= pack 'SSSx4CCx2CC', @KSpec; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
$self->{Key} = $File; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$self->{Status} = BTRIEVE::Native::Call |
82
|
|
|
|
|
|
|
( |
83
|
|
|
|
|
|
|
14 |
84
|
|
|
|
|
|
|
, $self->{Pos} |
85
|
|
|
|
|
|
|
, $self->{Data} |
86
|
|
|
|
|
|
|
, $self->{Size} |
87
|
|
|
|
|
|
|
, $self->{Key} |
88
|
|
|
|
|
|
|
, 0 |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
return bless $self, $class if $self->{Status}; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$class->Open( $File ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
95
|
|
|
|
|
|
|
sub Open |
96
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
97
|
|
|
|
|
|
|
{ |
98
|
|
|
|
|
|
|
my $class = shift; |
99
|
|
|
|
|
|
|
my $File = shift; |
100
|
|
|
|
|
|
|
my $self = {}; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$self->{Pos} = "\0" x 128; |
103
|
|
|
|
|
|
|
$self->{Size} = 255; |
104
|
|
|
|
|
|
|
$self->{Data} = "\0" x $self->{Size}; |
105
|
|
|
|
|
|
|
$self->{Key } = "\0" x 255; |
106
|
|
|
|
|
|
|
$self->{KeyNum} = 0; |
107
|
|
|
|
|
|
|
$self->{Status} = 0; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$self->{Status} = BTRIEVE::Native::Call |
110
|
|
|
|
|
|
|
( |
111
|
|
|
|
|
|
|
0 |
112
|
|
|
|
|
|
|
, $self->{Pos} |
113
|
|
|
|
|
|
|
, $self->{Data} |
114
|
|
|
|
|
|
|
, $self->{Size} |
115
|
|
|
|
|
|
|
, $File |
116
|
|
|
|
|
|
|
, 0 |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
bless $self, $class; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
121
|
|
|
|
|
|
|
sub Close |
122
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
123
|
|
|
|
|
|
|
{ |
124
|
|
|
|
|
|
|
my $self = shift; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
$self->{Status} = BTRIEVE::Native::Call |
127
|
|
|
|
|
|
|
( |
128
|
|
|
|
|
|
|
1 |
129
|
|
|
|
|
|
|
, $self->{Pos} |
130
|
|
|
|
|
|
|
, $self->{Data} |
131
|
|
|
|
|
|
|
, $self->{Size} |
132
|
|
|
|
|
|
|
, $self->{Key} |
133
|
|
|
|
|
|
|
, 0 |
134
|
|
|
|
|
|
|
); |
135
|
|
|
|
|
|
|
$self->IsOk; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
138
|
|
|
|
|
|
|
sub Insert |
139
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
140
|
|
|
|
|
|
|
{ |
141
|
|
|
|
|
|
|
my $self = shift; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
$self->{Data} = shift if @_; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
$self->{Status} = BTRIEVE::Native::Call |
146
|
|
|
|
|
|
|
( |
147
|
|
|
|
|
|
|
2 |
148
|
|
|
|
|
|
|
, $self->{Pos} |
149
|
|
|
|
|
|
|
, $self->{Data} |
150
|
|
|
|
|
|
|
, $self->{Size} |
151
|
|
|
|
|
|
|
, $self->{Key} |
152
|
|
|
|
|
|
|
, -1 |
153
|
|
|
|
|
|
|
); |
154
|
|
|
|
|
|
|
$self->IsOk; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
157
|
|
|
|
|
|
|
sub _Step |
158
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
159
|
|
|
|
|
|
|
{ |
160
|
|
|
|
|
|
|
my $self = shift; |
161
|
|
|
|
|
|
|
my $Op = shift; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
$self->{Data} = "\0" x $self->{Size}; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
$self->{Status} = BTRIEVE::Native::Call |
166
|
|
|
|
|
|
|
( |
167
|
|
|
|
|
|
|
$Op |
168
|
|
|
|
|
|
|
, $self->{Pos} |
169
|
|
|
|
|
|
|
, $self->{Data} |
170
|
|
|
|
|
|
|
, $self->{Size} |
171
|
|
|
|
|
|
|
, $self->{Key} |
172
|
|
|
|
|
|
|
, 0 |
173
|
|
|
|
|
|
|
); |
174
|
|
|
|
|
|
|
$self->IsOk; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
177
|
|
|
|
|
|
|
sub _Get |
178
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
179
|
|
|
|
|
|
|
{ |
180
|
|
|
|
|
|
|
my $self = shift; |
181
|
|
|
|
|
|
|
my $Op = shift; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
$self->{Data} = "\0" x $self->{Size}; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
$self->{Status} = BTRIEVE::Native::Call |
186
|
|
|
|
|
|
|
( |
187
|
|
|
|
|
|
|
$Op |
188
|
|
|
|
|
|
|
, $self->{Pos} |
189
|
|
|
|
|
|
|
, $self->{Data} |
190
|
|
|
|
|
|
|
, $self->{Size} |
191
|
|
|
|
|
|
|
, $self->{Key} |
192
|
|
|
|
|
|
|
, $self->{KeyNum} |
193
|
|
|
|
|
|
|
); |
194
|
|
|
|
|
|
|
$self->IsOk; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
197
|
|
|
|
|
|
|
sub DESTROY |
198
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
199
|
|
|
|
|
|
|
{ |
200
|
|
|
|
|
|
|
my $self = shift; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
$self->Close; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
205
|
|
|
|
|
|
|
1; |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 NAME |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
BTRIEVE::FileIO - Btrieve file I/O operations |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 SYNOPSIS |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
use BTRIEVE::FileIO(); |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
my $B = BTRIEVE::FileIO->Open('TEST.BTR'); |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
$B->{Size} = 13; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
for ( $B->StepFirst; $B->IsOk; $B->StepNext ) |
220
|
|
|
|
|
|
|
{ |
221
|
|
|
|
|
|
|
print join(':', unpack('A3A10', $B->{Data} ) ), "\n"; |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
$B->{Key} = 103; |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
for ( $B->GetEqual; $B->IsOk; $B->GetNext ) |
227
|
|
|
|
|
|
|
{ |
228
|
|
|
|
|
|
|
print join(':', unpack('A3A10', $B->{Data} ) ), "\n"; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 DESCRIPTION |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
This module provides methods for common Btrieve operations. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head2 Methods |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=over |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=item Create( $FileName, $FileSpec, $KeySpecs ) |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Creates a Btrieve file. This is a constructor method and returns an |
242
|
|
|
|
|
|
|
BTRIEVE::FileIO object. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
$FileSpec is a hash reference with the following defaults: |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
LogicalRecordLength => 128 |
247
|
|
|
|
|
|
|
PageSize => 512 |
248
|
|
|
|
|
|
|
FileFlags => 0 |
249
|
|
|
|
|
|
|
NumberOfDuplicatePointersToReserve => 0 |
250
|
|
|
|
|
|
|
Allocation => 0 |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
$KeySpecs is an array reference of hash references with the following |
253
|
|
|
|
|
|
|
defaults: |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
KeyPosition => 1 |
256
|
|
|
|
|
|
|
KeyLength => 1 |
257
|
|
|
|
|
|
|
KeyFlags => 0 |
258
|
|
|
|
|
|
|
ExtendedDataType => 0 |
259
|
|
|
|
|
|
|
NullValue => 0 |
260
|
|
|
|
|
|
|
ManuallyAssignedKeyNumber => 0 |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=item Open( $FileName ) |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Opens a Btrieve file. This is a constructor method and returns an |
265
|
|
|
|
|
|
|
BTRIEVE::FileIO object. |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item Close |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Closes a Btrieve file associated with an BTRIEVE::FileIO object. |
270
|
|
|
|
|
|
|
This method is called automatically from within DESTROY. |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=item IsOk |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Tests the Status property. It returns true if Status indicates |
275
|
|
|
|
|
|
|
success and false if Status indicates an error. |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=item Insert( $Data ) |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
Inserts $Data into the Btrieve file. If $Data is omitted, |
280
|
|
|
|
|
|
|
the Data property is used instead. |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=item StepFirst |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
Retrieves the physical first record of the file. |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=item StepLast |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
Retrieves the physical last record of the file. |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=item StepNext |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
Retrieves the physical next record of the file. |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=item StepPrevious |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
Retrieves the physical previous record of the file. |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=item GetFirst |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
Retrieves the logical first record of the file, |
301
|
|
|
|
|
|
|
based on the KeyNum property. |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=item GetLast |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
Retrieves the logical last record of the file, |
306
|
|
|
|
|
|
|
based on the KeyNum property. |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=item GetEqual |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
Retrieves a record which key is equal to the one specified |
311
|
|
|
|
|
|
|
by the Key/KeyNum properties. |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=item GetGreater |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
Retrieves a record which key is greater than the one specified |
316
|
|
|
|
|
|
|
by the Key/KeyNum properties. |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=item GetNext |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
Retrieves the logical next record of the file. |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
=item GetPrevious |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
Retrieves the logical previous record of the file. |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
=back |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
=head2 Properties |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
=over |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
=item Data |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
The data buffer used to transfer data from and to the Btrieve file. |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
=item Size |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
The size of the data buffer. Default is 255. |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=item KeyNum |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
The number of the key used for logical (key based) data retrieval operations. |
343
|
|
|
|
|
|
|
Default is 0. |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=item Key |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
The buffer of the key used for logical (key based) data retrieval operations. |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
=item Status |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
The status code. This is the return value of the native Btrieve call. |
352
|
|
|
|
|
|
|
It contains 0 for success or a native error code. |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
=back |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
=head1 AUTHOR |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
Steffen Goeldner |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
=head1 COPYRIGHT |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
Copyright (c) 2004 Steffen Goeldner. All rights reserved. |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
365
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
=head1 SEE ALSO |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
L, L. |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
=cut |