home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
VISBUILD
/
RAPSHEET
/
CPPOV23
/
DBQUERY.SQC
< prev
next >
Wrap
Text File
|
1995-05-25
|
19KB
|
430 lines
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sqlenv.h>
#include <rap.h>
#ifndef _c
#define _c
#include <dbquery.h>
#undef _c
#endif
EXEC SQL INCLUDE SQLCA;
/*DETAILS */
EXEC SQL BEGIN DECLARE SECTION;
long numberOfAliases=0;
long numberOfArrests=0;
long numberOfLastSeens=0;
long numberOfSuspects=0;
char SLNAME[30]; /* Hold area for return name */
char SFNAME[20]; /* Hold area for return name */
short SGENDER; /* Hold area for return GENDER */
short SHCOLOR; /* Hold area for return HAIR COLOR */
short SECOLOR; /* Hold area for return EYE COLOR */
short SWEIGHT; /* Hold area for return weight */
short SHEIGHT; /* Hold area for return height */
short SHSCAR; /* Hold area for return scar */
short SHMOLE; /* Hold area for return mole */
short SHTATTOO; /* Hold area for return tattoo */
char SBDATE[10]; /* Hold area for return date */
long SBOOK; /* Hold area for return book number */
long SMFRONT; /* Hold area for return front view RC ID */
long SMRIGHT; /* Hold area for return right view RC ID */
long SLEFT; /* Hold area for return left view RC ID */
char SSTREET[30]; /* Hold area for return street */
char SCITY[20]; /* Hold area for return city */
char SCOUNTY[20]; /* Hold area for return county */
char SSTATE[2]; /* Hold area for return state */
char SZIP[5]; /* Hold area for return zip */
char SINFO[100]; /* Hold area for return misc info. */
char SMO[100]; /* Hold area for return motus operandi */
char SSCARDSC[50]; /* Hold area for return scar desc */
char SMOLEDSC[50]; /* Hold area for return mole desc */
char STATODSC[50]; /* Hold area for return tattoo desc */
/*ARRESTS */
short ARCHARGE; /* Hold area for charge */
short ARSTATUS; /* Hold area for status */
char ARSTDATE[10]; /* Hold area for arrest date */
char ARREPORT[200]; /* Hold area for arrest report */
/*ALIASES */
char ALNAME[50]; /* Hold area for alias name */
/*LAST SEEN */
char LSLOC[50]; /* Hold area for last seen location */
char LSWITNESS[50]; /* Hold area for " by */
char LSDATE[10]; /* Hold area for " date */
char LSSTREET[30]; /* Hold area for " street */
char LSCITY[20]; /* Hold area for " city */
char LSSTATE[2]; /* Hold area for " state */
char LSCOMMENT[50]; /* Hold area for " comments */
EXEC SQL END DECLARE SECTION;
SQL_API_RC sql_rc = 0;
/*****************************************************************/
/* */
/* setupDataBase */
/* */
/*****************************************************************/
long setupDatabase()
{
EXEC SQL WHENEVER NOT FOUND GO TO error;
EXEC SQL WHENEVER SQLERROR GO TO error;
sql_rc = sqleisig(&sqlca);
EXEC SQL CONNECT TO RAP IN SHARE MODE;
EXEC SQL SELECT COUNT(*) INTO :numberOfSuspects FROM SUSPECT_DETAIL;
EXEC SQL DECLARE suspect_cursor CURSOR FOR
SELECT SUSPECT_LAST_NAME, SUSPECT_FIRST_NAME, SUSPECT_GENDER, SUSPECT_HAIR_COLOR,
SUSPECT_EYE_COLOR, SUSPECT_WEIGHT, SUSPECT_HEIGHT, SUSPECT_HAS_SCAR,
SUSPECT_HAS_MOLE, SUSPECT_HAS_TATTOO, SUSPECT_BIRTH_DATE,
SUSPECT_BOOK_NUM, SUSPECT_MUG_FRONT, SUSPECT_MUG_RIGHT,
SUSPECT_MUG_LEFT, SUSPECT_STREET, SUSPECT_CITY,
SUSPECT_COUNTY, SUSPECT_STATE, SUSPECT_ZIP, SUSPECT_INFO,
SUSPECT_MO, SUSPECT_SCAR_DESC, SUSPECT_MOLE_DESC,
SUSPECT_TATTOO_DSC
FROM SUSPECT_DETAIL;
EXEC SQL OPEN suspect_cursor;
EXEC SQL DECLARE alias_cursor CURSOR FOR
SELECT ALIAS_NAME
FROM SUSPECT_ALIAS
WHERE ALIAS_SUSPECT = :SBOOK;
EXEC SQL DECLARE arrest_cursor CURSOR FOR
SELECT ARREST_CHARGE, ARREST_STATUS, ARREST_STATUS_DATE, ARREST_REPORT
FROM SUSPECT_ARREST
WHERE ARREST_SUSPECT = :SBOOK;
EXEC SQL DECLARE lastSeen_cursor CURSOR FOR
SELECT LAST_SEEN_LOCATION, LAST_SEEN_BY, LAST_SEEN_DATE, LAST_SEEN_STREET,
LAST_SEEN_CITY, LAST_SEEN_STATE, LAST_SEEN_COMMENT
FROM SUSPECT_LAST_SEEN
WHERE LAST_SEEN_SUSPECT = :SBOOK;
error:
EXEC SQL WHENEVER SQLERROR CONTINUE;
return (SQLCODE);
}
/*****************************************************************/
/* */
/* howManySuspects */
/* */
/* Returns the number of suspect records in the database */
/*****************************************************************/
long howManySuspects()
{
return (numberOfSuspects);
}
/*****************************************************************/
/* */
/* howManyAliases */
/* */
/* Returns the number of alias records in the database */
/*****************************************************************/
long howManyAliases(unsigned long bookNumber)
{
SBOOK = bookNumber;
EXEC SQL WHENEVER NOT FOUND GO TO error;
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL SELECT COUNT(*) INTO :numberOfAliases
FROM SUSPECT_ALIAS
WHERE ALIAS_SUSPECT = :SBOOK;
error:
EXEC SQL WHENEVER SQLERROR CONTINUE;
return (numberOfAliases);
}
/*****************************************************************/
/* */
/* howManyArrests */
/* */
/* Returns the number of arrest records in the database */
/*****************************************************************/
long howManyArrests(unsigned long bookNumber)
{
SBOOK = bookNumber;
EXEC SQL WHENEVER NOT FOUND GO TO error;
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL SELECT COUNT(*) INTO :numberOfArrests
FROM SUSPECT_ARREST
WHERE ARREST_SUSPECT = :SBOOK;
error:
EXEC SQL WHENEVER SQLERROR CONTINUE;
return (numberOfArrests);
}
/*****************************************************************/
/* */
/* howManyLastSeens */
/* */
/* Returns the number of lastseen records in the database */
/*****************************************************************/
long howManyLastSeens(unsigned long bookNumber)
{
SBOOK = bookNumber;
EXEC SQL WHENEVER NOT FOUND GO TO error;
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL SELECT COUNT(*) INTO :numberOfLastSeens
FROM SUSPECT_LAST_SEEN
WHERE LAST_SEEN_SUSPECT = :SBOOK;
error:
EXEC SQL WHENEVER SQLERROR CONTINUE;
return (numberOfLastSeens);
}
/*****************************************************************/
/* */
/* getNextSuspect */
/* */
/* Returns the next suspect record from the database */
/*****************************************************************/
long getNextSuspect(SUSPECT_STRUCT *suspectStructure)
{
printf ("DBQUERY==> Entered getNextSuspect\n");
EXEC SQL WHENEVER NOT FOUND GO TO error;
EXEC SQL WHENEVER SQLERROR GO TO error;
printf ("DBQUERY==> About to perform FETCH of suspect info.\n");
EXEC SQL FETCH suspect_cursor
INTO :SLNAME, :SFNAME, :SGENDER, :SHCOLOR, :SECOLOR, :SWEIGHT, :SHEIGHT,
:SHSCAR, :SHMOLE, :SHTATTOO, :SBDATE, :SBOOK,
:SMFRONT, :SMRIGHT, :SLEFT, :SSTREET, :SCITY,
:SCOUNTY, :SSTATE, :SZIP, :SINFO, :SMO, :SSCARDSC,
:SMOLEDSC, :STATODSC;
printf ("DBQUERY==> Completed FETCH of suspect info. Return code is %d.\n",SQLCODE);
memset(suspectStructure,0,sizeof(SUSPECT_STRUCT));
printf ("DBQUERY==> Initialized structure. book_number is %d.\n",suspectStructure->book_number);
memcpy(suspectStructure->lastName,SLNAME,LAST_NAME_LEN);
printf ("DBQUERY==> Set lastName to %s.\n",suspectStructure->lastName);
memcpy(suspectStructure->firstName,SFNAME,FIRST_NAME_LEN);
memcpy(suspectStructure->street,SSTREET,ADDRESS_STREET_LEN);
memcpy(suspectStructure->city,SCITY,ADDRESS_CITY_LEN);
memcpy(suspectStructure->county,SCOUNTY,ADDRESS_COUNTY_LEN);
memcpy(suspectStructure->state,SSTATE,ADDRESS_STATE_LEN);
memcpy(suspectStructure->zip,SZIP,ADDRESS_ZIP_LEN);
memcpy(suspectStructure->info,SINFO,SUSPECT_INFO_LEN);
suspectStructure->hasMole = SHMOLE;
suspectStructure->hasScar = SHSCAR;
suspectStructure->hasTattoo = SHTATTOO;
suspectStructure->book_number = SBOOK;
suspectStructure->gender = SGENDER;
suspectStructure->hairColor = SHCOLOR;
suspectStructure->eyeColor = SECOLOR;
suspectStructure->weight = SWEIGHT;
suspectStructure->height = SHEIGHT;
memcpy(suspectStructure->birthDate,SBDATE,DATE_LEN);
suspectStructure->mugFront = SMFRONT;
suspectStructure->mugRight = SMRIGHT;
suspectStructure->mugLeft = SLEFT;
memcpy(suspectStructure->MO,SMO,SUSPECT_MO_DESC_LEN);
memcpy(suspectStructure->scarDescription,SSCARDSC,SUSPECT_TRAIT_DESC_LEN);
memcpy(suspectStructure->moleDescription,SMOLEDSC,SUSPECT_TRAIT_DESC_LEN);
memcpy(suspectStructure->tattooDescription,STATODSC,SUSPECT_TRAIT_DESC_LEN);
printf ("DBQUERY==> Leaving getNextSuspect\n");
error:
EXEC SQL WHENEVER SQLERROR CONTINUE;
return(SQLCODE);
}
/*****************************************************************/
/* */
/* getNextAlias */
/* */
/* Returns the next alias record from the database */
/*****************************************************************/
long getNextAlias(char * anAliasName, unsigned long bookNumber)
{
EXEC SQL WHENEVER NOT FOUND GO TO error;
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL FETCH alias_cursor
INTO :ALNAME;
memset(anAliasName,0,ALIAS_NAME_LEN+1);
memcpy(anAliasName, ALNAME,ALIAS_NAME_LEN);
error:
EXEC SQL WHENEVER SQLERROR CONTINUE;
return(SQLCODE);
}
/*****************************************************************/
/* */
/* getNextArrest */
/* */
/* Returns the next arrest record from the database */
/*****************************************************************/
long getNextArrest(ARREST_STRUCT *arrestStructure, unsigned long bookNumber)
{
EXEC SQL WHENEVER NOT FOUND GO TO error;
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL FETCH arrest_cursor
INTO :ARCHARGE, :ARSTATUS, :ARSTDATE, :ARREPORT;
memset(arrestStructure,0,sizeof(ARREST_STRUCT));
arrestStructure->arrestCharge = ARCHARGE;
arrestStructure->arrestStatus = ARSTATUS;
memcpy(arrestStructure->arrestDate,ARSTDATE,DATE_LEN);
memcpy(arrestStructure->arrestReport,ARREPORT,ARREST_REPORT_LEN);
error:
EXEC SQL WHENEVER SQLERROR CONTINUE;
return(SQLCODE);
}
/*****************************************************************/
/* */
/* getNextLastSeen */
/* */
/* Returns the next lastseen record from the database */
/*****************************************************************/
long getNextLastSeen(LAST_SEEN_STRUCT *lastSeenStructure, unsigned long bookNumber)
{
EXEC SQL WHENEVER NOT FOUND GO TO error;
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL FETCH lastSeen_cursor
INTO :LSLOC, :LSWITNESS, :LSDATE, :LSSTREET, :LSCITY, :LSSTATE, :LSCOMMENT;
memset(lastSeenStructure,0,sizeof(LAST_SEEN_STRUCT));
memcpy(lastSeenStructure->lastSeenLocation,LSLOC,LS_LOC_LEN);
memcpy(lastSeenStructure->lastSeenWitness,LSWITNESS,LS_WITNESS_LEN);
memcpy(lastSeenStructure->lastSeenDate,LSDATE,DATE_LEN);
memcpy(lastSeenStructure->lastSeenStreet,LSSTREET,ADDRESS_STREET_LEN);
memcpy(lastSeenStructure->lastSeenCity,LSCITY,ADDRESS_CITY_LEN);
memcpy(lastSeenStructure->lastSeenState,LSSTATE,ADDRESS_STATE_LEN);
memcpy(lastSeenStructure->lastSeenComment,LSCOMMENT,COMMENT_LEN);
error:
EXEC SQL WHENEVER SQLERROR CONTINUE;
return(SQLCODE);
}
/*****************************************************************/
/* */
/* closeAlC() */
/* */
/* Closes the alias cursor */
/*****************************************************************/
long closeAlC()
{
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL CLOSE alias_cursor;
error:
return (SQLCODE);
}
/*****************************************************************/
/* */
/* closeArC */
/* */
/* Closes the database */
/*****************************************************************/
long closeArC()
{
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL CLOSE arrest_cursor;
error:
return (SQLCODE);
}
/*****************************************************************/
/* */
/* closeLsC */
/* */
/* Closes the last seen cursor */
/*****************************************************************/
long closeLsC()
{
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL CLOSE lastSeen_cursor;
error:
return (SQLCODE);
}
/*****************************************************************/
/* */
/* openAlC() */
/* */
/* opens the alias cursor */
/*****************************************************************/
long openAlC()
{
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL OPEN alias_cursor;
error:
return (SQLCODE);
}
/*****************************************************************/
/* */
/* openArC */
/* */
/* opens the arrest cursor */
/*****************************************************************/
long openArC()
{
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL OPEN arrest_cursor;
error:
return (SQLCODE);
}
/*****************************************************************/
/* */
/* openLsC */
/* */
/* opens the last seen cursor */
/*****************************************************************/
long openLsC()
{
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL OPEN lastSeen_cursor;
error:
return (SQLCODE);
}
/*****************************************************************/
/* */
/* closeDB */
/* */
/* Closes the database */
/*****************************************************************/
long closeDB()
{
EXEC SQL WHENEVER SQLERROR GO TO error;
EXEC SQL CONNECT RESET;
error:
return (SQLCODE);
}