|
General Description
Hardware- and Software-Requirements
FABS Plus Compatibility
Using the Library
The toolkit FATS enables you the uncomplicated and fast administration of large volume of data with your preferred programming language.
The possibilities for the organization of data files supplied by conventional compilers are in most cases not sufficient. Data records are usually stored sequentially, i.e. new data records are added to the end of the file. This method is easy to implement, however it makes the access to the individual data records extremely inefficient, because searching for a data record will unfavourably result in a complete sequential scan of the whole data file.
FATS extends the abilities of your programming language with a powerful method to the indexed-sequential access to data. It operates with a modified version of the BTree+ algorithm. Because of this procedure and the fact that FATS was written to 100% in optimized assembler code, the access time constantly stays small also with several millions of data records.
At the indexed-sequential access to the data file, the search for records is done with the help of keys that represent a subset of the actual records and are stored in a file called index file. FATS does all work that is necessary to administrate the index file.
The keys in the index file are always presented in sorted order. With inserting or deletion of keys the index file is updated automatically by FATS.
You must modify your familiar way of programming when using FATS only slightly. Communication between your programming language and FATS is made by command strings with unique syntax and therefore requires a short training period. Even the development of networkable applications does not require considerable additional expenditure in relation to applications of single workstations.
Hardware- and Software-Requirements
The basic version of FATS is executable on all IBM PC or hundred percent compatible computers. As operating system MS-DOS, PC-DOS or compatible system are presupposed. FATS also is available for other operating systems (e.g. Windows 3.x, Windows 32s, Windows 95, Windows NT, IBM OS2 1.x, IBM OS2 2.x/Warp, SCO Unix, Sinix, Linux, Netware). FATS supports many popular programming languages, in chapter 9 you find an outline.
The FATS Toolkit supports a calling interface that is 100% compatible with the program FABS-Plus Net of Computer Control Systems. All programming interfaces of this software were reproduced.
There is no need to change your source code. You just need to change obj-/dll files to use FATS in existing projects, for example in the MS-DOS environment you only have to replace the FABSP.OBJ module with the FATS.obj module.
In order to obtain a speed increase, a completely new file structure had to be implemented in FATS. With the enclosed converting program it is possible to convert existing FABS Plus files to the new file format of FATS (see chapter 6).
FABS-interfaces available in FATS.OBJ (in brackets the absolute access locations):
FABSB86 BasicA, GWBasic etc. (offset 5) FABSMB Basic Compiler (offset 8) FBSPAS IBM- / MS-Pascal (offset 11) GFSEG common (offset 14) FBSFOR Fortran Compiler (offset 17) FBSCOB Cobol Compiler (offset 20) FBPAS1 MS-Pascal (offset 23) GFSEG1 common (offset 26) FBSSANYO Sanyo-Basic (offset 29) KEYADR common (offset 42)
Further compatible interfaces were integrated into the respective FATS modules and are described in the context of the description of the appropriate programming language (see chapter 9).
The following Turbo Pascal example demonstrates the use of FATS. Even if you operate with another programming language, you should read the following explanations. You find a individual description of the programming language interfaces in chapter 9. On the FATS diskette you additionally find a sample program to each programming language.
All commands provided by FATS can be executed with one function:
function FATSCALL (var szCmnd:string; var nErrorcode: word; var szFatsKey:string): longint;
The meaning of the used parameters:
szCmnd With this command string you specify the actual FATS command. The available commands are described in chapter 4. nErrorcode Your application must always pass this variable as the status parameter on a FATS call. After the FATS call, the application should always check the value of this variable. FATS returns a errorcode of 0 after a successful operation. FATS indicates any errors which occur during processing by returning a nonzero value in the errorcode variable. See chapter 5 for a list of FATS errorcodes and their possible causes. szFatsKey This variable will contain the key value of a found key after any search command (S,G,F,L,N,P,A,E).
Create Data- & Indexfile (Turbo-Pascal)
At the beginning of the program you define the file structure and declare some variables:
{ structure of the data file }
{ the "deleted mark" is used to mark deleted records }
type
customers = record
DELETEDMARK: char;
STATE: string[5];
NAME: string[25];
JOB: string[25];
STREET: string[25];
ZIP: string[5];
CITY: string[20];
end;
var
hCustomer: file of customers;{ data file }
custrec: customers;{ file buffer }
szCmnd: string;{ Command string (input) }
szFatsKey: string;{ Key value (output) }
nErrorcode, word;{ Errorcode (output) }
dwRecno: longint;{ record number }
{ create data file }
assign ( hCustomer, "CUSTOMER.DAT" );
rewrite ( hCustomer );
{ create index file containing the following keys:
NAME, JOB & ZIP + CITY }
szCmnd:='C\CUSTOMER.KEY\25\3\A\1';
dwRecno:=FATSCALL(szCmnd, nErrorcode, szFatsKey);
The syntax of the command:
szCmnd := "C\Filename\KeyLength\KeyCount\KeyType\FileNo";
"FileName" filename, perhaps with an additional path
(e.g. C:/DATEN/ARTIKEL.KEY or ARTIKEL.KEY)"KeyLength" Maximum key length "KeyCount" Number of primary keys (1-200) "KeyType" Key type (A = Ascii text, I = Integer) "FileNo" File number (1-40)
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.. CMND$ = "&C&c:\data\customer.key&25&3&A&1". Any character with an Ascii code less then 48 will be accepted.
Insert Record
After you created the files successfully you are able to insert records:
{ initialize "deleted mark" }
custrec.DELETEDMARK:=' ';
{ insert primary keys }
szCmnd:='I\1\'+custrec.NAME+'\'+custrec.JOB+'\'+custrec.ZIP+custrec.CITY;
dwRecno:=fatscall(szCmnd, nErrorcode, szFatsKey);
{ insert data record }
if nErrorcode = 0 then begin
seek( hCustomer, dwRecno - 1 );
write( hCustomer, custrec );
end;
With the command Insert Record (I) the primary keys are inserted into the index file. After that you receive the record number that must be used to write the data record to the data file using the standard pascal instructions SEEK & WRITE.
Searching for Record
A serie of FATS commands supports you at searching for records:
Write( 'Please input customer name: ' );
ReadLn( szFatsKey );
{ Search record above first key (customer name) }
szCmnd:='S\1\1\'+szFatsKey;
dwRecno:=fatscall(szCmnd, nErrorcode , szFatsKey);
{ Load data record }
seek( hCustomer, dwRecno – 1 );
read( hCustomer, custrec );
Change Content of a Record
When changing the content of records the keys have to be considered:
{ save old key values }
key1:=custrec.NAME;
key2:=custrec.JOB;
key3:=custrec.ZIP+custrec.CITY;
str(dwRecno, recnostr);
{ make changes to the record }
...
{ check if key values have changed }
if key1 <> custrec.NAME then begin
szCmnd:="R\1\" + recnostr + "\1\" + key1 + "\"+custrec.NAME;
dwRecno:=fatscall(szCmnd, nErrorcode, szFatsKey); { Update keys }
end;{ This has to be done for all primary keys }
.... and finally save changed record ....
Delete Record
{ delete record }
if nErrorcode = 0 then begin
custrec.DELETEDMARK:='D';{ "set deleted mark" }
seek( hCustomer, dwRecno - 1 );
write( hCustomer, custrec );
end;
{delete primary keys }
szCmnd:='D\'+recnostr+'\Y\1\'+custrec.NAME+'\'+custrec.JOB+'\'
+custrec.ZIP+custrec.CITY;
dwRecno:=fatscall(szCmnd, nErrorcode, szFatsKey);
The record numbers of deleted data records are taken up by FATS with the command Delete Record (D) to a list of the data records that already have been deleted, so that the command Insert Record (I) can possibly reuse these, before the data file must be extended. This list is administered according to the principle read in, first out, i.e. the record deleted last is reused as next.
Close Data- and Indexfile
close( hCustomer );
szCmnd:="K\1";{ close index file no. 1 }
dwRecno:=fatscall(szCmnd, nErrorcode, szFatsKey);
© 2008 GCS Software, Udo Gertz