4.2.6 Databases



RMS offers two layers of file systems. The lower layer is a flat file system. The outer layer adds databases with logical files to the flat file system. The RMS programmer is encouraged to use the database system when programming.

Databases are organized collections of related data. A good example of a simple database is a book library. In it you have thousands of books with a card catalog indexing all of the books. More complex databases have interrelations between the data. A common example of a complex database is an accounting system. Here you have several sets of related data (customers, invoices, payments, etc.) that are interrelated (invoices tied to customers, payments tied to invoices, etc.).

Each database consists of one or more logical files. A logical file is a single collection of related data (a vendor master). Logical files should always be referred to by their logical file name (like vendor). This way, if transaction logging is enabled for the logical file, changes to the logical file are logged.

Logical names are something unique to C/Base. A logical name is a reference to a single file. This can be a logical file name of an RMSfile within a database or the pathname of an RMSfile. For example, if you are in the home directory of the demo database, you can reference the C/Base Demonstration RMSfiles with names like data\mag. From any directory in the system, you can reference the Demonstration RMSfiles with names like demo~magazine. The tilde character (~) is required with no blanks before or after it. The part of the name before the tilde, demo, is the database name. The part of the name after the tilde, magazine, is the logical file name.

Within one database, logical RMSfile names must be unique. However, different databases can have the same logical RMSfile name. Because of this, any reference to a logical RMSfile must always mention its database.

As it turns out, most applications use logical RMSfiles from the same database. For this reason, RMS provides a default database; used only when the database name is not explicitly stated. This leaves only the logical RMSfile name to be specified. Using the same example we had before, a logical name can also be ~magazine (or under certain circumstances just magazine). See C/Base Reference Manual Chapter 2, Databases for more information on logical names.

A default database is set in one of two ways. The first method requires a function call within the program:

dbopen ("demo");

(see dbopen(C-3)). This makes the program only work with the demo database. The second method requires setting the environment variable DBASE to the name of the database. None of the C/Base programs call dbopen directly. This enables you to design applications that work with several databases of similar structure.

We mentioned earlier that there are certain circumstances where you can leave off the tilde character (~). The only time this can be done is when a default database is established as described above AND no RMSfile exists in the current directory with the same name as the logical file name. For any toolkit(C-1) application, this is always the case; logical RMSfile names can always be named using just the logical file name (magazine).