/****************************************************************************** ** ** Source File Name = static.sqc 1.4 ** ** 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 sample program demonstrates the use of static SQL. ** It will output the entry in the FIRSTNME column where ** the entry in the LASTNAME column equals "JOHNSON". ** Otherwise, an error message is printed. ** ** An external function "check_error" is contained in the file "util.c" ** which must be compiled along with this file. ** ** EXTERNAL DEPENDENCIES : ** - Ensure existence of database for precompile purposes. ** - Precompile with the SQL precompiler (PREP in DB2) ** - Bind to a database (BIND in DB2) ** - 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 "util.h" #ifdef DB268K /* Need to include ASLM for 68K applications */ #include <LibraryManager.h> #endif EXEC SQL INCLUDE SQLCA; /* :rk.1:erk. */ #define CHECKERR(CE_STR) if (check_error (CE_STR, &sqlca) != 0) return 1; int main(int argc, char *argv[]) { EXEC SQL BEGIN DECLARE SECTION; /* :rk.2:erk. */ char firstname[13]; char userid[9]; char passwd[19]; EXEC SQL END DECLARE SECTION; #ifdef DB268K /* Before making any API calls for 68K environment, need to initial the Library Manager */ InitLibraryManager(0,kCurrentZone,kNormalMemory); atexit(CleanupLibraryManager); #endif printf( "Sample C program: STATIC\n" ); if (argc == 1) { EXEC SQL CONNECT TO sample; CHECKERR ("CONNECT TO SAMPLE"); } else if (argc == 3) { strcpy (userid, argv[1]); strcpy (passwd, argv[2]); EXEC SQL CONNECT TO sample USER :userid USING :passwd; /* :rk.3:erk. */ CHECKERR ("CONNECT TO SAMPLE"); } else { printf ("\nUSAGE: static [userid passwd]\n\n"); return 1; } /* endif */ EXEC SQL SELECT FIRSTNME INTO :firstname /* :rk.4:erk. */ FROM employee WHERE LASTNAME = 'JOHNSON'; CHECKERR ("SELECT statement"); /* :rk.5:erk. */ printf( "First name = %s\n", firstname ); EXEC SQL CONNECT RESET; /* :rk.6:erk. */ CHECKERR ("CONNECT RESET"); return 0; } /* end of program : static.sqc */