home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
TP1.ZIP
/
UTIL.C
< prev
Wrap
C/C++ Source or Header
|
1989-08-25
|
5KB
|
183 lines
/***************************************************************************/
/* Copyright (C) 1989 Microsoft Corporation */
/* Copyright (C) 1989 Sybase, Inc. */
/* Module: UTIL.C */
/* Description: Miscellaneous routines for the SQL Server benchmark */
/* programs. */
/* */
/* Created: Trish Millines 1/24/89 */
/* Modified: Bob Muglia 4/6/89 */
/* */
/***************************************************************************/
#define INCL_BASE
#include <stdio.h>
#include <time.h>
#include <memory.h>
#include <math.h>
#include <malloc.h>
#include <sqlfront.h>
#include <sqldb.h>
#include <os2def.h>
#include <bse.h>
#define RANTYPE unsigned long
#define DBDIST far
#define M1 259200
#define IA1 7141
#define IC1 54773
#define M2 134456
#define IA2 8121
#define IC2 28411
#define M3 243000
#define IA3 4561
#define IC3 51349
#define Ran_x1 (ix1 = (IA1 * ix1 + IC1) % M1)
#define Ran_x2 (ix2 = (IA2 * ix2 + IC2) % M2)
#define Ran_x3 (ix3 = (IA3 * ix3 + IC3) % M3)
#define SHUFFLE 98
#define SHUFFLE_M1 (SHUFFLE - 1)
extern DBPROCESS far *dbproc;
/***************************************************************************/
/* FUNCTION TO GET A RANDOM NUMBER */
/***************************************************************************/
/* The C runtime random number generator only provides a 15 bit random */
/* number. This is insufficient for our purposes. This routine */
/* generates a true 32 bit random number. It returns a value between */
/* 1 and the maximum value requested. */
/***************************************************************************/
static long ix1,ix2,ix3;
static RANTYPE r[SHUFFLE];
static RANTYPE temp;
static int iff=0;
void InitRan1( int ival)
{
register int j;
if( iff == 0 || ival > 0) { //initialize on first call even
//if ival is not zero
if(ival == 0 ) ival = (int) time((time_t *)NULL);
iff = 1;
ix1 = (IC1 - (ival)) % M1; // seed to the first routine
ix2 = Ran_x1 % M2; // seed to the second routine
ix3 = Ran_x1 % M3; // seed to the third routine
for(j=1; j < SHUFFLE; j++) {
Ran_x1;
Ran_x2;
r[j] = (ix1 + ( ix2 >> 16) );
}
}
}
RANTYPE get_random(max)
long max;
{
register int j;
if( iff == 0) InitRan1(0);
Ran_x1;
Ran_x2;
Ran_x3;
j = (ix3 >> 10) % SHUFFLE;
temp = r[j];
r[j] = ( ix1 + ( ix2 << 16 ));
return ((temp % max) + 1);
}
/***************************************************************************/
/* FUNCTION TO GET MAXIMUM VALUE OF A COLUMN */
/***************************************************************************/
DBINT Get_max_value(thisproc,table,column)
DBPROCESS far *thisproc;
char table[],column[];
{
char cmd[100];
DBINT max;
int rowinfo;
/* */
/* Assemble the command and send it */
/* */
sprintf(cmd,"select max(%s) from %s",column,table);
dbcmd(thisproc,(char DBDIST *)cmd);
if(dbsqlexec(thisproc) == FAIL)
return(-1);
/* */
/* Get the results */
/* */
if((dbresults(thisproc)) == SUCCEED)
{
dbbind(thisproc, 1, INTBIND, (DBINT) 0, (BYTE *)&max);
while((dbnextrow(thisproc)) != NO_MORE_ROWS)
return(max);
}
else
return(-1);
}
/***************************************************************************/
/* FUNCTION TO GET THE RESULTS */
/***************************************************************************/
int Get_results(dbproc)
DBPROCESS far *dbproc;
{
while(dbresults(dbproc) != NO_MORE_RESULTS)
{
if(DBROWS(dbproc)) /* Return any rows? */
while(dbnextrow(dbproc) != NO_MORE_ROWS);
}
}
#ifdef DBMSOS2
/***************************************************************************/
/* FUNCTION TO DELAY N SECONDS */
/***************************************************************************/
void Wait(target)
long target;
{
DosSleep(target * 1000);
}
#endif
/***************************************************************************/
/* FUNCTION TO PARSE A BUFFER BASED ON A DELIMETER */
/***************************************************************************/
int parsebuff(buffin,start,delim,buffout)
char buffin[];
int start;
char delim;
char buffout[];
{
int j = 0;
int i = start;
while(buffin[i] != delim && buffin[i] != '\0' && buffin[i] != '\n')
{
buffout[j] = buffin[i];
++i;
++j;
}
buffout[j] = '\0';
return(i+1);
}