/*******************************************************************************
**
** Source File Name = dbstop.c  1.2
**
** Licensed Materials - Property of IBM
**
** (C) COPYRIGHT International Business Machines Corp. 1995, 1999 
** All Rights Reserved.
**
** US Government Users Restricted Rights - Use, duplication or
** disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
**
**
**    PURPOSE :
**       an example showing how to use the following APIs in order to:
**          - FORCE USERS off of a database
**          - STOP a DATABASE MANAGER
**       This program will stop further connect to the database and will
**       force the current users off, and shut down the database manager.
**
**    APIs USED :
**       FORCE APPLICATION        sqlefrce()
**       STOP DATABASE MANAGER    sqlepstp()
**
**    STRUCTURES USED :
**       sqlca
**
**    OTHER FUNCTIONS DECLARED :
**       'C' COMPILER LIBRARY :
**          stdio.h  -  printf
**
**       internal :
**
**       external :
**          check_error :     Checks for SQLCODE error, and prints out any
**          [in util.c]          related information available.
**                               This procedure is located in the util.c file.
**
**    EXTERNAL DEPENDENCIES :
**       - Ensure existence of database for precompile purposes.
**       - Compile and link with the IBM Cset++ compiler (AIX and OS/2)
**         or the Microsoft Visual C++ compiler (Windows) 
**         or the compiler supported on your platform.
**
** For more information about these samples see the README file.
**
** For more information on programming in C, see the:
**   -  "Programming in C and C++" section of the Application Development Guide
** For more information on Building C Applications, see the:
**   -  "Building C Applications" section of the Application Building Guide.
**
** For more information on the SQL language see the SQL Reference.
**
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <sqlca.h>
#include <sqlenv.h>
#include "util.h"

#define  CHECKERR(CE_STR)   check_error (CE_STR, &sqlca);

int main (void) {
   struct sqlca sqlca;
   unsigned long *agentidarray;
   /* This array is ignored when used in the FORCE APPLICATION API, when
      SQL_ALL_USERS is defined as the "count".  All users are forced off */

   printf ("Forcing Users off DB2\n");
   /******************************\
   * FORCE APPLICATION API called *
   \******************************/
   sqlefrce (SQL_ALL_USERS, agentidarray, SQL_ASYNCH, &sqlca);
   if (sqlca.sqlcode == SQLE_RC_NOSTARTG) {
      printf ("No start database manager command was issued\n");
      return 1;
   } /* endif */
   CHECKERR ("force application all");

   printf ("Stopping the Database Manager\n");
   /**********************************\
   * STOP DATABASE MANAGER API called *
   \**********************************/
   sqlepstp (NULL, &sqlca);
   CHECKERR ("stopping database manager");

   printf ("Database Manager STOPPED\n");
}