home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
VISBUILD
/
RAPSHEET
/
CPPOV23
/
QUERYDB.CPP
< prev
next >
Wrap
Text File
|
1995-05-12
|
18KB
|
454 lines
//****************************************************************************
// querydb.cpp - source file of database functions *
// *
// COPYRIGHT: Copyright (C) International Business Machines Corp., 1994,1995 *
// *
// DISCLAIMER OF WARRANTIES: *
// The following [enclosed] code is sample code created by IBM *
// Corporation. This sample code is not part of any standard IBM product *
// and is provided to you solely for the purpose of assisting you in the *
// development of your applications. The code is provided "AS IS", *
// without warranty of any kind. IBM shall not be liable for any damages *
// arising out of your use of the sample code, even if they have been *
// advised of the possibility of such damages. *
//****************************************************************************
//NOTE: WE RECOMMEND USING A FIXED-SPACE FONT TO LOOK AT THE SOURCE.
//
#include <stdlib.h>
#include <iostream.h>
#include <istring.hpp>
//#include <iseq.h> /*for the alias names collection */
#include "isusrec.hpp" /*ISuspectRecord header */
#include "irsltrec.hpp" /*IResultRecord header */
#include <ilsrec.hpp>
#include <iarstrec.hpp>
#include <ialsrec.hpp>
#include "querydb.hpp"
#include "dbquery.h"
#include <rap.h>
#ifndef _ITRACE_
#include <itrace.hpp>
#endif
IBoolean firstSuspectRecord;
/*****************************************************************/
/* */
/* getAllSuspects */
/* */
/*Function: Gets the list of suspects from the database */
/* */
/*****************************************************************/
IResultRecord getAllSuspects()
{
firstSuspectRecord = true;
unsigned short numberOfAddresses=1; /*one address for driver 1 */
IString tempBuffer;
IString tempRecords;
IString suspectNumber;
IString suspectName;
IString queryName; /*added - kae */
IString suspectAddress;
IString suspectVariableData; /* accumulate the addresses and aliases data to */
/* pass to setSuspectVariableData() member function */
ISuspectRecord suspectRecord;
ISuspectRecord tempSuspectRecord;
IResultRecord resultRecord;
long rc;
long numberOfSuspects;
long numberOfResults;
long suspectsToGo;
SUSPECT_STRUCT myss;
//-------------------------------------------------------------------------------
// Open communications with the database
//-------------------------------------------------------------------------------
IFUNCTRACE_DEVELOP();
ITRACE_DEVELOP("Setting up the database");
rc = setupDatabase();
ITRACE_DEVELOP("Setting up the database is complete. return code is " + IString(rc) + ".");
//-------------------------------------------------------------------------------
// If the database open was successful, see how many suspect records are in the
// database and use that value to control their retrieval
//-------------------------------------------------------------------------------
if (rc == 0)
{
numberOfSuspects = howManySuspects();
numberOfResults = numberOfSuspects;
ITRACE_DEVELOP("Number of Suspects: " + IString(numberOfSuspects) + ".");
for (suspectsToGo = numberOfSuspects;suspectsToGo > 0 ;suspectsToGo--)
{
ITRACE_DEVELOP("Suspects to go: " + IString(suspectsToGo) + ".");
// Get the next suspect record from the database
rc = getNextSuspect(&myss);
if (rc == 0)
{
/* suspect.setNumOfSuspects(numberOfSuspects); */
suspectRecord.setLastName(myss.lastName);
ITRACE_DEVELOP("Last Name is: " + IString(myss.lastName) + ".");
suspectRecord.setFirstName(myss.firstName);
suspectRecord.setStreet(myss.street);
suspectRecord.setCity(myss.city);
suspectRecord.setCounty(myss.county);
suspectRecord.setState(myss.state);
suspectRecord.setZip(myss.zip);
suspectRecord.setDescription(myss.info);
suspectRecord.setBookNumber(myss.book_number);
suspectRecord.setGender(myss.gender);
suspectRecord.setHeight(myss.height);
suspectRecord.setWeight(myss.weight);
suspectRecord.setHairColor(myss.hairColor);
suspectRecord.setEyeColor(myss.eyeColor);
suspectRecord.enableHasMole(myss.hasMole);
suspectRecord.enableHasScar(myss.hasScar);
suspectRecord.enableHasTattoo(myss.hasTattoo);
suspectRecord.setMugFront(myss.mugFront);
suspectRecord.setMugRight(myss.mugRight);
suspectRecord.setMugLeft(myss.mugLeft);
suspectRecord.setBirthDate(myss.birthDate);
suspectRecord.setMO(myss.MO);
suspectRecord.setMoleDescription(myss.moleDescription);
suspectRecord.setScarDescription(myss.scarDescription);
suspectRecord.setTattooDescription(myss.tattooDescription);
/* setup resultRecord */
cout << "suspectRecord built in query." << endl;
cout << " Size: " << suspectRecord.size() << "." << endl;
cout << " Last Name: " << suspectRecord.lastName() << "." << endl;
cout << " First Name: " << suspectRecord.firstName() << "." << endl;
cout << "Description: " << suspectRecord.description() << "." << endl;
cout << endl;
ITRACE_DEVELOP("Setting up result record.");
resultRecord.setNumResults(numberOfSuspects);
//-----------------------------------------------------------------
// If this is the first suspect record then copy it to a temporary
// area. Otherwise, append it to the temporary area
// When all records are copied/appended, copy the temporary
// suspect record to the result record.
//-----------------------------------------------------------------
if (firstSuspectRecord)
{
ITRACE_DEVELOP("This is the first suspect record.");
firstSuspectRecord = false;
tempRecords = suspectRecord.asString();
}
else
{
ITRACE_DEVELOP("This is not the first suspect record.");
tempRecords += suspectRecord.asString();
}
}
else
{
// resultRecord.setReturnCode(rc);
} /* end DATA BASE READ */
} /* end processing of suspect list for loop */
//------------------------------------------------------
// Finished building suspect records. Build the result record
//------------------------------------------------------
resultRecord.setResultData(tempRecords);
}
else
{
// resultRecord.setReturnCode(rc);
}
return resultRecord;
}
/*****************************************************************/
/* */
/* getAllAliases */
/* */
/*Function: Gets the list of aliases from the database */
/* using the book number from the suspect object */
/* */
/*****************************************************************/
IResultRecord getAllAliases(unsigned long bookNumber)
{
IBoolean firstAliasRecord = true;
unsigned short numberOfAddresses=1; /*one address for driver 1 */
char anAliasName[ALIAS_NAME_LEN];
IString tempBuffer;
IString tempRecords;
IString aliasVariableData; /* accumulate the alias data to */
IAliasRecord aliasRecord;
IAliasRecord tempAliasRecord;
IResultRecord aliasResultRecord;
long alRc;
long numberOfAliases;
long numberOfAliasResults;
long aliasesToGo;
//-------------------------------------------------------------------------------
// See how many alias records are in the
// database and use that value to control their retrieval
//-------------------------------------------------------------------------------
numberOfAliases = howManyAliases(bookNumber);
numberOfAliasResults = numberOfAliases;
aliasResultRecord.setNumResults(numberOfAliases);
alRc = openAlC(); // Open the alias table cursor
for (aliasesToGo = numberOfAliases;aliasesToGo > 0 ;aliasesToGo--)
{
//--------------------------------------------
// Get the next alias record from the database
//--------------------------------------------
alRc = getNextAlias(anAliasName, bookNumber);
if (alRc == 0)
{
tempBuffer = anAliasName;
aliasRecord.setName(tempBuffer);
//-----------------------------------------------------------------
// If this is the first alias record then copy it to a temporary
// area. Otherwise, append it to the temporary area
// When all records are copied/appended, copy the temporary
// alias record to the result record.
//-----------------------------------------------------------------
if (firstAliasRecord)
{
firstAliasRecord = false;
tempRecords = aliasRecord.asString();
}
else
{
tempRecords += aliasRecord.asString();
}
}
else
{
// aliasResultRecord.setReturnCode(alRc);
} /* end DATA BASE READ */
} /* end processing of suspect list for-loop */
alRc=closeAlC(); // close the alias table cursor
//------------------------------------------------------
// Finished building alias records. Build the result record
//------------------------------------------------------
aliasResultRecord.setResultData(tempRecords);
return aliasResultRecord;
}
/*****************************************************************/
/* */
/* getAllArrests */
/* */
/*Function: Gets the list of arrests from the database */
/* using the book number from the suspect object */
/* */
/*****************************************************************/
IResultRecord getAllArrests(unsigned long bookNumber)
{
IBoolean firstArrestRecord = true;
IString tempBuffer;
IString tempRecords;
IString arrestVariableData; /* accumulate the arrest data to */
IArrestRecord arrestRecord;
IArrestRecord tempArrestRecord;
IResultRecord arrestResultRecord;
long arRc;
long numberOfArrests;
long numberOfArrestResults;
long arrestsToGo;
ARREST_STRUCT MyArs;
//-------------------------------------------------------------------------------
// See how many arrest records are in the
// database and use that value to control their retrieval
//-------------------------------------------------------------------------------
numberOfArrests = howManyArrests(bookNumber);
numberOfArrestResults = numberOfArrests;
arrestResultRecord.setNumResults(numberOfArrests);
arRc = openArC(); // Open the arrest table cursor
for (arrestsToGo = numberOfArrests;arrestsToGo > 0 ;arrestsToGo--)
{
//---------------------------------------------
// Get the next arrest record from the database
//---------------------------------------------
arRc = getNextArrest(&MyArs, bookNumber);
if (arRc == 0)
{
arrestRecord.setCharge(MyArs.arrestCharge);
arrestRecord.setStatus(MyArs.arrestStatus);
arrestRecord.setStatusDate(MyArs.arrestDate);
// arrestRecord.setReport(MyArs.arrestReport);
/* setup resultRecord */
//-----------------------------------------------------------------
// If this is the first arrest record then copy it to a temporary
// area. Otherwise, append it to the temporary area
// When all records are copied/appended, copy the temporary
// arrest record to the result record.
//-----------------------------------------------------------------
if (firstArrestRecord)
{
firstArrestRecord = false;
tempRecords = arrestRecord.asString();
}
else
{
tempRecords += arrestRecord.asString();
}
}
else
{
// arrestResultRecord.setReturnCode(arRc);
} /* end DATA BASE READ */
} /* end processing of suspect list for loop */
arRc = closeArC(); // close the arrest table cursor
//------------------------------------------------------
// Finished building suspect records. Build the result record
//------------------------------------------------------
arrestResultRecord.setResultData(tempRecords);
return arrestResultRecord;
}
/*****************************************************************/
/* */
/* getAllLastSeen */
/* */
/*Function: Gets the list of last seen reports from the database */
/* using the book number from the suspect object */
/* */
/*****************************************************************/
IResultRecord getAllLastSeen(unsigned long bookNumber)
{
IBoolean firstLastSeenRecord = true;
IString tempBuffer;
IString tempRecords;
IString lastSeenVariableData; /* accumulate the lastSeen data to */
ILastSeenRecord lastSeenRecord;
ILastSeenRecord tempLastSeenRecord;
IResultRecord lastSeenResultRecord;
long lsRc;
long numberOfLastSeens;
long numberOfLastSeenResults;
long lastSeensToGo;
LAST_SEEN_STRUCT MyLSs;
//-------------------------------------------------------------------------------
// See how many lastSeen records are in the
// database and use that value to control their retrieval
//-------------------------------------------------------------------------------
numberOfLastSeens = howManyLastSeens(bookNumber);
numberOfLastSeenResults = numberOfLastSeens;
lastSeenResultRecord.setNumResults(numberOfLastSeens);
lsRc = openLsC(); // open the las seen cursor
for (lastSeensToGo = numberOfLastSeens;lastSeensToGo > 0 ;lastSeensToGo--)
{
//---------------------------------------------
// Get the next lastSeen record from the database
//---------------------------------------------
lsRc = getNextLastSeen(&MyLSs, bookNumber);
if (lsRc == 0)
{
lastSeenRecord.setLocation(MyLSs.lastSeenLocation);
lastSeenRecord.setWitness(MyLSs.lastSeenWitness);
lastSeenRecord.setLastSeenDate(MyLSs.lastSeenDate);
lastSeenRecord.setStreet(MyLSs.lastSeenStreet);
lastSeenRecord.setCity(MyLSs.lastSeenCity);
lastSeenRecord.setState(MyLSs.lastSeenState);
lastSeenRecord.setComment(MyLSs.lastSeenComment);
/* setup resultRecord */
//-----------------------------------------------------------------
// If this is the first lastSeen record then copy it to a temporary
// area. Otherwise, append it to the temporary area
// When all records are copied/appended, copy the temporary
// lastSeen record to the result record.
//-----------------------------------------------------------------
if (firstLastSeenRecord)
{
firstLastSeenRecord = false;
tempRecords = lastSeenRecord.asString();
}
else
{
tempRecords += lastSeenRecord.asString();
}
}
else
{
// lastSeenResultRecord.setReturnCode(lsRc);
} /* end DATA BASE READ */
} /* end processing of suspect list for loop */
lsRc = closeLsC(); // close the last seen cursor
//------------------------------------------------------
// Finished building suspect records. Build the result record
//------------------------------------------------------
lastSeenResultRecord.setResultData(tempRecords);
return lastSeenResultRecord;
}
/*****************************************************************************
! error(const char *message)
!
! Display error message and exit.
*****************************************************************************/
void error(const char *message)
{
cout << "\n\nERROR: %s\n\n", message;
exit(1);
}