home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: Product
/
Product.zip
/
DBDEMO.ZIP
/
DEMOFLS.ZIP
/
ARIS.SQC
< prev
next >
Wrap
Text File
|
1991-06-03
|
4KB
|
107 lines
/************************************************************************/
/* DATABASE PERFORMANCE CONCEPTS AND TECHNIQUES DEMONSTRATION PROGRAM */
/* MODULE: APPLICATION REMOTE PROCEDURE (SERVER PART) */
/* source file: ARIS.SQC */
/************************************************************************/
/*****************************************************************************/
/*Purpose: This module is the SERVER side of the stored procedure. It */
/* contains the functions get_total and is stored as a DLL on server*/
/*Support: This functions could be compiled into a dynamic library using its*/
/* own make file - ARIS. */
/* It needs a DEF file(ARIS.DEF) to be compiled into a DLL */
/*Input : vardata - NULL */
/* input_sqlda - NULL */
/* output_sqlda- out sqlda, contains the median balance value */
/* sqlcaptr - pointer of sqlca */
/*output : */
/* sqlcaptr - sql code */
/*****************************************************************************/
/************************************************************************/
/* HEADER FILES - SYSTEM , LANGUAGE AND SQL HEADER */
/************************************************************************/
#include <memory.h>
#include <stdio.h>
#include <string.h>
#include "sql.h" /* defines SQLZ_DISCONNECT_PROC */
#include "sqlutil.h" /* defines sqlchar structure */
/************************************************************************/
/* FUNCTION PROTOTYPES */
/************************************************************************/
void get_error(char *);
EXEC SQL INCLUDE SQLCA;
EXEC SQL INCLUDE SQLDA; /* defines sqlda structure */
/*************************************************/
/* SQL HOST VARIABLE DECLARATIONS */
/*************************************************/
EXEC SQL BEGIN DECLARE SECTION;
short int num_accounts;
EXEC SQL END DECLARE SECTION;
short int retcode;
/************************************************************************/
/* FUNCTION get_total */
/************************************************************************/
extern int far pascal get_total(
struct sqlchar *vardata,
struct sqlda *insqlda,
struct sqlda *outsqlda,
struct sqlca *sqlcaptr)
{
/* UNPACKED INPUT SQLDA */
char error_from[20];
short cur_row;
EXEC SQL BEGIN DECLARE SECTION;
double balance;
short num_rows;
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL WHENEVER NOT FOUND GO TO ext;
retcode = 0;
sqlcaptr->sqlcode = 0;
/* update customer */
strcpy(error_from,"select count * ");
EXEC SQL SELECT COUNT(*)
INTO :num_rows
FROM BMCHUGH.CHECKING;
/****** DECLARE CURSOR *********/
EXEC SQL DECLARE CBLOCK CURSOR FOR
SELECT C_ENDBAL FROM BMCHUGH.CHECKING
ORDER BY C_ENDBAL;
/****** OPEN CURSOR *********/
EXEC SQL OPEN CBLOCK;
cur_row = 1;
/****** FETCH num_rows/2 ROWS *********/
while ((sqlca.sqlcode == 0) && (cur_row <= num_rows/2) ) {
cur_row++;
EXEC SQL FETCH CBLOCK
INTO :balance;
}/*end while more rows */
/****** CLOSE CURSOR *********/
EXEC SQL CLOSE CBLOCK;
memcpy(outsqlda->sqlvar[0].sqldata, &balance, sizeof(double));
memcpy(sqlcaptr, &sqlca, sizeof(sqlca));
error:
ext:
return(SQLZ_DISCONNECT_PROC);
}/* end get_total*/
/*****************************************************************************/