OpenFileWithResource Incremental ISAM open, based on the IFIL Resource. Short Name OPNRFIL() Type ISAM function Declaration COUNT OpenFileWithResource(COUNT filno, pTEXT filnam, COUNT filmod) Description OpenFileWithResource() opens the data file with the name pointed to by filnam and optional index files referenced by the IFIL resource information stored in that file. This resource was automatically added to the file when the file was created with CreateIFile() unless Resources have been disabled for this file. All subsequent references to the file are made via the filno value. filno must be less than fils - 1, where fils is the second parameter in the initialization routine InitISAM(). The name referenced by filnam must conform to the operating system environment, and usually can include directory path names and/or disk drive identifiers. If OpenFileWithResource() is called with a different path than the original IFIL definition holds, an attempt is made to automatically update alternative index names with the same path modification. The file name should be null terminated. If filnam references an index file with additional index members, OpenFileWithResource() opens all indices included in the file. Consecutive file numbers are assigned to the data file and any associated indices. If filno is less than zero, c-tree Plus finds the first available block of consecutive file numbers that can accommodate the data file and its indices. If a block of numbers is found, the first number in the block is assigned to the data file and returned. If filno is greater than or equal to zero, filno is assigned to the data file and returned provided enough consecutive file numbers are available. filmod is limited to the values shown below. Modes not listed are reserved for file creation and cannot change for an existing file. For example, ctFIXED or ctVLENGTH are not specified when opening the file, as they are set when the file is created. ctPERMANENT ctVIRTUAL ctEXCLUSIVE ctSHARED ctREADFIL ctCHECKLOCK ctCHECKREAD ctDUPCHANEL ctWRITETHRU ctOPENCRPT ctCHECKREAD and ctDUPCHANEL are available only with the c-tree Server. See filmod in the index for additional information. Some values must be used exclusively. For instance, you cannot use both ctSHARED and ctEXCLUSIVE. Note: This function supports EXCLUSIVE file opens. For more information, please refer to “Multi-user File Mode”. Return OpenFileWithResource() returns the file number assigned to the data file. If an error occurs, the function returns a -1 and isam_err contains an error code. On a successful open when a differently named file matches the file ID of an open file, the error return will be NO_ERROR (0) but sysiocod will be set to MFID_COD (-586). If the files are detected to actually be different, then the file ID is changed as discussed above and sysiocod is not set to MFID_COD.
See c-tree Plus Error Codes for a complete listing of valid c-tree Plus error values. Example COUNT filno = 0, retval; TEXT filnam[15] = "sample.dat";
printf("\nCould not initialize. Error %d.", retval);
else {
if (OpenFileWithResource(filno, filnam, ctSHARED) < 0) printf("\nCould not open file (%d,%d).", isam_err, sysiocod);
else if (CloseRFile(filno)) printf("\nCould not close file (%d,%d).", isam_err, sysiocod);
printf("\nCould not close ISAM.");
} Limitations The data file must contain a resource record with the appropriate Incremental ISAM Structures (IFIL, etc.). CreateIFile() inserts a resource record and adds Incremental ISAM Structures. However, if the file was created without resource records, by either removing #define RESOURCE from ctoptn.h or by using ctDISABLERES as a file mode, resources can be enabled dynamically using EnableCtResource(). The Incremental ISAM Structures can be inserted by calling PutIFile(). See also EnableCtResource(), PutIFile(), OpenIFile(), InitISAM(), CreateIFile(), CloseISAM(), OpenFileWithResourceXtd() and “ISAM Functions” in the c-tree Plus Programmer’s Reference Guide describing the ISAM parameters. |
|||||||||||||||||||||||||||||||||