/*******************************************************************************
**
** Source File Name = dbstop.c 
**
** Licensed Materials - Property of IBM
**
** (C) COPYRIGHT International Business Machines Corp. 1995, 2000 
** 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 "utilapi.h"


int main (void) {
   struct sqlca sqlca;
   sqluint32    *agentidarray=NULL;
   /* 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 */
   API_SQL_CHECK("force application all");

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

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