Was this helpful?
The Employee Query Interactive Forms Application
This section contains a sample EQUEL/FORMS application that uses a form in query mode to view a subset of the Employee table in the Personnel database. An Ingres query qualification is built at runtime using values entered in fields of the form "empform."
The objects used in this application are:
Object
Description
personnel
The program's database environment.
employee
A table in the database, with six columns:
name (c20)
age (i1)
idno (i4)
hired (date)
dept (c10)
salary (money).
empform
A VIFRED form with fields corresponding in name and type to the columns in the Employee database table. The Name and Idno fields are used to build the query and are the only updatable fields. "Empform" is a compiled form.
A display statement drives the application. This statement allows the runtime user to enter values in the two fields that build the query. The Build_Query and Exec_Query procedures make up the core of the query that is run as a result. Note the way the values of the query operators determine the logic that builds the where clause in Build_Query. The retrieve statement encloses a submenu block that allows the user to step through the results of the query.
The retrieved values are not updated, but any employee screen can be saved in a log file using the printscreen statement in the save menu item.
The following create statement describes the format of the Employee database table:
##   create employee
##     (name   = c20,    /* Employee name */
##      age    = i1,     /* Employee age */
##      idno   = i4,     /* Unique employee id */
##      hired  = date,   /* Date of hire */
##      dept   = c10,    /* Employee department */
##      salary = money)  /* Annual salary */

/*
** Procedure: MAIN
** Purpose:   Entry point into Employee Query application.
*/

## main()
## {

##   
    extern int *empfrm;         /* Compiled form - UNIX */

     /* For VMS the compiled form is declared using the statement
     ** 'globalref int *empform;'
     */
    char where_clause[101];    /* For WHERE clause qualification */

     /*
     **       Initialize global WHERE clause qualification buffer
     **      to be an Ingres default qualification that is 
     **      always true
     */

    strcpy (where_clause, "1=1");
##  forms
##  message "Accessing Employee Query Application . . ."
##  ingres personnel

##  range of e is employee

##  addform empfrm

##  display #empfrm query
##  initialize

##  activate menuitem "Reset"
##  {
##    clear field all
##  }

##  activate menuitem "Query"
##  
      /* Verify validity of data */
##    validate
      Build_Query(where_clause);
      Exec_Query(where_clause);
##  }

##  activate menuitem "LastQuery"
##  {
      Exec_Query(where_clause)  
##  }

##  activate menuitem "End"
##  {
##    breakdisplay
##  }
##  finalize

##  clear screen
##  endforms
##  exit

## } /* main */
/*  
** Procedure:   Build_Query
** Purpose:     Build an Ingres query from the values in the
**              'name' and 'idno' fields in 'empfrm.'
** Parameters:  where_clause
**              Pointer to array for building WHERE clause. */**

Build_Query(where_clause)
char      *where_clause

## {
##   char ename[21];      /* Employee name */
##   int  eidno;          /* Employee id */
##   int  name_op, id_op; /* Query operators */

/*  Query operator table maps integer values to string 
**   query operators static char
**   *opertab[] = {'=', '!=', '<', '>', '<=', '>='};

## getform #empfrm
##        (Ename = name, nameop = getoper(name),
##         Eidno = idno, idop = getoper(idno))

   /*  Fill in the WHERE clause */
   if (name_op == 0 && id_op == 0) 
   {
          strcpy (where_clause,'1=1');
   }
   else
   {
          if (name_op !=0 && id_op != 0) 
          {
            /* Query on both fields */
            sprintf (where_clause, "e.name %s \"%s\" 
            and e.idno %s %d",
            opertab[name_op -1], ename, 
            opertab[id_op -1], eidno);
          }
          else if (name_op != 0)
          {
            /* Query on the "name" field */
            sprintf (where_clause, "e.name %s \"%s\"",
            opertab[name_op -1], ename);
          }
          else
          {
             /* Query on the '"idno" field */
             sprintf (where_clause, "e.idno %s %d",
             opertab[id_op -1], eidno); 
          }
      }

## }
/*
**
**  Procedure:   Exec_Query
**  Purpose:    Given a query buffer defining a WHERE clause, issue
**              a RETRIEVE to allow the runtime user to browse the
**              employee found with the given qualification.
** Parameters:   where_clause 
**               - Contains WHERE clause qualification.
**
*/

 
## Exec_Query(where_clause)
##  char *where_clause;
## {
   /* Employee data */

## char    ename[21];
## short   eage;
## int     eidno;
## char    ehired[26];
## char    edept[11];
## float   esalary;
## int     rows; /*Were rows found? */

## retrieve (ename = e.name, eage = e.age, eidno = e.idno,
##     ehired = e.hired, edept = e.dept, epay = e.salary)
##     where where_clause
## {
##     /* put values on to form and display them */
##     putform empfrm
##        (name = ename, age = eage, idno = eidno, hired = ehired,
##        dept = edept, salary = epay)
##        redisplay
##        submenu
##        activate menuitem "Next"
##    {
        /* 
        **  Do nothing, and continue with the RETRIEVE loop. The
        **  last one will drop out.
        */ 
##    }
##    activate menuitem "Save"
##    {
##      /*  Save screen data in log file */
##      printscreen (file = 'query.log')
        /*  Drop through to next employee */
##    }  

##    activate menuitem "End"
##    {
        /*  Terminate the RETRIEVE loop */
##      endretrieve
##    }
## }

## inquire_equel (rows = ROWCOUNT)
   if (rows == 0)
   {
##     message "No rows found for this query"
   else
   {
##      clear field all
##      message "Reset for next query"
   }

##   sleep 2

## }
Last modified date: 06/10/2024