# CHAPTER 3: The Windows Batch Interface

## 3.1 Introduction

There are two commands you can use to execute Empress Query Language commands under the Windows NT command prompt:

1. `empcmd` to execute a single command.
2. `empbatch` to execute a batch of commands.

The Batch Interface allows rapid packaging of prototype database management interactions. It allows existing console programs, C routines, and other batch programs to be invoked by simple commands, thereby encouraging the rapid design and development of custom interfaces to the database management system.

## 3.2 Execute a Single Command from Windows Prompt

The command `empcmd` is used to have the Windows NT command prompt execute one Empress SQL command. The syntax of the command is as follows:

`empcmd database "command"`

where:

`database` | is the name of the database directory.
`command` | is the Empress SQL command to be executed.

Example 1: Retrieve an Attribute Values from a Table

The following command lists all employees from the `personnel` table in the database `repairs`:

       empcmd repairs "SELECT name FROM personnel"

The above command executes the Empress SQL command "`SELECT name FROM personnel`" on the database called `repairs`, without the need to invoke `empsql` directly. Once the command has been executed, control returns to the Windows NT command prompt.

The above `empcmd` command can also be stored in a batch file called `names.bat`. Once this is done, typing in `names` under the command prompt will produce the list of employee names as before.

Example 2: Passing Argument to the Batch File

The following command, stored in a batch file called `phone.bat`, produces the telephone number of the employee given as its argument.

       empcmd repairs "select phone from personnel dump
            where name = '%1'"<$Idump keyword>

The `dump` keyword has been included in the `empcmd` command to suppress printing the heading `phone`, which would be spurious information for this program.

To find Jones' phone number, type in:

       phone Jones

will get the following:

       667-2951

## 3.3 Execute a Batch SQL Commands from Windows Prompt

The command `empbatch` allows you to submit a batch of Empress commands from the operating system. The syntax of `empatch` is as follows:

`empbatch database`

where:

`database` | is the name of the database directory.

The command `empbatch` works in interactive mode. It is similar to being in Empress SQL but there are no prompts. A semicolon (;) is used to end each Query Language command, and a command may span several lines. The program exits on a syntax error.

For example, if you type in from the command prompt:

       empbatch repairs

the cursor will wait on the next line for a command. Typing in a command brings an immediate response:

       SELECT FROM loans WHERE name = "Jones";

will produce:

       names   date                amount

       Jones    7 February 1992    $33.95
       Jones    3 April 1992       $25.00
       Jones   12 August 1992     $300.00

<Ctrl+Z> or <F6> will return you to the command prompt.

To submit a series of Query Language commands from a file, use input redirection from the file or specify it as the optional input file. For example, you use a system editor to create a file called `queries` which contains:

       select from loans where name = "jones";
       select from loans where name = "mosca";

Then submit the queries by typing:

       empbatch repairs < queries

The input redirection makes the `empbatch` command get input from the file `queries`.