/******************************************************************************
**
** Source File Name = delet.sqc
**
** 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: This sample program demonstrates the use of static SQL.
**          It deletes all the rows where the job is "Mgr".  A
**          ROLLBACK is issued so that the sample database remains
**          unchanged.
**
** An external function "check_error" is contained in the file "util.c"
** which must be compiled along with this file.  
**
**    EXTERNAL DEPENDENCIES :
**       - Ensure existence of database for precompile purposes.
**       - Precompile with the SQL precompiler (PREP in DB2)
**       - Bind to a database (BIND in DB2)
**       - 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 <string.h>
#include <stdlib.h>
#include <sqlenv.h> /* :rk.1:erk. */
#include "utilemb.h"


EXEC SQL INCLUDE SQLCA;  /* :rk.2:erk. */


int main(int argc, char *argv[]) {

   EXEC SQL BEGIN DECLARE SECTION;
      char statement[256]; /* :rk.3:erk. */
      char userid[9];
      char passwd[19];
   EXEC SQL END DECLARE SECTION;


   printf( "\nSample C program:  DELET\n");

   if (argc == 1) {
      EXEC SQL CONNECT TO sample;     /* :rk.5:erk. */
      EMB_SQL_CHECK("CONNECT TO SAMPLE"); /* :rk.6:erk. */
   }
   else if (argc == 3) { 
      strcpy (userid, argv[1]);
      strcpy (passwd, argv[2]);
      EXEC SQL CONNECT TO sample USER :userid USING :passwd;  /* :rk.5:erk. */
      EMB_SQL_CHECK("CONNECT TO SAMPLE");  /* :rk.6:erk. */
   }
   else {
      printf ("\nUSAGE: delet [userid passwd]\n\n");
      return 1;
   } /* endif */
   
   strcpy( statement, /* :rk.7:erk. */
           "DELETE FROM staff WHERE job = 'Mgr'" );

   EXEC SQL EXECUTE IMMEDIATE :statement; /* :rk.8:erk. */
   EMB_SQL_CHECK("DELETE STAFF");

   printf( "All managers have been deleted!\n" );
   EXEC SQL ROLLBACK; /* :rk.9:erk. */
   EMB_SQL_CHECK("ROLLBACK");
   printf( "On second thought -- changes rolled back.\n" );

   EXEC SQL CONNECT RESET;  /* :rk.10:erk. */
   EMB_SQL_CHECK("CONNECT RESET");
   return 0;
}
/* end of program : delet.sqc */