home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: Product
/
Product.zip
/
DBDEMO.ZIP
/
DEMOFLS.ZIP
/
RBLOCKNO.SQC
< prev
next >
Wrap
Text File
|
1991-06-03
|
4KB
|
117 lines
/************************************************************************/
/* DATABASE PERFORMANCE CONCEPTS AND TECHNIQUES DEMONSTRATION PROGRAM */
/* MODULE: NO RECORD BLOCKING */
/* source file: RBLOCKNO.SQC */
/************************************************************************/
/************************************************************************/
/* HEADER FILES - USER DEFINED */
/************************************************************************/
#include "db.h"
/************************************************************************/
/* FUNCTION PROTOTYPES */
/************************************************************************/
int blocking_no(void);
struct timeb dbeg, dend;
double qtime_noblock;
/***************************************************************************/
/* 1. rblock */
/* 2. block */
/***************************************************************************/
/*************************************************/
/* SQL HOST VARIABLE DECLARATIONS */
/*************************************************/
EXEC SQL BEGIN DECLARE SECTION;
double balance;
short num_rows;
EXEC SQL END DECLARE SECTION;
/************************************************************************/
/* FUNCTION rblockno() */
/************************************************************************/
short far rblockno()
{
qtime_noblock = 0.0;
if (blocking_no())
return(-1);
return(0);
}/* end main */
/***************************************************************************/
/* FUNCTION: blocking_no() */
/***************************************************************************/
int blocking_no()
{
char error_from[20];
short cur_row;
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL WHENEVER NOT FOUND GO TO ext;
strcpy(error_from,"select count * ");
ftime (&dbeg);
EXEC SQL SELECT COUNT(*)
INTO :num_rows
FROM BMCHUGH.CHECKING;
ftime(&dend);
qtime_noblock += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
/* printf("\ntotal number of rows = %d", num_rows);
*/
/****** DECLARE CURSOR *********/
strcpy(error_from," declare cursor");
ftime (&dbeg);
EXEC SQL DECLARE CBLOCKNO CURSOR FOR
SELECT C_ENDBAL FROM BMCHUGH.CHECKING
ORDER BY C_ENDBAL;
ftime(&dend);
qtime_noblock += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
/****** OPEN CURSOR *********/
strcpy(error_from," open cursor");
ftime (&dbeg);
EXEC SQL OPEN CBLOCKNO;
ftime(&dend);
qtime_noblock += 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 CBLOCKNO
INTO :balance;
ftime(&dend);
qtime_noblock += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
/* printf("%7.3f\n", balance);
*/
}/*end while more rows */
/****** CLOSE CURSOR *********/
ftime (&dbeg);
EXEC SQL CLOSE CBLOCKNO;
ftime(&dend);
qtime_noblock += delta(dbeg.time, dend.time, dbeg.millitm, dend.millitm);
/* printf("\nmedian balance = %7.3f",balance);
printf("\ntotal time = %7.3f", qtime_noblock);
*/
ext:
return(0);
error:
/* get_error( &sqlca, error_from);
*/ return(-1);
}/* end blocking */
/***************************************************************************/