home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / TP1.ZIP / UTIL.C < prev   
C/C++ Source or Header  |  1989-08-25  |  5KB  |  183 lines

  1. /***************************************************************************/
  2. /* Copyright (C) 1989 Microsoft Corporation                                */
  3. /* Copyright (C) 1989 Sybase, Inc.                                         */
  4. /* Module:  UTIL.C                                                         */
  5. /* Description:  Miscellaneous routines for the SQL Server benchmark       */
  6. /*               programs.                                                 */
  7. /*                                                                         */
  8. /* Created:   Trish Millines 1/24/89                                       */
  9. /* Modified:  Bob Muglia 4/6/89                                            */
  10. /*                                                                         */
  11. /***************************************************************************/
  12. #define INCL_BASE
  13. #include <stdio.h>
  14. #include <time.h>
  15. #include <memory.h>
  16. #include <math.h>
  17. #include <malloc.h>
  18. #include <sqlfront.h>
  19. #include <sqldb.h>
  20. #include <os2def.h>
  21. #include <bse.h>
  22.  
  23. #define RANTYPE unsigned long
  24.  
  25. #define DBDIST far
  26.  
  27. #define M1 259200
  28. #define IA1 7141
  29. #define IC1 54773
  30.  
  31. #define M2 134456
  32. #define IA2 8121
  33. #define IC2 28411
  34.  
  35. #define M3 243000
  36. #define IA3 4561
  37. #define IC3 51349
  38.  
  39. #define Ran_x1 (ix1 = (IA1 * ix1 + IC1) % M1)
  40. #define Ran_x2 (ix2 = (IA2 * ix2 + IC2) % M2)
  41. #define Ran_x3 (ix3 = (IA3 * ix3 + IC3) % M3)
  42.  
  43. #define SHUFFLE 98
  44. #define SHUFFLE_M1 (SHUFFLE - 1)
  45.  
  46. extern DBPROCESS far *dbproc;
  47.  
  48.  
  49. /***************************************************************************/
  50. /*                   FUNCTION TO GET A RANDOM NUMBER                       */
  51. /***************************************************************************/
  52. /*   The C runtime random number generator only provides a 15 bit random   */
  53. /*   number.  This is insufficient for our purposes.  This routine         */
  54. /*   generates a true 32 bit random number.  It returns a value between    */
  55. /*   1 and the maximum value requested.                                    */
  56. /***************************************************************************/
  57.  
  58. static long ix1,ix2,ix3;
  59. static RANTYPE r[SHUFFLE];
  60.  
  61. static RANTYPE temp;
  62. static int iff=0;
  63.  
  64. void InitRan1( int ival)
  65. {
  66.     register int j;
  67.  
  68.     if( iff == 0 || ival > 0) { //initialize on first call even
  69.                                 //if ival is not zero
  70.         if(ival == 0 ) ival = (int) time((time_t *)NULL);
  71.         iff = 1;
  72.         ix1 = (IC1 - (ival)) % M1;  // seed to the first routine
  73.  
  74.         ix2 = Ran_x1 % M2;              // seed to the second routine
  75.  
  76.         ix3 = Ran_x1 % M3;              // seed to the third routine
  77.  
  78.         for(j=1; j < SHUFFLE; j++) {
  79.             Ran_x1;
  80.             Ran_x2;
  81.             r[j] = (ix1 + ( ix2 >> 16) );
  82.             }
  83.         }
  84. }
  85.  
  86. RANTYPE get_random(max)
  87. long max;
  88. {
  89.     register int j;
  90.     if( iff == 0) InitRan1(0);
  91.     Ran_x1;
  92.     Ran_x2;
  93.     Ran_x3;
  94.  
  95.     j = (ix3 >> 10) % SHUFFLE;
  96.  
  97.     temp = r[j];
  98.  
  99.     r[j] = ( ix1 + ( ix2 << 16 ));
  100.     return ((temp % max) + 1);
  101. }
  102.  
  103. /***************************************************************************/
  104. /*                   FUNCTION TO GET MAXIMUM VALUE OF A COLUMN             */
  105. /***************************************************************************/
  106. DBINT Get_max_value(thisproc,table,column)
  107. DBPROCESS far *thisproc;
  108. char table[],column[];
  109. {
  110.  char cmd[100];
  111.  DBINT max;
  112.  int rowinfo;
  113.  
  114. /* */
  115. /* Assemble the command and send it */
  116. /* */
  117.  
  118.  sprintf(cmd,"select max(%s) from %s",column,table);
  119.  dbcmd(thisproc,(char DBDIST *)cmd);
  120.  if(dbsqlexec(thisproc) == FAIL)
  121.    return(-1);
  122.  
  123. /* */
  124. /* Get the results */
  125. /* */
  126.  
  127.  if((dbresults(thisproc)) == SUCCEED)
  128.   {
  129.    dbbind(thisproc, 1, INTBIND, (DBINT) 0, (BYTE *)&max);
  130.    while((dbnextrow(thisproc)) != NO_MORE_ROWS)
  131.      return(max);
  132.   }
  133.  else
  134.   return(-1);
  135. }
  136.  
  137. /***************************************************************************/
  138. /*                      FUNCTION TO GET THE RESULTS                        */
  139. /***************************************************************************/
  140.  
  141. int Get_results(dbproc)        
  142. DBPROCESS far *dbproc;
  143. {
  144.  while(dbresults(dbproc) != NO_MORE_RESULTS)
  145.   {
  146.    if(DBROWS(dbproc))        /* Return any rows? */
  147.      while(dbnextrow(dbproc) != NO_MORE_ROWS);
  148.   }
  149. }
  150.  
  151. #ifdef DBMSOS2
  152. /***************************************************************************/
  153. /*                      FUNCTION TO DELAY N SECONDS                        */
  154. /***************************************************************************/
  155. void Wait(target)
  156. long target;
  157. {
  158.  DosSleep(target * 1000);
  159. }
  160. #endif
  161.  
  162. /***************************************************************************/
  163. /*          FUNCTION TO PARSE A BUFFER BASED ON A DELIMETER                */
  164. /***************************************************************************/
  165. int parsebuff(buffin,start,delim,buffout)
  166. char buffin[];
  167. int start;
  168. char delim;
  169. char buffout[];
  170. {
  171.  int j = 0;
  172.  int i = start;
  173.  
  174.  while(buffin[i] != delim && buffin[i] != '\0' && buffin[i] != '\n')
  175.   {
  176.    buffout[j] = buffin[i];
  177.    ++i;
  178.    ++j;
  179.   }
  180.  buffout[j] = '\0';
  181.  return(i+1);
  182. }
  183.