Incremental ISAM structures allow you to create, open, close, and rebuild individual ISAM files independent of an ISAM parameter file. The incremental ISAM structures contain the same information as the parameter file, but permit the information to be stored in your application instead of an external file, and permit direct control of the opening and closing of individual files instead of complete sets of files.
isam1.c is an example of how to use incremental ISAM structures. Other than its use of incremental ISAM structures, it is identical to isam.c.
The incremental ISAM structure typedefs are used to create a series of related structures to describe a data file, its associated index files, and the key segments from the data file used to build each index. Details on these structures are in “ISAM Functions”. We briefly discuss them here in relation to isam1.c.
IFIL Structure
Each data file will have one IFIL structure. Here we show the structure for the inventory data file. The values shown match those found in the data description record in the ISAM parameter file isam.p. When using incremental ISAM structures the file extention .dat is added to the data file name automatically. Note that one of the values is a pointer to the IIDX structure containing information about the indexes.
IFIL inv_dat = {
"invent", /* data file name
(".dat" extension is default) */
0, /* data file number */
128, /* data record length */
4096, /* data extension size */
1, /* data file mode */
1, /* number of indexes */
4096, /* index extension size */
1, /* index file mode */
&inv_idx, /* pointer to index array */
"", /* r-tree info (not used here) */
"" /* r-tree info (not used here) */
};
IIDX Structure
The IIDX structure describes the indexes for the data file. As before, you should be able to relate the values here with the values of the index description record. The file extent .idx is added to the index file name by default when the non-extended create functions are used (i.e., CreateIndexFile() and CreateIFile()). Note the pointer to the ISEG structure, which contains information about the structure of the keys.
IIDX inv_idx = {
25, /* key length */
0, /* key type */
0, /* dup off */
0, /* null off */
32, /* empty char */
1, /* number of key segments */
&inv_seg, /* pointer to segment array */
"Itemidx", /* pointer to symbolic index name (r-tree) */
"invent" /* optional index name (if this field is *
* omitted, the default index name will be *
* used. The default is the name supplied *
* in the IFIL pfilnam with an extension *
* of ".idx".) */
};
ISEG Structure
Each key segment is described by an ISEG structure. If there are multiple segments then the ISEG structure must be an array. There must be an ISEG array element for each key segment as specified in the IIDX structure. It is easy to relate the key segment description record of isam.p to the following ISEG structure:
ISEG inv_seg = {
2,25,2
};
InitISAM
When using incremental ISAM structures initializing the system is similar to the low-level functions. InitISAM() performs the same function as InitCTree() or the initialization record of the ISAM parameter file.
CreateIFile and OpenIFile
Each data file is created or initialized by CreateIFile() or OpenIFile(). The address of the IFIL structure for that data file is passed to the function. This call also opens all associated index files.
All other operations in isam1.c are identical to the ISAM parameter file example isam.c. The only differences are in the way you initialize the system and create/open the files. There are two other incremental ISAM functions, which we don’t use in these examples. CloseIFile() closes individual data files and their associated indexes, and RebuildIFile() rebuilds a corrupted data file and its indexes.
The regular CloseISAM() function closes all open ISAM files, whether they were opened with an ISAM parameter file or as an incremental structure.