/******************************************************************************* ** ** Source File Name = dbcmt.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 ** change the comment for a database. ** ** STRUCTURES USED : ** sqledinfo ** sqlca ** ** APIs USED : ** CHANGE DATABASE COMMENT sqledcgd ** INSTALL SIGNAL HANDLER sqleisig ** OPEN DATABASE DIRECTORY SCAN sqledosd ** GET NEXT DATABASE ENTRY sqledgne ** CLOSE DATABASE DIRECTORY SCAN sqledcls ** ** ** FUNCTIONS DECLARED : ** 'C' COMPILER LIBRARY : ** stdio.h - printf ** string.h - strncmp ** ** DBMS LIBRARY : ** sqlenv.h - see "APIs USED" above ** ** OTHER : ** 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 CHECK_ERR(CE_STR) if (check_error (CE_STR, &sqlca) != 0) return 1; int main (void) { struct sqlca sqlca; unsigned short idx; unsigned short dbHandle; unsigned short dbCount; struct sqledinfo *dbBuffer; #ifdef DB268K /* Before making any API calls for 68K environment, need to initial the Library Manager */ InitLibraryManager(0,kCurrentZone,kNormalMemory); atexit(CleanupLibraryManager); #endif /*************************************\ * INSTALL SIGNAL HANDLER API called * \*************************************/ sqleisig( &sqlca); /*****************************************\ * OPEN DATABASE DIRECTORY SCAN API called * \*****************************************/ sqledosd ("\0", &dbHandle, &dbCount, &sqlca); CHECK_ERR("opening the database directory scan API"); printf ("opened directory scan\n"); for (idx = 0; idx < dbCount; idx++) { /************************************\ * GET NEXT DATABASE ENTRY API called * \************************************/ sqledgne (dbHandle, &dbBuffer, &sqlca); CHECK_ERR("getting next database entry API"); strncmp("SAMPLE ",dbBuffer->alias,SQL_ALIAS_SZ); if (strncmp("SAMPLE ",dbBuffer->alias,SQL_ALIAS_SZ) == 0) { printf ("alias found\n"); /*****************************\ * CHANGE DATABASE COMMENT API * \*****************************/ sqledcgd ("SAMPLE", "", "the new comment for sample", &sqlca); CHECK_ERR("changing comment"); printf ("CHANGE DATABASE COMMENT successful\n"); /*********************************\ * RESET DATABASE COMMENT TO BLANK * \*********************************/ sqledcgd ("SAMPLE", "", "", &sqlca); CHECK_ERR("reset comment"); break; } /* endif */ } /* endfor */ /******************************************\ * CLOSE DATABASE DIRECTORY SCAN API called * \******************************************/ sqledcls (dbHandle, &sqlca); CHECK_ERR("closing the node directory scan"); return 0; }