## Files and Databases

APLX offers a range of features for accessing data in files. These include facilities both for storing and retrieving data within your APL applications, and for exchanging data with other applications. They include:

### Component Files

For simple APL applications, you can often keep all the data you need in the current workspace in APL variables. However, for more sophisticated applications, this may not fit your requirements. For example, if you wrote a suite of functions which produced monthly profit and loss accounts, you might want to store the data for each month separately. You could arrange to keep the data in a series of stored workspaces, but you would not want to replicate the functions in each of these workspaces.

Component files provide an efficient and easy-to-use method to store APL variables (of any type, shape, and size) in a file, and read them into the workspace when they are needed. Each individual item in the file is known as a component. A single number may constitute one component, while a matrix containing several thousand numbers may be its next door neighbour.

Functions, operators and classes can also be stored in component files, but they must first be converted into character arrays by the system function ŒCR, or stored via the overlay system function, ŒOV.

APLX supports two different component file systems. The first is based on system functions such as ŒFTIE. It uses a syntax which is compatible with APL interpreters from other vendors.

The second of these is based on the file-access primitives Ô Õ Ò Ó, as implemented in the predecessor to APLX, APL.68000.

For more information, see the separate section on Component File Systems.

### Native Files

'Native' files are operating-system files which are not necessarily associated with APL, and which are typically used for exchanging data with non-APL applications. For example, they might include text files, HTML pages, or binary files produced by a Fortran application. Unlike component files (which retain information about the type and shape of APL data), the structure of native files is unknown to APLX, so you as the programmer are responsible for specifying how the data should be interpreted. For example, you can specify that you want to read the first four bytes of a file as an integer, and the next 32 bytes as a character vector.

See the section on Native File Functions for details.

### System Functions for Data Import/Export

Although native files provide a general, low-level way to exchange data with other applications, there are a number of common file formats for which APLX provides an easier alternative, by means of the ŒIMPORT and ŒEXPORT functions. These allow you to read or write the entire contents of a file in a single call. They support a number of common file formats, for example Unicode text, or Comma-Separated Variable (CSV) files used for spreadsheets. The advantage of ŒIMPORT and ŒEXPORT is that you do not have to write any code to interpret the file format yourself, since APLX already has the necessary logic built-in.

### Accessing Database Records

Much of the data in modern computer systems, especially for large commercial applications with many thousands of records, is held in relational databases. These are accessed and updated using SQL ('Structured Query Language'). You can easily interface to such databases by using the ŒSQL system function. This allows you to read and write records in most major commercial database systems including Oracle, SQL Server and DB2, as well as open-source databases such as MySQL and PostgreSQL. You can also exchange data with popular desktop file systems such as Microsoft Access.

### Other facilities

In addition to the above facilities for directly reading and writing data into the APL workspace, APLX provides a number of System Classes which can manipulate specific types of files such as images and movies. See the documentation on the Picture, Movie, Image classes in the separate manual System Classes and User-Interface Programming.

Topic: APLX Help : Help on APL language : APL Fundamentals : Files and Databases

[ Previous | Contents | Index ]