Opening a Sculptor keyed file¶
openfile |
Open a Sculptor keyed file |
Contents
SYNTAX
Open the specified Sculptor keyed file. The file must have been declared within the program by means of ![o]file.
If a file was declared by !file, meaning it is initially closed, or if it was declared initially open by using !ofile but has subsequently been closed, it should be opened before the data it contains can be accessed or the file updated. Sculptor opens a file automatically if it is required by a file access or update statement and is found to be closed, but it is strongly recommended that programs open files explicitly rather than depending on this behaviour.
This command may also be used to open a file in an ODBC database.
file_id |
The identifier of the file to be opened. The identifier is defined in the file’s !ofile declaration. |
||||||||
[name = pathname] |
This optional clause may be used to specify the path and filename of the file required. The filename requires no extension. If this clause is absent, the pathname allocated when it was last opened is used, defaulting to the path allocated when it was declared. |
||||||||
[name = SQL_connection_string] |
Alternative form for use with ODBC databases only. See SQL database connection strings. |
||||||||
[create[big] | read | update] |
File mode. This clause is optional. If it is absent the mode specified in the file declaration is used, defaulting to update mode. The meanings of the modes are:
See Testing file mode. |
||||||||
[nsf = label] |
Traps the No such file error condition which is generated if the specified file does not exist. Control passes to the line indicated by label. In order to open a keyed file in read or update mode Sculptor requires that the index file (.k extension) and the data file (no extension) are present in the directory specified. This directory is originally defined when the file is declared (!ofile), but may be overridden at run time by means of the openfile name = clause. Index-only files (created by the newkf -i option) require the index file only. If a file is opened in create mode, the index file and data file need not exist as they are created automatically when the file is opened. If this condition is not trapped, the error No such file is displayed and control passes to the active menu, if any. If no menu is active the program exits. In a !report section, an untrapped NSF causes the command to be ignored. |
||||||||
[fe = label] |
If a file is opened in create mode, and it already exists, its current contents are destroyed. This condition may be trapped by the Fe trap, which works as follows:
The fe condition cannot occur in an ODBC database - the file must exist already. |
||||||||
[err = label] |
Error conditions other than No such file and File exists (such as permissions failures) return the trappable condition err, which may be trapped by the err = clause or by the general traps = clause. Control passes to the line indicated by label. The error number is stored in the system variable sys.Error. The error numbers are defined by manifest constants in the file errors.h, which is located in the Sculptor include directory. This file may be included in a program by means of a !include declaration. If an error occurs and is not trapped, an error message is displayed and the program returns to the active menu, if any. If no menu is active the program exits. If an untrapped error occurs in a !report section, the openfile command is ignored. |
||||||||
[traps = label] |
General purpose trap clause that traps any condition not explicitly trapped, passing control to the line indicated by label. It has the lowest priority, and is only invoked if a trappable condition has not been more explicitly trapped. |
File position and buffers¶
Closing and reopening a file does not alter the current file position for next and prev type commands, nor does it clear any record buffers attached to the file. However, the clear command still operates on the buffers of closed files, unless the preserve command has been used on them.
Maximum number of files¶
There is no specific limit to the number of Sculptor keyed files that may be open at any one time, available memory being the only limiting factor. The exception to this is that clients who connect to kfserver using earlier versions of Sculptor than 4.2 are restricted to 400 open files. See Servers.
The number of files that may be open at any one time is also dependent on the operating system. If the maximum is exceeded, the program aborts. Note that each secondary index for an open file counts as an extra file.
Testing file mode¶
The read-only clause:
file_id->state
can be used to determine the mode in which a file is currently open. The values which file_id->state can have are as follows:
0 |
closed |
1 |
read |
2 |
create |
3 |
update |
NOTES
The open command may also be used to open a file. However, no traps may be attached to the open command, and it is not the recommended method.
A file may subsequently be closed by means of the close command.
The mode of a file can be changed by closing it, and then opening it in the new mode.
An attempt to open a file that is already open is ignored if the mode is unchanged.
This command may only be used to open a Sculptor keyed file or ODBC database file. In order to open a sequential file, use the open # command.
EXAMPLES
openfile Codes read traps = NOCODES
openfile Prices update nsf = PR_NSF traps = IGNORE
openfile File3 create fe = IGNORE
openfile RemData name = ServName / "/data/remdata" update
RELATED TOPICS |