/******************************************************************************* ** ** Source File Name = cli_info.c ** ** Licensed Materials - Property of IBM ** ** (C) COPYRIGHT International Business Machines Corp. 1999, 2000 ** All Rights Reserved. ** ** US Government Users Restricted Rights - Use, duplication or ** disclosure restricted by GSA ADP Schedule Contract with IBM Corp. ** ** ** PURPOSE : ** an example showing how to use CLIENT INFORMATION APIs in order to: ** - set a client information ** - and query a client information ** ** APIs USED : ** SET CLIENT INFORMATION sqleseti ** QUERY CLIENT INFORMATION sqleqryi ** ** STRUCTURES USED : ** sqle_client_info ** sqlca ** ** OTHER FUNCTIONS DECLARED : ** 'C' COMPILER LIBRARY : ** stdio.h - printf ** string.h - strcpy, strlen ** ** internal : ** printClientInfo ** ** external : ** check_error : Checks for SQLCODE error, and prints out any ** [in UTIL.C] related information available. ** This procedure is located in the UTIL.C file. ** ** EXTERNAL DEPENDENCIES : ** - 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 <sqlenv.h> #include "utilapi.h" #define NUM_ITEMS 2 int printClientInfo (struct sqle_client_info *); int main (void) { int rc; struct sqlca sqlca; struct sqle_client_info clientInfo[NUM_ITEMS]; char userid[SQL_USERID_SZ+1]; char wrkstnname[SQL_COMPUTERNAME_SZ+1]; unsigned short dbAliasLen; char dbAlias[SQL_ALIAS_SZ+1]; char tempUserid[SQL_USERID_SZ+1]; char tempWrkstnname[SQL_COMPUTERNAME_SZ+1]; /* Specify all the connections */ dbAliasLen=0; strcpy(dbAlias, ""); /* Initialize clientInfo */ clientInfo[0].type = SQLE_CLIENT_INFO_USERID; clientInfo[0].pValue=(char*)&userid; clientInfo[1].type = SQLE_CLIENT_INFO_WRKSTNNAME; clientInfo[1].pValue=(char*)&wrkstnname; printf ("QUERY CLIENT INFORMATION *************************************\n"); /*************************************\ * QUERY CLIENT INFORMATION API called * \************************************/ sqleqryi (dbAliasLen, dbAlias, NUM_ITEMS, &clientInfo[0], &sqlca); API_SQL_CHECK("QUERY CLIENT INFORMATION"); rc = printClientInfo(&clientInfo[0]); /* Save current client informations */ strcpy(tempUserid, clientInfo[0].pValue); strcpy(tempWrkstnname, clientInfo[1].pValue); /* Change client informations */ strcpy(clientInfo[0].pValue, "USER001"); clientInfo[0].length=strlen(clientInfo[0].pValue); strcpy(clientInfo[1].pValue, "WRKSTN001"); clientInfo[1].length=strlen(clientInfo[1].pValue); printf ("CHANGE CLIENT INFORMATION ************************************\n"); rc = printClientInfo(&clientInfo[0]); /***********************************\ * SET CLIENT INFORMATION API called * \***********************************/ sqleseti (dbAliasLen, dbAlias, NUM_ITEMS, &clientInfo[0], &sqlca); API_SQL_CHECK("CHANGE CLIENT INFORMATION"); printf ("QUERY CLIENT INFORMATION *************************************\n"); /*************************************\ * QUERY CLIENT INFORMATION API called * \*************************************/ sqleqryi (dbAliasLen, dbAlias, NUM_ITEMS, &clientInfo[0], &sqlca); API_SQL_CHECK("QUERY CLIENT"); rc = printClientInfo(&clientInfo[0]); /* Reset client informations */ strcpy(clientInfo[0].pValue, tempUserid); clientInfo[0].length=strlen(clientInfo[0].pValue); strcpy(clientInfo[1].pValue, tempWrkstnname); clientInfo[1].length=strlen(clientInfo[1].pValue); printf ("RESET CLIENT INFORMATION *************************************\n"); rc = printClientInfo(&clientInfo[0]); /***********************************\ * SET CLIENT INFORMATION API called * \***********************************/ sqleseti (dbAliasLen, dbAlias, NUM_ITEMS, &clientInfo[0], &sqlca); API_SQL_CHECK("RESET CLIENT INFORMATION"); printf ("QUERY CLIENT INFORMATION *************************************\n"); /*************************************\ * QUERY CLIENT INFORMATION API called * \*************************************/ sqleqryi (dbAliasLen, dbAlias, NUM_ITEMS, &clientInfo[0], &sqlca); API_SQL_CHECK("QUERY CLIENT"); rc = printClientInfo(&clientInfo[0]); return 0; } int printClientInfo (struct sqle_client_info * pClientInfo) { printf ("\n"); printf ("userid = %s\n", pClientInfo->pValue); pClientInfo++; printf ("workstation = %s\n", pClientInfo->pValue); printf ("\n"); return 0; }