/*******************************************************************************
**
** Source File Name = dcscat.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 :
** This program is an example of how APIs are implemented in order to
** access DB/2. The order of the program is as follows:
** - create/catalog a DCS database
** - list a directory of DCS databases (showing what was created)
** - uncatalog the DCS database
**
** STRUCTURES USED :
** "sql_dir_entry" :
** unsigned short struct_id;
** unsigned short release;
** unsigned short codepage;
** unsigned char comment[SQL_CMT_SZ];
** unsigned char ldb[SQL_DBNAME_SZ];
** unsigned char tdb[SQL_LONG_NAME_SZ];
** unsigned char ar[SQL_AR_SZ];
** unsigned char parm[SQL_PARAMETER_SZ];
**
** APIs USED :
** ADD DCS DIRECTORY ENTRY sqlegdad()
** SCAN DCS DIRECTORY sqlegdsc()
** GET DCS DIRECTORY ENTRIES sqlegdgt()
** CLOSE DCS DIRECTORY SCAN sqlegdcl()
** GET DCS DIRECTORY ENTRY sqlegdge()
** DELETE DCS DIRECTORY ENTRY sqlegdel()
**
** FUNCTIONS USED :
** 'C' COMPILER LIBRARY :
** stdio.h - printf
** string.h - fgets, strncpy
**
** DBMS LIBRARY :
** sqlenv.h - see "APIs USED" above
**
** OTHER :
** internal :
** list_dcs : Displays a directory of databases
**
** external :
** 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.
**
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlenv.h>
#include "util.h"
#ifdef DB268K
/* Need to include ASLM for 68K applications */
#include <LibraryManager.h>
#endif
#define CHECKERR(CE_STR) if (check_error (CE_STR, &sqlca) != 0) return 1;
int list_dcs (struct sqlca);
int main (void) {
int rc;
struct sqlca sqlca;
struct sql_dir_entry dcsEntry;
#ifdef DB268K
/* Before making any API calls for 68K environment,
need to initial the Library Manager */
InitLibraryManager(0,kCurrentZone,kNormalMemory);
atexit(CleanupLibraryManager);
#endif
printf ("this is sample program 'dcscat.c'\n");
strcpy(dcsEntry.comment, "this is a dcs database");
strcpy(dcsEntry.ldb, "dcsnm");
strcpy(dcsEntry.tdb, "targetnm");
strcpy(dcsEntry.ar, "arName");
strcpy(dcsEntry.parm, "");
dcsEntry.struct_id = SQL_DCS_STR_ID;
printf ("cataloging the DCS database : '%s'...\n",dcsEntry.tdb);
/*********************************\
* CATALOG DCS DATABASE API called *
\*********************************/
sqlegdad (&dcsEntry, &sqlca);
CHECKERR("cataloging the database");
printf ("database '%s' has been catalogued\n",dcsEntry.tdb);
printf ("now listing all databases...\n");
rc = list_dcs (sqlca);
printf ("now uncataloging the database that was created : '%s'\n",
dcsEntry.tdb);
/***********************************\
* UNCATALOG DCS DATABASE API called *
\***********************************/
sqlegdel (&dcsEntry, &sqlca);
CHECKERR ("uncataloging database");
printf ("list all databases [after uncataloged DCS]\n");
rc = list_dcs (sqlca);
return 0;
}
/*******************************************************************************
** Procedure : list_dcs
**
** Purpose : This procedure displays the data contained in each database
** entries by retreiving the "sql_dir_entry" structure.
**
*******************************************************************************/
int list_dcs (struct sqlca sqlca) {
short count, index;
struct sql_dir_entry *dcsPointer;
/************************************\
* OPEN DCS DIRECTORY SCAN API called *
\************************************/
sqlegdsc (&count, &sqlca);
if (sqlca.sqlcode == 1312) {
printf ("--- DCS directory is empty ---\n");
return 0;
} else {
CHECKERR("opening the database directory scan API");
} /* endif */
dcsPointer = (struct sql_dir_entry * )
malloc (count * (sizeof(struct sql_dir_entry)));
/**************************************\
* GET DCS DIRECTORY ENTRIES API called *
\**************************************/
sqlegdgt (&count, dcsPointer, &sqlca);
CHECKERR("getting dcs database entries API");
printf ("number of dcs databases : %d\n",count);
for (index = 0; index < count; index++) {
/* printing out the node information on to the screen */
printf ("Local Database Name : %.8s\n", dcsPointer[index].ldb);
printf ("Target Database Name : %.18s\n", dcsPointer[index].tdb);
printf ("App. Requestor Name : %.32s\n", dcsPointer[index].ar);
printf ("DCS parameters : %.50s\n", dcsPointer[index].parm);
printf ("Comment : %.30s\n", dcsPointer[index].comment);
printf ("DCS Release Level : 0x%x\n", dcsPointer[index].release);
printf ("\n");
} /* endfor */
if (count > 0)
/* use the first sql_dir_entry from the previous call.
Normally just the Target Database Name field would be set prior
to the call. */
{
/**************************************************\
* GET DCS DIRECTORY ENTRY FOR DATABASE API called *
\**************************************************/
sqlegdge (dcsPointer, &sqlca);
}
free (dcsPointer);
/*************************************\
* CLOSE DCS DIRECTORY SCAN API called *
\*************************************/
sqlegdcl (&sqlca);
CHECKERR("closing the node directory scan");
return 0;
}