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

  1. /************************************************************************/
  2. /* DATABASE PERFORMANCE CONCEPTS AND TECHNIQUES DEMONSTRATION PROGRAM   */
  3. /* MODULE: APPLICATION REMOTE INTERFACE (REQUESTER PART)                 */
  4. /* source file: ARI.SQC                                                 */
  5. /************************************************************************/
  6.  
  7.  
  8. /************************************************************************/
  9. /* HEADER FILES - SYSTEM , LANGUAGE AND SQL HEADER                      */
  10. /************************************************************************/
  11. #include <sqlda.h>
  12. #include <malloc.h>
  13. /************************************************************************/
  14. /* HEADER FILES - USER DEFINED                                          */
  15. /************************************************************************/
  16. #include "db.h"
  17.  
  18. /************************************************************************/
  19. /*     FUNCTION PROTOTYPES                                              */
  20. /************************************************************************/
  21. extern int far pascal get_total( struct sqlchar * , struct sqlda * ,
  22.                                  struct sqlda * , struct sqlca *);
  23.  
  24. struct timeb dbeg, dend;
  25. double qtime_ari, qtime_noari;
  26. double q1avg=0.0, q2avg=0.0;
  27.  
  28. /************************************************************************/
  29. /* FUNCTION  arir()                                                     */
  30. /************************************************************************/
  31. short far arir()
  32. {
  33.    long rc;
  34.    short i;
  35.    double med_balance;
  36.    struct sqlchar *vardata;  // parameter to sqleproc(), not used this time
  37.    struct sqlda *in_sqlda;   // parameter to sqleproc(), not used this time
  38.    struct sqlda *out_sqlda;  // aris() returns the median value in this
  39.  
  40.    qtime_ari = 0.0;
  41.    med_balance = 0;                        /* assume no error */
  42.  
  43.    vardata = NULL;
  44.  
  45. /* INITIALIZE OUT SQLDA */
  46.    out_sqlda =(struct sqlda *) malloc(SQLDASIZE(1));
  47.    out_sqlda->sqln = 1;
  48.    out_sqlda->sqld = 1;
  49.    out_sqlda->sqlvar[0].sqltype =  SQL_TYP_FLOAT;
  50.    out_sqlda->sqlvar[0].sqlind  = NULL;
  51.  
  52. // make the data pointer point to med_balance
  53. // this is where the value will be returned
  54.    out_sqlda->sqlvar[0].sqldata = (unsigned char *)&med_balance;
  55.    out_sqlda->sqlvar[0].sqllen  = sizeof(double);
  56.  
  57.  
  58. /* INVOKE SERVER, THE STORE PROCEDURE */
  59.       printf(" before calling remote procedure\n");
  60.  
  61.         ftime (&dbeg);
  62.       sqleproc("aris.dll\\get_total", NULL, NULL, out_sqlda, &sqlca);
  63.         ftime(&dend);
  64.         qtime_ari += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
  65.         rc = sqlca.sqlcode;
  66.  if (rc >= 0L)  // if no error
  67.    return(0);
  68. // if SQL error
  69.  error_sql = sqlca.sqlcode;
  70.  return(-1);
  71. }
  72.  
  73. /************************************************************************/
  74. /* FUNCTION  noari()                                                    */
  75. /************************************************************************/
  76.  
  77. short far noari()
  78. {
  79. /*************************************************/
  80. /*  SQL HOST VARIABLE DECLARATIONS               */
  81. /*************************************************/
  82.   EXEC SQL BEGIN DECLARE SECTION;
  83.      double balance;
  84.      short num_rows;
  85.   EXEC SQL END DECLARE SECTION;
  86.  
  87. struct timeb dbeg, dend;
  88.    long rc;
  89.    short cur_row;
  90.    short i;
  91.    double med_balance;
  92.  
  93.   EXEC SQL WHENEVER SQLERROR GO TO error;
  94.   EXEC SQL WHENEVER NOT FOUND GO TO ext;
  95.  
  96.    qtime_noari = 0.0;
  97.    med_balance = 0;                        /* assume no error */
  98.  
  99.    rc = 0;
  100.  
  101. /* INVOKE SERVER, THE STORE PROCEDURE */
  102.  
  103.      ftime (&dbeg);
  104.      EXEC SQL SELECT COUNT(*)
  105.          INTO :num_rows
  106.          FROM BMCHUGH.CHECKING;
  107.      ftime(&dend);
  108.      qtime_noari += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
  109.      printf("\ntotal number of rows = %d", num_rows);
  110.  
  111. /****** DECLARE CURSOR *********/
  112.      ftime (&dbeg);
  113.      EXEC SQL DECLARE CBLOCK CURSOR FOR
  114.         SELECT C_ENDBAL FROM BMCHUGH.CHECKING
  115.         ORDER BY C_ENDBAL;
  116.      ftime(&dend);
  117.      qtime_noari += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
  118.  
  119. /****** OPEN CURSOR *********/
  120.      ftime (&dbeg);
  121.     EXEC SQL OPEN CBLOCK;
  122.      ftime(&dend);
  123.      qtime_noari += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
  124.     cur_row = 1;
  125.  
  126. /****** FETCH num_rows/2 ROWS  *********/
  127.     while ((sqlca.sqlcode == 0) && (cur_row <= num_rows/2) ) {
  128.  
  129.        cur_row++;
  130.  
  131.      ftime (&dbeg);
  132.        EXEC SQL FETCH CBLOCK
  133.        INTO :balance;
  134.      ftime(&dend);
  135.      qtime_noari += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
  136.  
  137.        printf("%7.3f\n", balance);
  138.  
  139.     }/*end while more rows */
  140.     printf("\nmedian balance = %7.3f",balance);
  141.       rc = sqlca.sqlcode;
  142. /****** CLOSE CURSOR *********/
  143.      ftime (&dbeg);
  144.     EXEC SQL CLOSE CBLOCK;
  145.      ftime(&dend);
  146.      qtime_noari += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
  147.  
  148.  
  149. ext:
  150.    return(0);
  151. error:
  152.   error_sql = sqlca.sqlcode;  // copy the sql code into external variable
  153.                               // to be printed on user screen by dbdemo
  154.    return(-1);
  155.  
  156. }/* end noari */
  157.  
  158. /************************************************************************/
  159. /* FUNCTION  ari()                                                      */
  160. /* This function is called by DBDEMO and in turn calls noari() and arir()*/
  161. /* num_run times.                                                       */
  162. /* gets the timing info from  variables qtime_ari and                   */
  163. /* qtime_noari  and applies the averaging logic, depending upon         */
  164. /* user entered variable num_runs.                                      */
  165. /* i.e. if num_runs = 1 then q1avg = qtime_ari and q2avg=qtime_noari    */
  166. /* otherwise, it disregards the first value and averages the rest       */
  167. /************************************************************************/
  168. /************************************************************************/
  169. ari()
  170. {
  171.    short i;
  172.     // SET THE NUMBER OF DEMOS FOR THIS SECTION 1 OR 2.. 2 IS MAX!!!!
  173.        Timetext[0].test_num = 1;
  174.     q1avg = 0.0;
  175.  
  176.   // call the function arir (which calls aris() the DLL) num_runs time
  177.     for (i=1; i<=num_runs; i++)
  178.        {
  179.         if (arir())
  180.            return(3);
  181.        if (i!=1)
  182.            q1avg = q1avg + qtime_ari;
  183.        }/* end for */
  184.        if (num_runs == 1)
  185.            q1avg = qtime_ari;
  186.        else
  187.            q1avg = q1avg / (num_runs-1);
  188.  
  189.     // FILL UP TIMETEXT STRUCTURE FOR DEMO 1
  190.        strcpy(Timetext[0].demoname,"Ari           ");
  191.        Timetext[0].demotime = qtime_ari;
  192.        Timetext[0].rows = 800;
  193.  
  194.   // now call the function noari()  num_runs time
  195.     for (i=1; i<=num_runs; i++)
  196.        {
  197.          if (noari())
  198.             return(3);  // if error
  199.        if (i!=1)
  200.            q2avg = q2avg + qtime_noari;
  201.        }/* end for */
  202.        if (num_runs == 1)
  203.            q2avg = qtime_noari;
  204.        else
  205.            q2avg = q2avg / (num_runs-1);
  206.  
  207.     // FILL UP TIMETEXT STRUCTURE FOR DEMO 2
  208.        strcpy(Timetext[1].demoname,"No Ari        ");
  209.        Timetext[1].demotime = qtime_noari;
  210.        Timetext[1].rows = 800;
  211.  
  212.     return(0);
  213. }/* end ari */
  214.