home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / static1.zip / static1.sqc
Text File  |  2002-11-18  |  3KB  |  88 lines

  1. /******************************************************************************
  2. **
  3. ** Source File Name = static.sqc  
  4. **
  5. ** Licensed Materials - Property of IBM
  6. **
  7. ** (C) COPYRIGHT International Business Machines Corp. 1995, 1999 
  8. ** All Rights Reserved.
  9. **
  10. ** US Government Users Restricted Rights - Use, duplication or
  11. ** disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  12. **
  13. **
  14. ** PURPOSE: This sample program demonstrates the use of static SQL.
  15. **          It will output the entry in the FIRSTNME column where
  16. **          the entry in the LASTNAME column equals "JOHNSON".
  17. **          Otherwise, an error message is printed.
  18. **
  19. **    EXTERNAL DEPENDENCIES :
  20. **       - Ensure existence of database for precompile purposes.
  21. **       - Precompile with the SQL precompiler (PREP in DB2)
  22. **       - Bind to a database (BIND in DB2)
  23. **       - Compile and link with the compiler supported on your platform.
  24. **
  25. ** For more information about these samples see the README file.
  26. **
  27. ** For more information on programming in C, see the:
  28. **   -  "Programming in C and C++" section of the Application Development Guide
  29. ** For more information on building C applications, see the:
  30. **   -  "Building C Applications" section of the Application Building Guide.
  31. **
  32. ** For more information on the SQL language see the SQL Reference.
  33. **
  34. *******************************************************************************/
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include "utilemb.h"
  39.  
  40.  
  41. EXEC SQL INCLUDE SQLCA;  /* :rk.1:erk. */
  42.  
  43.  
  44. int main(int argc, char *argv[])
  45. {   int  rc = 0; 
  46.  
  47.     char dbAlias[15] ;
  48.     char user[15] ; 
  49.     char pswd[15] ; 
  50.  
  51.     EXEC SQL BEGIN DECLARE SECTION; /* :rk.2:erk. */
  52.         char firstname[13];
  53.     EXEC SQL END DECLARE SECTION;
  54.  
  55.     /* checks the command line arguments */
  56.     rc = CmdLineArgsCheck1( argc, argv, dbAlias, user, pswd );
  57.     if ( rc != 0 ) return( rc ) ;
  58.  
  59.     printf("\n\nSample C program: STATIC\n");
  60.  
  61.     /* initialize the embedded application */
  62.     rc = EmbAppInit( dbAlias, user, pswd);
  63.     if ( rc != 0 ) return( rc ) ;
  64.  
  65.     EXEC SQL SELECT FIRSTNME INTO :firstname  /* :rk.4:erk. */
  66.             FROM employee
  67.             WHERE LASTNAME = 'JOHNSON';
  68.     EMB_SQL_CHECK("SELECT statement");  /* :rk.5:erk. */
  69.  
  70.     printf( "First name = %s\n", firstname );
  71.  
  72.     /* pmr28801 start */
  73.  
  74.     EXEC SQL SELECT FIRSTNME INTO :firstname
  75.          FROM employee
  76.          WHERE LASTNAME = 'JOHNSON' 
  77.         UNION SELECT FIRSTNME FROM employee WHERE LASTNAME = 'JOHNSON';
  78.     EMB_SQL_CHECK("pmr28801 no.1");
  79.  
  80.     /* pmr28801 end */
  81.    
  82.     /* terminate the embedded application */
  83.     rc = EmbAppTerm( dbAlias);
  84.     return( rc ) ;
  85. }
  86. /* end of program : STATIC.SQC */
  87.  
  88.