Prev Next Title Contents

SUPPORT FOR DATA-BASES


There is in Gifa a support for the UNIX standard data-base file format dbm. A dbm data-base is composed of two file : base_name.pag and base_name.dir which together hold the information of the base_name data-base. Each entry consist of a field indexed with an access key. Each entry is accessed with the access key. Data can be retrieve, stored, modified in the data-base. Every operations are realised on the file, but the disk accesses are minimised.

In Gifa, such a dbm data-base is accessed through a binding to an associative array. Each entry of the data-base appear as a element of the array. Reading, storing and modifying entries is performed by fetching and assigning array values. The access key of the entry in the dbm file appears as the index of the associative array, and the content appears as the value of the associative array. Due to internal Gifa limitation, only key up to 31 characters and entry up to 256 characters can be handled.

DBOPEN, DBCLOSE

These two commands permits to associate the dbm file with a pseudo internal array variable. The command

dbopen array_name file_name

will associate a pseudo associative array with the dbm files of base name : file_name. The file is created if it does not exist yet. No actual variable array_name is created, but each operation on it is performed on the dbm file.

DBCLOSE closes the file and forget about the array array_name .

The functions dbm() and nextlm() permits to handle the dbm file in macro processing. The control FOREACH permits to scan easily through all the entries of a dbm file.

Let's give an example :

dbopen array file_db ; associates the file

set array['dim'] = $dim ; store entries (associative array)

set array['size_1d'] = $si1_1d

dbclose array ; and closes the file

after closing array[] is not available anymore (it was here as a tool to writing into the file file_db.

However, values have been stored into the file, so next time you will dbopen it (eventually associating an array with a different name this time), they will be there again.

dbopen next_time file_db

print $next_time['dim']

dbclose next_time


Prev Next Title Contents