home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Product / Product.zip / DBDEMO.ZIP / DEMOFLS.ZIP / ARIS.SQC < prev    next >
Text File  |  1991-06-03  |  4KB  |  107 lines

  1. /************************************************************************/
  2. /* DATABASE PERFORMANCE CONCEPTS AND TECHNIQUES DEMONSTRATION PROGRAM   */
  3. /* MODULE: APPLICATION REMOTE PROCEDURE (SERVER PART)                   */
  4. /* source file: ARIS.SQC                                                */
  5. /************************************************************************/
  6. /*****************************************************************************/
  7. /*Purpose:  This module is the SERVER side of the stored procedure. It       */
  8. /*          contains the functions get_total and is stored as a DLL on server*/
  9. /*Support:  This functions could be compiled into a dynamic library using its*/
  10. /*          own make file - ARIS.                                            */
  11. /*          It needs a DEF file(ARIS.DEF) to be compiled into a DLL          */
  12. /*Input  :  vardata - NULL                                                   */
  13. /*          input_sqlda - NULL                                               */
  14. /*          output_sqlda- out sqlda, contains the median balance value       */
  15. /*          sqlcaptr    - pointer of sqlca                                   */
  16. /*output :                                                                   */
  17. /*          sqlcaptr    - sql code                                           */
  18. /*****************************************************************************/
  19.  
  20. /************************************************************************/
  21. /* HEADER FILES - SYSTEM , LANGUAGE AND SQL HEADER                      */
  22. /************************************************************************/
  23. #include <memory.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "sql.h"                        /* defines SQLZ_DISCONNECT_PROC     */
  27. #include "sqlutil.h"                    /* defines sqlchar structure        */
  28. /************************************************************************/
  29. /*     FUNCTION PROTOTYPES                                              */
  30. /************************************************************************/
  31. void get_error(char *);
  32.  
  33. EXEC SQL INCLUDE SQLCA;
  34. EXEC SQL INCLUDE SQLDA;                 /* defines sqlda structure          */
  35.  
  36. /*************************************************/
  37. /*  SQL HOST VARIABLE DECLARATIONS               */
  38. /*************************************************/
  39. EXEC SQL BEGIN DECLARE SECTION;
  40. short int num_accounts;
  41. EXEC SQL END DECLARE SECTION;
  42.  
  43. short int retcode;
  44.  
  45. /************************************************************************/
  46. /* FUNCTION get_total                                                   */
  47. /************************************************************************/
  48. extern int far pascal get_total(
  49. struct sqlchar *vardata,
  50. struct sqlda *insqlda,
  51. struct sqlda *outsqlda,
  52. struct sqlca *sqlcaptr)
  53.  
  54. {
  55.  
  56.  
  57. /* UNPACKED INPUT SQLDA */
  58.  
  59.   char error_from[20];
  60.   short cur_row;
  61.  
  62.   EXEC SQL BEGIN DECLARE SECTION;
  63.      double balance;
  64.      short num_rows;
  65.   EXEC SQL END DECLARE SECTION;
  66.  
  67.   EXEC SQL WHENEVER SQLERROR GO TO error;
  68.   EXEC SQL WHENEVER NOT FOUND GO TO ext;
  69.  
  70.    retcode = 0;
  71.    sqlcaptr->sqlcode = 0;
  72. /* update customer */
  73.      strcpy(error_from,"select count * ");
  74.      EXEC SQL SELECT COUNT(*)
  75.          INTO :num_rows
  76.          FROM BMCHUGH.CHECKING;
  77.  
  78. /****** DECLARE CURSOR *********/
  79.      EXEC SQL DECLARE CBLOCK CURSOR FOR
  80.         SELECT C_ENDBAL FROM BMCHUGH.CHECKING
  81.         ORDER BY C_ENDBAL;
  82.  
  83. /****** OPEN CURSOR *********/
  84.     EXEC SQL OPEN CBLOCK;
  85.     cur_row = 1;
  86.  
  87. /****** FETCH num_rows/2 ROWS  *********/
  88.     while ((sqlca.sqlcode == 0) && (cur_row <= num_rows/2) ) {
  89.  
  90.        cur_row++;
  91.  
  92.        EXEC SQL FETCH CBLOCK
  93.        INTO :balance;
  94.     }/*end while more rows */
  95.  
  96. /****** CLOSE CURSOR *********/
  97.     EXEC SQL CLOSE CBLOCK;
  98.  
  99.     memcpy(outsqlda->sqlvar[0].sqldata,  &balance, sizeof(double));
  100.     memcpy(sqlcaptr, &sqlca, sizeof(sqlca));
  101.  error:
  102.  ext:
  103.  
  104.    return(SQLZ_DISCONNECT_PROC);
  105. }/* end get_total*/
  106. /*****************************************************************************/
  107.