/*******************************************************************************
**
** Source File Name = monreset.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 : to demonstrate the use the RESET DATABASE SYSTEM MONITOR DATA
**           AREAS.
** The following illustrates how to issue a snapshot and process the output.
** It prints database lock snapshots. Printing routines for other
** request types are left to the reader to complete as an exercise...
**
** OTHER APIs USED :
**          INSTANCE ATTACH               sqleatin()
**
** EXTERNAL FUNCTIONS USED IN CODE SAMPLE:
**          check_error :     Checks for SQLCODE error, and prints out any
**          [in UTIL.C]          related information available.
**
**    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.
**
*******************************************************************************/
/*******************************************************************************
    Database Monitor Reset API

#include "sqlmon.h"
#include "sqlca.h"
#include "utilapi.h"

int SQL_API_FN sqlmrset(sqluint32               version,
                        char                   *reserved,
                        sqluint32               reset_all,
                        char                   *db_alias,
                        struct sqlca           *sqlca
                       );

This function calls resets to 0, all *resettable* data items *for the
aplication performing the call*. (Note: In Version 1, Reset would affect
the data for all monitoring applications, this is no longer the case.)

INPUT:

    reset_all:    1   -     Reset monitor data for all databases,
                            and also the database manager level data.
                  0   -     Only reset data for the database 'db_alias'.

    db_alias:     NULL terminated string, the alias of the database to
                  reset.  Ignored if reset_all = 1.

OUTPUT:
    sqlca:        Indicates whether or not the call was successful.

*******************************************************************************/
#include <stdio.h>
#include <string.h>
#include "sqlca.h"
#include "sqlutil.h"
#include "sqlmon.h"
#include "utilapi.h" 


/* Reset monitored data for a single database */
int main(int argc, char* argv[]) {
    struct sqlca        sqlca;

    char dbname[9];
    char userid[9];
    char passwd[19];
    char nodename[9];

    if (argc == 5) {
        strcpy (userid, argv[2]);
        strcpy (passwd, argv[3]);
        strcpy (nodename, argv[4]);

       
       /*************************/
       /* ATTACH API called     */
       /*************************/
        sqleatin (nodename, userid, passwd, &sqlca);
    }
    else if (argc!=2) {
        printf("\nreset: Reset Database Monitor Data for a "
        "database.\n\tUSAGE: monreset dbname [userid password remote_nodename]\n");
        return 1;
    } 

    strcpy (dbname, argv[1]);

    /*****************************************************\
    * RESET DATABASE SYSTEM MONITOR DATA AREAS API called *
    \*****************************************************/
    sqlmrset(SQLM_DBMON_VERSION2, NULL, SQLM_OFF, argv[1], &sqlca);
    API_SQL_CHECK("RESET DB MONITOR");

    printf("Database Monitor Reset for '%s' was successful!\n", dbname);
 
    return 0;
}