#ifdef RCSID static char *RCSid = "$Header: /og/v2/go/RCS/testexit.pc,v 1.2 1993/11/18 23:43:14 jrhee Exp $ "; #endif /* RCSID */ /* NAME testexit.c - TEST user EXIT DESCRIPTION This file contains a PCC user exit that exercises EXEC TOOLS functionality. PUBLIC FUNCTION(S) testexit - TEST user EXIT PRIVATE FUNCTION(S) None. RETURNS See individual functions. NOTES None. MODIFIED (MM/DD/YY) jrhee 04/02/93 - Creation */ /* Define some local variables to be used in the testexit routine below. */ EXEC SQL BEGIN DECLARE SECTION; int ihv1; int ihv2; int ihv3; char chv1[60]; char chv2[60]; char chv3[60]; char dhv1[60]; char dhv2[60]; char dhv3[60]; char my_context[60]; char my_context2[60]; char my_context3[60]; char *pctx; char *pctx2; EXEC SQL END DECLARE SECTION; EXEC SQL INCLUDE SQLCA; /* testexit: --------- This is a PCC user exit that is meant to demonstrate on a very simple level the interaction between a PCC user exit and an Oracle Graphics document. It demonstrates the following functionality: * setting named application contexts * getting named application contexts * setting bind variable values * getting bind variable values * sending messages The only assumptions it makes are that it is called from an Oracle Graphics document having the following bind variables: bvnum1 NUMBER bvnum2 NUMBER bvchar1 CHAR bvchar2 CHAR bvdate1 DATE bvdate2 DATE The routine is divided into subsections with each subsection commented fairly thoroughly. Please reference the Oracle Graphics Reference Manual for additional information. */ int testexit(cmdlin, cmdlinl) char *cmdlin; /* command line */ int *cmdlinl; /* command line length */ { /* Print out the command line and its length */ #ifdef GODEBUG printf("Command line: %s\n", cmdlin); printf("Command line length: %d\n\n", *cmdlinl); #endif /********************************************************************* * The following section demonstrates setting and getting named * * application contexts. * ********************************************************************* */ /* Set the application context named 'appctx_1' to contain the value of the pointer 'my_context'. Named application contexts are just ways of stashing away named pointer entities in an Oracle Graphics document and then being able to retrieve them later. So, here I am just stashing away the value of the pointer 'my_context' under the name 'appctx_1'. */ strcpy(my_context ,"application context 1"); EXEC TOOLS SET CONTEXT :my_context BY appctx_1; /* Do similar operation for 'my_context2' pointer and name it 'appctx_2'. */ strcpy(my_context2, "application context 2"); EXEC TOOLS SET CONTEXT :my_context2 BY appctx_2; /* Now, I want to reset the value of the pointer named by 'appctx_1' to be the value of the pointer 'my_context3'. */ strcpy(my_context3, "application context 1 reset"); EXEC TOOLS SET CONTEXT :my_context3 BY appctx_1; /* Now, let's retrieve the pointers that were stored away under the names 'appctx_1' and 'appctx_2' and let's put the pointer values into the local variables 'pctx' and 'pctx2'. */ EXEC TOOLS GET CONTEXT appctx_1 INTO :pctx; EXEC TOOLS GET CONTEXT appctx_2 INTO :pctx2; /* Print out the retrieved context values (the context pointers were just char pointers so we can just print out the string values appropriately) to make sure we got back the right values */ #ifdef GODEBUG printf("App Context 1 (expecting 'application context 1 reset'): '%s'\n", pctx); printf("App Context 2 (expecting 'application context 2'): '%s'\n", pctx2); #endif /********************************************************************* * The next section demonstrates setting and getting values * * of bind variables. * ********************************************************************* */ /* First, we set the values of the NUMBER bind variables 'bvnum1' and 'bvnum2' (which reside in the calling Oracle Graphics document) to be the values 29 and 39 respectively using a local variable for the value 29 and a constant for the value 39. */ ihv1 = 29; EXEC TOOLS SET bvnum1, bvnum2 VALUES (:ihv1, 39); /* Now, let's get the values of 'bvnum1' and 'bvnum2' to make sure they were set correctly. We put the values into the local variables 'ihv2' and 'ihv3'. */ EXEC TOOLS GET bvnum1, bvnum2 INTO :ihv2, :ihv3; /* Print out the values of 'ihv2' and 'ihv3' to make sure that they were successfully retrieved */ #ifdef GODEBUG printf("Numeric bind variable 1 (expecting '29'): '%d'\n", ihv2); printf("Numeric bind variable 2 (expecting '39'): '%d'\n", ihv3); #endif /* Next, let's set the values of the CHAR bind variables 'bvchar1' and 'bvchar2' in a similar manner to which we set the 'bvnum1' and 'bvnum2' bind variables above (i.e., use one local variable and one constant as the value mechanism) */ strcpy(chv1, "char bind variable 1"); EXEC TOOLS SET bvchar1, bvchar2 VALUES (:chv1, 'char bind variable 2'); /* Retrieve 'bvchar1' and 'bvchar2' into the local variables 'chv2' and 'chv3'. */ EXEC TOOLS GET bvchar1, bvchar2 INTO :chv2, :chv3; /* Now, print out 'chv2' and 'chv3' to make sure they were retrieved correctly. */ #ifdef GODEBUG printf("Char bind variable 1 (expecting 'char bind variable 1'): '%s'\n", chv2); printf("Char bind variable 2 (expecting 'char bind variable 2'): '%s'\n", chv3); #endif /* Do set operations for the DATE bind variables 'bvdate1' and 'bvdate2'. */ strcpy(dhv1, "05-NOV-92"); EXEC TOOLS SET bvdate1, bvdate2 VALUES (:dhv1, '01-JAN-90'); /* Retrieve the values back into local variables 'dhv2' and 'dhv3'. */ EXEC TOOLS GET bvdate1, bvdate2 INTO :dhv2, :dhv3; /* Print out 'dhv2' and 'dhv3' to make sure they were retrieved correctly. */ #ifdef GODEBUG printf("Date bind variable 1 (expecting '05-NOV-92'): '%s'\n", dhv2); printf("Date bind variable 2 (expecting '01-JAN-90'): '%s'\n", dhv3); #endif /********************************************************************* * The last section demonstrates sending messages back to Oracle * * Graphics. * ********************************************************************* */ /* Send a message with no numeric code (the message gets displayed in an alert in Oracle Graphics) */ EXEC TOOLS MESSAGE 'First message'; /* Now, try sending a message with a numeric error code of 101 (again, the message with its associated numeric code will get displayed in an alert in Oracle Graphics) */ EXEC TOOLS MESSAGE 'Second message' 101; /* Return success */ return(0); } /* end testexit */