/******************************************************************************
**
** Source File Name = qload.sqc  1.4
**
** 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 :
**       This program is an example of how APIs are implemented in order to
**       query the current status of any LOAD being envoked on a table in
**       the database that the program is currently connected to.
**
**       This program needs the embedded SQL calls in order to connect to
**       an existing database, then to create a temporary table to work with.
**
**    APIs USED :
**       LOAD QUERY                 sqluqry()
**
**    FUNCTIONS DECLARED :
**       'C' COMPILER LIBRARY :
**          stdio.h  -  printf
**          string.h -  strncpy
**
**       DBMS LIBRARY :
**          sql.h -  see "APIs USED" above
**
**       OTHER :
**          external :
**             check_error :     Checks for SQLCODE error, and prints out any
**             [in util.c]       related information available.
**
**    EXTERNAL DEPENDANCIES :
**       - 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 <stdlib.h>
#include <string.h>
#include <sqlutil.h>
#include "util.h"

#define  CHECKERR(CE_STR)   if (check_error (CE_STR, &sqlca) != 0) return 1;
EXEC SQL INCLUDE SQLCA;

int main (int argc, char *argv[]) {
   char * LocalMsgFileName  = "QLOADMSG";
   char * RemoteMsgFileName = "RLOADMSG";

   EXEC SQL BEGIN DECLARE SECTION;
      char userid[9];
      char passwd[19];
   EXEC SQL END DECLARE SECTION;

   if (argc == 1) {
      EXEC SQL CONNECT TO sample;
	  CHECKERR ("CONNECT TO SAMPLE");
   }
   else if (argc == 3) { 
      strcpy (userid, argv[1]);
      strcpy (passwd, argv[2]);
      EXEC SQL CONNECT TO sample USER :userid USING :passwd;
      CHECKERR ("CONNECT TO SAMPLE");
   }
   else {
      printf ("\nUSAGE: qload [userid passwd]\n\n");
      return 1;
   } /* endif */
   
   /***************/
   /* LOAD QUERY  */
   /***************/
   sqluqry(LocalMsgFileName, RemoteMsgFileName, &sqlca);
   if (SQLCODE == 3523)
     printf("No load is in progress; empty message file QLOADMSG created.\n");
   else
     printf("Load status has been written to QLOADMSG\n");

   printf("CONNECT RESETting\n");
   EXEC SQL CONNECT RESET;
   CHECKERR ("CONNECT RESET");

   return 0;

}