| ![]() | ||||||||||||||||||||
The following Microsoft Pascal example demonstrates the use of the FATS
 indexing commands:
(*
FATS 02.30
(c) GCS Software, Udo Gertz 1993-1998
Test program (Microsoft Pascal, IBM Pascal)
Fast Re-Indexing with the command "XB"
This program needs the extended version of FATS
19-03-2009 U.Gertz
*)
program REINDEX (input, output);
type
custrec = record
DELETEDMARK: char;
ID: lstring(5);
NAME: lstring(25);
JOB: lstring(25);
STREET: lstring(25);
ZIP: lstring(5);
CITY: lstring(20);
end;
const
fn_cust = 'CUSTOMER.DAT';
var
hCustomer: file of custrec;
cbuffer: custrec;
szCmnd: lstring(255);
szFATSkey: lstring(255);
szRecno: lstring(8);
uFATSError: word;
dwFATSRecno: integer4;
dwRecords: integer4;
function FATSCALL (vars szCmnd: lstring; vars nErrorcode: word;
vars szReturnKey: lstring) : integer4; extern;
begin
assign (hCustomer, fn_cust);
hCustomer.mode:=direct;
reset (hCustomer);
(*
-------> Create index file
*)
(*
"C" Create Indexfile
With this command you create an index file, whereby a possibly
already existing file with the same name is deleted.
After the file is created it will be opened with the opening
flags defined with the command Auto Refresh (Y) and can be
accessed under the file number you specified.
Max. 200 primary keys per data record can be administered in an
index file, the max. key length amounts to 240 characters.
Full path names must be specified using forward slashes (/)
instead of Backslashes (\), because FATS normally uses the
Backslash character as delimiter.
You may change the delimiters by placing the desired character
as the first character of the command string,
e.g. szCmnd = "&C&C:\ARTICLES.KEY&1&1&A&1". Any character with
an Ascii code less then 48 will be accepted.
The syntax of the command string:
szCmnd = "C\{Filename}\{KeyLength}\{KeyCount}\{KeyType}\{FileNo}"
FileName filename, perhaps with an additional path
(e.g. C:/DATA/ARTICLES.KEY or ARTICLES.KEY)
KeyLength Maximum key length (1-250)
If you choose to have more than one key for
this index file, you may specify the length
for each key (separated by a semicolon ";")
to conserve diskette space.
Otherwise, the maximum length applies to all
keys, i.e. every key will occupy the maximum
space.
KeyCount Number of primary keys (1-200)
KeyType Key type (A = Ascii text, I = Integer)
FileNo File number (1-40)
*)
szCmnd:='C\CUSTOMER.KEY\5;25\4\A\1';
dwFATSRecno:=FATSCALL(szCmnd, uFATSError, szFATSkey);
If uFATSError <> 0 Then Begin
writeln;
write ('FATS Errorcode: '); write (uFATSError);
writeln (' (Command: C)');
writeln;
close( hCustomer );
Return;
End;
(*
========================================================================
Re-Indexing
========================================================================
*)
dwRecords:=0;
repeat
seek(hCustomer, dwRecords + 1);
get(hCustomer);
cbuffer:=hCustomer^;
If EOF( hCustomer ) Then Begin
(*
After the last record was inserted the creating process
has to be terminated with the command "XB\{FileNo}\0".
Because this command closes the index file you don't
have to do a close command.
*)
szCmnd:='XB\1\0';
dwFATSRecno:=FATSCALL(szCmnd, uFATSError, szFATSkey);
break;
End;
dwRecords:=dwRecords + 1;
If cbuffer.DELETEDMARK = ' ' Then Begin
(*
"XB" Re-Indexing: Build
This command inserts the primary keys of the specified
data record ("RecNo") into the index file. The number
of keys included in the command string must equal the
number of primary keys you specified in the "C" command.
Use this command to insert the keys of all data records
into the index after a successful "Create Indexfile" (C)
command within a programme loop. The command only can be
used during the re-indexing phase, i.e. immediately
according to a call of the "C"-command.
The command "XB\{FileNo}\0" terminates re-indexing and
closes the corresponding index file. The file is closed
automatically in the case of a premature abnormal
termination of indexing. A subsequent close-command can
always remain undone.
The length of the transferred keys may not exceed the
maximum key length specified with the "Create Indexfile"
command. Variable length keys will be padded with the Ascii
char 0 to the maximum key length.
The syntax of the command string:
szCmnd = "XB\{FileNo}\{RecNo}\{KeyStr1}[\{KeyStr2}]"
FileNo File number
RecNo <> 0 Record Number
== 0 Stop Re-Indexing
KeyStr# Key value
*)
szCmnd:='XB\1\';
If encode(szRecno, dwRecords:8) Then concat(szCmnd, szRecno);
concat (szCmnd, '\');
concat(szCmnd, cbuffer.ID);
concat(szCmnd, '\');
concat(szCmnd, cbuffer.NAME);
concat(szCmnd, '\');
concat(szCmnd, cbuffer.JOB);
concat(szCmnd, '\');
concat(szCmnd, cbuffer.ZIP);
concat(szCmnd, cbuffer.CITY);
End Else Begin
(*
Add the data record to the list of deleted records.
*)
szCmnd:='DL\';
If encode(szRecno, dwRecords:8) Then concat(szCmnd, szRecno);
concat (szCmnd, '\S\1');
End;
dwFATSRecno:=FATSCALL(szCmnd, uFATSError, szFATSkey);
until uFATSError <> 0;
close(hCustomer);
end.
© 2008
GCS Software, Udo Gertz