CHAPTER 2: The Command Language Interface


Query Language commands may be invoked from a Fortran program by calls to the routine mfcall specifying the database directory and the Empress SQL statement.

   mfcall (database_directory, query_language_statement)

Both the database directory and the Empress SQL statement are in the form of strings which may be dynamically built by the application program. mfcall returns 0 if the statement succeeds, and a non-zero exit status if it fails, for example, due to a syntax error in the Query Language statement, or an invalid attribute or table name is given.

A description of mfcall is included in the chapter Manual Pages.



2.1 The Header File

The header file msfer.h or msf.h, which are shown below, must be included at the beginning of each program using mfcall. It has the definitions for mfcall, as well as all the mf functions (the Database Manipulation Language Interface). You should use the full pathname for this file, which resides in the include directory under the directory where Empress is installed, unless your system provides other conventions for including files.

The header file msfer.h contains:

   logical  mfcpi, mfchka, mftrst
   logical  mfadd, mfdel,mfgetb, mfopen
   logical  mfptvs, mfptvi, mfputi, mfsrtb, mfput
   logical  mfqatr, mfqc, mfqci, mfqmch
   logical  mfqnul, mfqrg, mfqrgi
   
   integer  mfcomp, mfgtvi, mfgetv, mfigta
   integer  mfget, mfprev, mfrget, mfrprv
   integer  mfoper
   
   external  mfcall, mfstop, mfinit, mfexit, mfcln
   external  mfadd, mfdel, mfgetb, mfcpi, mfchka, mfopen
   external  mfptvs, mfptvi, mfputi, mfsrtb, mfput
   external  mfcomp, mfgtvi, mfgetv, mfigta
   external  mfget, mfprev, mfrget, mfrprv
   external  mfgete, mfclos, mfacls, mfsetn, mfqand, mfqor
   external  mfqnot, mfqatr, mfqc, mfqci, mfqmch, mfqnul
   external  mfqrg, mfqrgi, mfqieq, mfqseq
   external  mftrst, mftrcn, mftrcm
   external  mferrt, mfoper, mfprte

The header file msf.h contains:

   logical  mfcpi, mfchka, mftrst
   
   integer  mfcomp, mfgtvi, mfgetv, mfigta
   integer  mfget, mfprev, mfrget, mfrprv
   
   external  mfcall, mfstop, mfinit, mfexit, mfcln
   external  mfadd, mfdel, mfgetb, mfcpi, mfchka, mfopen
   external  mfptvs, mfptvi, mfputi, mfsrtb, mfput
   external  mfcomp, mfgtvi, mfgetv, mfigta
   external  mfget, mfprev, mfrget, mfrprv
   external  mfgete, mfclos, mfacls, mfsetn, mfqand, mfqor
   external  mfqnot, mfqatr, mfqc, mfqci, mfqmch, mfqnul
   external  mfqrg, mfqrgi, mfqieq, mfqseq
   external  mftrst, mftrcn, mftrcm



2.2 Initialization and Cleanup

There are two ways to organize a program using mfcall.

You can have the main program unit defined for you by naming the entry point of your program subroutine mfmain. Initialization and cleanup will then be taken care of. If you do this, you should also replace the stop call, if any, with a call to mfstop.

You can write your own main program unit, calling mfinit before using the interface routines and mfcln before stop. These calls are necessary to carry out various initialization and cleanup tasks.



2.3 Compiling and Linking

empf77 and empf90 compiles a Fortran program invoking the Empress libraries. It invokes the appropriate Fortran compiler and searches the Empress libraries. The syntax for empf77 and empf90 are:

   empf77 [compiler_options] ... file ...
   empf90 [compiler_options] ... file ...

Refer to the Manual Pages for more detail description of empf77 and empf90.

2.4 Examples Using the Command Language Interface

The database name in the following examples is a logical database named repairs. The physical location of the database could be anywhere on the system, such as:

   /usr/joe/repairs

In the following examples, the header file is indicated as HEADER_FILE and you should substitute this with the full pathname of the header file. For example:

   include '/usr/empress/include/msfer.h'

The following program, names.f, selects the names of all employees in the personnel table.

   subroutine mfmain
      include 'HEADER_FILE'
      call mfcall ('repairs', 'select name
   &               from personnel')
      call mfstop
      end

The following program, employees.f, selects the names and phone numbers of all employees in the personnel table, counts them, and prints suitable headings.

      subroutine mfmain
      include 'HEADER_FILE'
      print 10
   10 format ('Current Employees',// '')
      call mfcall ('repairs', 'select name,
   &               phone from personnel')
      print 20
   20 format ('Total Number of Employees = ')
      call mfcall ('repairs', 'select count
   &               from personnel dump')
      call mfstop
      end