home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: Product
/
Product.zip
/
DBDEMO.ZIP
/
DEMOFLS.ZIP
/
ARI.SQC
< prev
next >
Wrap
Text File
|
1991-06-30
|
7KB
|
214 lines
/************************************************************************/
/* DATABASE PERFORMANCE CONCEPTS AND TECHNIQUES DEMONSTRATION PROGRAM */
/* MODULE: APPLICATION REMOTE INTERFACE (REQUESTER PART) */
/* source file: ARI.SQC */
/************************************************************************/
/************************************************************************/
/* HEADER FILES - SYSTEM , LANGUAGE AND SQL HEADER */
/************************************************************************/
#include <sqlda.h>
#include <malloc.h>
/************************************************************************/
/* HEADER FILES - USER DEFINED */
/************************************************************************/
#include "db.h"
/************************************************************************/
/* FUNCTION PROTOTYPES */
/************************************************************************/
extern int far pascal get_total( struct sqlchar * , struct sqlda * ,
struct sqlda * , struct sqlca *);
struct timeb dbeg, dend;
double qtime_ari, qtime_noari;
double q1avg=0.0, q2avg=0.0;
/************************************************************************/
/* FUNCTION arir() */
/************************************************************************/
short far arir()
{
long rc;
short i;
double med_balance;
struct sqlchar *vardata; // parameter to sqleproc(), not used this time
struct sqlda *in_sqlda; // parameter to sqleproc(), not used this time
struct sqlda *out_sqlda; // aris() returns the median value in this
qtime_ari = 0.0;
med_balance = 0; /* assume no error */
vardata = NULL;
/* INITIALIZE OUT SQLDA */
out_sqlda =(struct sqlda *) malloc(SQLDASIZE(1));
out_sqlda->sqln = 1;
out_sqlda->sqld = 1;
out_sqlda->sqlvar[0].sqltype = SQL_TYP_FLOAT;
out_sqlda->sqlvar[0].sqlind = NULL;
// make the data pointer point to med_balance
// this is where the value will be returned
out_sqlda->sqlvar[0].sqldata = (unsigned char *)&med_balance;
out_sqlda->sqlvar[0].sqllen = sizeof(double);
/* INVOKE SERVER, THE STORE PROCEDURE */
printf(" before calling remote procedure\n");
ftime (&dbeg);
sqleproc("aris.dll\\get_total", NULL, NULL, out_sqlda, &sqlca);
ftime(&dend);
qtime_ari += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
rc = sqlca.sqlcode;
if (rc >= 0L) // if no error
return(0);
// if SQL error
error_sql = sqlca.sqlcode;
return(-1);
}
/************************************************************************/
/* FUNCTION noari() */
/************************************************************************/
short far noari()
{
/*************************************************/
/* SQL HOST VARIABLE DECLARATIONS */
/*************************************************/
EXEC SQL BEGIN DECLARE SECTION;
double balance;
short num_rows;
EXEC SQL END DECLARE SECTION;
struct timeb dbeg, dend;
long rc;
short cur_row;
short i;
double med_balance;
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL WHENEVER NOT FOUND GO TO ext;
qtime_noari = 0.0;
med_balance = 0; /* assume no error */
rc = 0;
/* INVOKE SERVER, THE STORE PROCEDURE */
ftime (&dbeg);
EXEC SQL SELECT COUNT(*)
INTO :num_rows
FROM BMCHUGH.CHECKING;
ftime(&dend);
qtime_noari += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
printf("\ntotal number of rows = %d", num_rows);
/****** DECLARE CURSOR *********/
ftime (&dbeg);
EXEC SQL DECLARE CBLOCK CURSOR FOR
SELECT C_ENDBAL FROM BMCHUGH.CHECKING
ORDER BY C_ENDBAL;
ftime(&dend);
qtime_noari += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
/****** OPEN CURSOR *********/
ftime (&dbeg);
EXEC SQL OPEN CBLOCK;
ftime(&dend);
qtime_noari += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
cur_row = 1;
/****** FETCH num_rows/2 ROWS *********/
while ((sqlca.sqlcode == 0) && (cur_row <= num_rows/2) ) {
cur_row++;
ftime (&dbeg);
EXEC SQL FETCH CBLOCK
INTO :balance;
ftime(&dend);
qtime_noari += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
printf("%7.3f\n", balance);
}/*end while more rows */
printf("\nmedian balance = %7.3f",balance);
rc = sqlca.sqlcode;
/****** CLOSE CURSOR *********/
ftime (&dbeg);
EXEC SQL CLOSE CBLOCK;
ftime(&dend);
qtime_noari += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
ext:
return(0);
error:
error_sql = sqlca.sqlcode; // copy the sql code into external variable
// to be printed on user screen by dbdemo
return(-1);
}/* end noari */
/************************************************************************/
/* FUNCTION ari() */
/* This function is called by DBDEMO and in turn calls noari() and arir()*/
/* num_run times. */
/* gets the timing info from variables qtime_ari and */
/* qtime_noari and applies the averaging logic, depending upon */
/* user entered variable num_runs. */
/* i.e. if num_runs = 1 then q1avg = qtime_ari and q2avg=qtime_noari */
/* otherwise, it disregards the first value and averages the rest */
/************************************************************************/
/************************************************************************/
ari()
{
short i;
// SET THE NUMBER OF DEMOS FOR THIS SECTION 1 OR 2.. 2 IS MAX!!!!
Timetext[0].test_num = 1;
q1avg = 0.0;
// call the function arir (which calls aris() the DLL) num_runs time
for (i=1; i<=num_runs; i++)
{
if (arir())
return(3);
if (i!=1)
q1avg = q1avg + qtime_ari;
}/* end for */
if (num_runs == 1)
q1avg = qtime_ari;
else
q1avg = q1avg / (num_runs-1);
// FILL UP TIMETEXT STRUCTURE FOR DEMO 1
strcpy(Timetext[0].demoname,"Ari ");
Timetext[0].demotime = qtime_ari;
Timetext[0].rows = 800;
// now call the function noari() num_runs time
for (i=1; i<=num_runs; i++)
{
if (noari())
return(3); // if error
if (i!=1)
q2avg = q2avg + qtime_noari;
}/* end for */
if (num_runs == 1)
q2avg = qtime_noari;
else
q2avg = q2avg / (num_runs-1);
// FILL UP TIMETEXT STRUCTURE FOR DEMO 2
strcpy(Timetext[1].demoname,"No Ari ");
Timetext[1].demotime = qtime_noari;
Timetext[1].rows = 800;
return(0);
}/* end ari */