FATS - Fast Access Tree System
Table of Contents
Programming Interfaces
MS-Basic, Quick Basic Compiler


The following Microsoft Basic example demonstrates the use of the FATS  indexing commands:

REM   FATS 02.30
REM   (c) GCS Software, Udo Gertz 1993-1998
REM
REM   Test program (Microsoft Basic / Quick Basic Compiler)
REM 
REM   Reindex the test data file customer.dat.
REM
REM   19-03-2009 U.Gertz



REM  -------> Activation of FATS Cache
REM
REM  By default the cache functionality is deactivated. It can be activated
REM  with the  "Y" Auto Refresh command.
REM
REM  If you want to reorganize a index file for example, you can activate
REM  the cache algorithm with the commands "Y\5" or "Y\106", then build the
REM  entire file and finally restore the original status (e.g. "Y\0", "Y\2").
REM  The operation can be speed up for 30 times.
REM
REM  FATS does not perform writes to the operation system until its cache is
REM  full and the least-recently-used algorithm controlling the I/O buffer
REM  cache selects a buffer for reuse. FATS never writes to the index file
REM  unless the cache buffers are entirely filled during a single command.
REM  In addition, FATS does not perform the reset disk operations that cause
REM  the operation system to flush its cache buffers to the disk. It does not
REM  close and reopen the file each time it physically expands in order to
REM  flush the directory structure.
REM  When using this command, you cannot assume that any of your updates have
REM  been written to the disk until you either perform a close operation or
REM  execute the command Write Page Map (W).
REM
REM  Use "Y\106" instead of "Y\5" in an network environment.
REM

CALL FATSBASIC( "Y\5", ERRORCODE%, RECNO&, KEYLEN% )

REM  -------> Open data file

OPEN "R", #1, "CUSTOMER.DAT", 128
FIELD #1, 1 AS DELETEDMARK$,_
          5 AS CUSTID$,_
         25 AS NAME$,_
         25 AS JOB$,_
         25 AS STREET$,_
          5 AS ZIP$,_
         20 AS CITY$

REM  -------> Create index file

CALL FATSBASIC( "C\CUSTOMER.KEY\5;25\4\A\1", ERRORCODE%, RECNO&, KEYLEN% )
IF ERRORCODE% <> 0 GOTO ENDE


REM  ========================================================================
REM            Re-Indexing
REM  ========================================================================

RECORDS& = 0

DO

  GET #1, RECORDS& + 1

  IF EOF(1) THEN

    EXIT DO

  END IF

  RECORDS& = RECORDS& + 1

  IF DELETEDMARK$ = " " THEN

    REM   "BK" Build Keys
    REM
    REM  This command inserts the primary keys of the specified
    REM  data record ("RecNo") into the index file. The number
    REM  of keys included in the command string must equal the
    REM  number of primary keys you specified in the  Create
    REM  Indexfile (C) command.
    REM
    REM  This command corresponds to the command  Insert Keys (IK)
    REM  except that FATS does not perform writes to the operation
    REM  system until its cache is full and the least-recently-used
    REM  algorithm controlling the I/O buffer cache selects a buffer
    REM  for reuse. FATS never writes to the index file unless the
    REM  cache buffers are entirely filled during the operation.
    REM  All other FATS commands will update the index file before
    REM  returning to the calling program (if this feature had not
    REM  been disabled with the Auto Refresh command).
    REM
    REM  The syntax of the command string:
    REM
    REM    szCmnd = "BK\{RecNo}\{FileNo}\{KeyStr1}[\{KeyStr2}[\{KeyStr3}]]"
    REM
    REM      RecNo      Record number
    REM
    REM      FileNo     File number
    REM
    REM      KeyStr#    Key value

    CMND$ = "BK\" + STR$(RECORDS&) + "\1\"
    CMND$ = CMND$ + RTRIM$(CUSTID$) + "\" + RTRIM$(NAME$) + "\" + RTRIM$(JOB$) + "\" + RTRIM$(ZIP$ + CITY$)

  ELSE

    REM   "DL" Manipulate Deleted List
    REM
    REM  The record numbers of deleted data records are taken up
    REM  by FATS automatically with the command Delete Record (D)
    REM  to a list of the data records that already have been
    REM  deleted, so that the command Insert Record (I) can
    REM  possibly reuse these, before the data file must be
    REM  extended. This list is administered according to the
    REM  principle last in, first out, i.e. the record deleted
    REM  last is reused as next.
    REM
    REM  This command allows you to manipulate this list by
    REM  inserting and deleting of record numbers. Because free
    REM  space in the data and index files is reclaimed and reused
    REM  by FATS automatically as records are deleted and added,
    REM  this command is normally not needed, but it can be useful
    REM  for reindexing data files containing deleted records.
    REM
    REM  Note that using this command in conjunction with the
    REM  commands "Insert Record" and "Delete Record" can result
    REM  in corrupted data files, incorrect query results, and
    REM  program failures.
    REM
    REM  The syntax of the command string:
    REM
    REM    szCmnd = "DL\{RecNo}\{GetSetFlag}\{FileNo}"
    REM
    REM      RecNo       Record number
    REM
    REM      GetSetFlag  Possible values:
    REM
    REM                  G  Remove a record number from the list
    REM                     of deleted records. If there are no
    REM                     entries in the list this command will
    REM                     return the number of the next available
    REM                     record in the data file. If there are
    REM                     entries in the list, the record number
    REM                     of the last deleted record will be
    REM                     returned.
    REM
    REM                     This command is automatically called by
    REM                     FATS when the Insert Record (I) command
    REM                     is used.
    REM
    REM                  S  Add a record number ("RecNo") to the
    REM                     list of deleted records.
    REM
    REM                     This command is automatically called by
    REM                     FATS when the Delete Record (D) command
    REM                     is used.
    REM
    REM      FileNo      File number

    CMND$ = "DL\" + STR$(RECORDS&) + "\S\1"

  END IF

  CALL FATSBASIC( CMND$, ERRORCODE%, RECNO&, KEYLEN% )
  IF ERRORCODE% <> 0 THEN EXIT DO

LOOP WHILE NOT EOF(1)

ENDE:

REM  --------> Close index file

CALL FATSBASIC( "K\1", ERRORCODE%, RECNO&, KEYLEN% )

CLOSE #1

END

© 2008  GCS Software, Udo Gertz