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 >
Text File  |  1995-05-12  |  18KB  |  454 lines

  1. //****************************************************************************
  2. // querydb.cpp - source file of database functions                           *
  3. //                                                                           *
  4. // COPYRIGHT: Copyright (C) International Business Machines Corp., 1994,1995 *
  5. //                                                                           *
  6. // DISCLAIMER OF WARRANTIES:                                                 *
  7. //   The following [enclosed] code is sample code created by IBM             *
  8. //   Corporation.  This sample code is not part of any standard IBM product  *
  9. //   and is provided to you solely for the purpose of assisting you in the   *
  10. //   development of your applications.  The code is provided "AS IS",        *
  11. //   without warranty of any kind.  IBM shall not be liable for any damages  *
  12. //   arising out of your use of the sample code, even if they have been      *
  13. //   advised of the possibility of such damages.                             *
  14. //****************************************************************************
  15. //NOTE: WE RECOMMEND USING A FIXED-SPACE FONT TO LOOK AT THE SOURCE.
  16. //
  17.  
  18. #include <stdlib.h>
  19.  
  20. #include <iostream.h>
  21. #include <istring.hpp>  
  22.  
  23. //#include <iseq.h>                     /*for the alias names collection                  */
  24.  
  25. #include "isusrec.hpp"                /*ISuspectRecord header                           */
  26. #include "irsltrec.hpp"               /*IResultRecord header                            */
  27. #include <ilsrec.hpp>
  28. #include <iarstrec.hpp>
  29. #include <ialsrec.hpp>
  30.  
  31. #include "querydb.hpp"
  32. #include "dbquery.h"
  33. #include <rap.h>
  34.  
  35.  
  36. #ifndef _ITRACE_
  37.    #include <itrace.hpp>
  38. #endif
  39.  
  40. IBoolean firstSuspectRecord;
  41.  
  42.  
  43. /*****************************************************************/ 
  44. /*                                                               */
  45. /* getAllSuspects                                                */
  46. /*                                                               */
  47. /*Function: Gets the list of suspects from the database          */
  48. /*                                                               */
  49. /*****************************************************************/
  50. IResultRecord getAllSuspects()
  51. {
  52.  
  53.   firstSuspectRecord = true;
  54.   
  55.   unsigned short numberOfAddresses=1;    /*one address for driver 1                               */
  56.  
  57.   IString   tempBuffer;
  58.   IString   tempRecords;
  59.   IString   suspectNumber;
  60.   IString   suspectName;
  61.   IString   queryName;                   /*added - kae                                             */
  62.   IString   suspectAddress;
  63.   IString   suspectVariableData;         /* accumulate the addresses and aliases data to           */
  64.                                          /* pass to setSuspectVariableData() member function       */
  65.  
  66.   ISuspectRecord        suspectRecord;
  67.   ISuspectRecord        tempSuspectRecord;
  68.   IResultRecord         resultRecord;
  69.  
  70.   long rc;
  71.   long numberOfSuspects;
  72.   long numberOfResults;
  73.   long suspectsToGo;
  74.  
  75.   SUSPECT_STRUCT myss;
  76.  
  77. //-------------------------------------------------------------------------------
  78. // Open communications with the database
  79. //-------------------------------------------------------------------------------
  80.  
  81.   IFUNCTRACE_DEVELOP();
  82.  
  83.   ITRACE_DEVELOP("Setting up the database");
  84.   rc = setupDatabase();
  85.   ITRACE_DEVELOP("Setting up the database is complete. return code is " + IString(rc) + ".");
  86.  
  87. //-------------------------------------------------------------------------------
  88. // If the database open was successful, see how many suspect records are in the
  89. // database and use that value to control their retrieval
  90. //-------------------------------------------------------------------------------
  91.   if (rc == 0) 
  92.   {
  93.     numberOfSuspects = howManySuspects();
  94.     numberOfResults =  numberOfSuspects;
  95.  
  96.  
  97.     ITRACE_DEVELOP("Number of Suspects: " + IString(numberOfSuspects) + ".");
  98.     for (suspectsToGo = numberOfSuspects;suspectsToGo > 0 ;suspectsToGo--) 
  99.     {
  100.      ITRACE_DEVELOP("Suspects to go: " + IString(suspectsToGo) + ".");
  101.  
  102.      // Get the next suspect record from the database
  103.  
  104.      rc = getNextSuspect(&myss);
  105.      if (rc == 0)
  106.      {
  107.  
  108.       /* suspect.setNumOfSuspects(numberOfSuspects);                   */
  109.        suspectRecord.setLastName(myss.lastName);
  110.  
  111.        ITRACE_DEVELOP("Last Name is: " + IString(myss.lastName) + ".");
  112.  
  113.        suspectRecord.setFirstName(myss.firstName);
  114.        suspectRecord.setStreet(myss.street);
  115.        suspectRecord.setCity(myss.city);
  116.        suspectRecord.setCounty(myss.county);          
  117.        suspectRecord.setState(myss.state);            
  118.        suspectRecord.setZip(myss.zip);                
  119.        suspectRecord.setDescription(myss.info);
  120.        suspectRecord.setBookNumber(myss.book_number);
  121.        suspectRecord.setGender(myss.gender);
  122.        suspectRecord.setHeight(myss.height);
  123.        suspectRecord.setWeight(myss.weight);
  124.        suspectRecord.setHairColor(myss.hairColor);
  125.        suspectRecord.setEyeColor(myss.eyeColor);
  126.        suspectRecord.enableHasMole(myss.hasMole);
  127.        suspectRecord.enableHasScar(myss.hasScar);
  128.        suspectRecord.enableHasTattoo(myss.hasTattoo);
  129.        suspectRecord.setMugFront(myss.mugFront);
  130.        suspectRecord.setMugRight(myss.mugRight);
  131.        suspectRecord.setMugLeft(myss.mugLeft);
  132.        suspectRecord.setBirthDate(myss.birthDate);
  133.        suspectRecord.setMO(myss.MO);
  134.        suspectRecord.setMoleDescription(myss.moleDescription);
  135.        suspectRecord.setScarDescription(myss.scarDescription);
  136.        suspectRecord.setTattooDescription(myss.tattooDescription);
  137.  
  138.      /* setup resultRecord */
  139.  
  140.        cout << "suspectRecord built in query." << endl;
  141.        cout << "       Size: " << suspectRecord.size() << "." << endl;
  142.        cout << "  Last Name: " << suspectRecord.lastName() << "." << endl;
  143.        cout << " First Name: " << suspectRecord.firstName() << "." << endl;
  144.        cout << "Description: " << suspectRecord.description() << "." << endl;
  145.        cout << endl;
  146.  
  147.      
  148.        ITRACE_DEVELOP("Setting up result record.");
  149.        resultRecord.setNumResults(numberOfSuspects);
  150.  
  151.        //-----------------------------------------------------------------
  152.        // If this is the first suspect record then copy it to a temporary
  153.        // area. Otherwise, append it to the temporary area
  154.        // When all records are copied/appended, copy the temporary
  155.        // suspect record to the result record.
  156.        //-----------------------------------------------------------------
  157.        if (firstSuspectRecord)
  158.        {
  159.  
  160.         ITRACE_DEVELOP("This is the first suspect record.");
  161.         firstSuspectRecord = false;
  162.         tempRecords = suspectRecord.asString();
  163.        }
  164.        else
  165.        {
  166.         ITRACE_DEVELOP("This is not the first suspect record.");
  167.         tempRecords += suspectRecord.asString();
  168.        }
  169.      }
  170.      else 
  171.      {
  172. //        resultRecord.setReturnCode(rc);
  173.      } /* end DATA BASE READ  */
  174.  
  175.     } /* end processing of suspect list for loop */
  176.  
  177.     //------------------------------------------------------
  178.     // Finished building suspect records. Build the result record
  179.     //------------------------------------------------------
  180.     resultRecord.setResultData(tempRecords);
  181.   } 
  182.   else
  183.   {
  184.   //   resultRecord.setReturnCode(rc);
  185.   }
  186.  return resultRecord;
  187.  
  188. }
  189.  
  190.  
  191.  
  192.  
  193. /*****************************************************************/ 
  194. /*                                                               */
  195. /* getAllAliases                                                 */
  196. /*                                                               */
  197. /*Function: Gets the list of aliases from  the database          */
  198. /*          using the book number from the suspect object        */
  199. /*                                                               */
  200. /*****************************************************************/
  201. IResultRecord getAllAliases(unsigned long bookNumber)
  202. {
  203.   IBoolean       firstAliasRecord = true;
  204.   unsigned short numberOfAddresses=1;    /*one address for driver 1                               */
  205.   char           anAliasName[ALIAS_NAME_LEN];
  206.   IString        tempBuffer;
  207.   IString        tempRecords;
  208.   IString        aliasVariableData;           /* accumulate the alias data to           */
  209.   IAliasRecord   aliasRecord;
  210.   IAliasRecord   tempAliasRecord;
  211.   IResultRecord  aliasResultRecord;
  212.   long           alRc;
  213.   long           numberOfAliases;
  214.   long           numberOfAliasResults;
  215.   long           aliasesToGo;
  216.  
  217. //-------------------------------------------------------------------------------
  218. // See how many alias records are in the
  219. // database and use that value to control their retrieval
  220. //-------------------------------------------------------------------------------
  221.     numberOfAliases =  howManyAliases(bookNumber);
  222.     numberOfAliasResults =  numberOfAliases;
  223.     aliasResultRecord.setNumResults(numberOfAliases);
  224.  
  225.     alRc = openAlC();                    // Open the alias table cursor
  226.     for (aliasesToGo = numberOfAliases;aliasesToGo > 0 ;aliasesToGo--)
  227.     {
  228.  
  229.      //--------------------------------------------
  230.      // Get the next alias record from the database
  231.      //--------------------------------------------
  232.      alRc = getNextAlias(anAliasName, bookNumber);
  233.      if (alRc == 0)
  234.      {
  235.        tempBuffer = anAliasName;
  236.        aliasRecord.setName(tempBuffer);
  237.  
  238.        //-----------------------------------------------------------------
  239.        // If this is the first alias record then copy it to a temporary
  240.        // area. Otherwise, append it to the temporary area
  241.        // When all records are copied/appended, copy the temporary
  242.        // alias record to the result record.
  243.        //-----------------------------------------------------------------
  244.        if (firstAliasRecord)
  245.        {
  246.         firstAliasRecord = false;
  247.         tempRecords = aliasRecord.asString();
  248.        }
  249.        else
  250.        {
  251.         tempRecords += aliasRecord.asString();
  252.        }
  253.      }
  254.      else 
  255.      {
  256. //        aliasResultRecord.setReturnCode(alRc);
  257.      } /* end DATA BASE READ  */
  258.  
  259.     } /* end processing of suspect list for-loop */
  260.  
  261.     alRc=closeAlC();            // close the alias table cursor
  262.  
  263.     //------------------------------------------------------
  264.     // Finished building alias records. Build the result record
  265.     //------------------------------------------------------
  266.     aliasResultRecord.setResultData(tempRecords);
  267.  return aliasResultRecord;
  268.  
  269. }
  270.  
  271.  
  272.  
  273.  
  274. /*****************************************************************/ 
  275. /*                                                               */
  276. /* getAllArrests                                                 */
  277. /*                                                               */
  278. /*Function: Gets the list of arrests from  the database          */
  279. /*          using the book number from the suspect object        */
  280. /*                                                               */
  281. /*****************************************************************/
  282. IResultRecord getAllArrests(unsigned long bookNumber)
  283. {
  284.   IBoolean              firstArrestRecord = true;
  285.   IString               tempBuffer;
  286.   IString               tempRecords;
  287.   IString               arrestVariableData;           /* accumulate the arrest data to           */
  288.   IArrestRecord         arrestRecord;
  289.   IArrestRecord         tempArrestRecord;
  290.   IResultRecord         arrestResultRecord;
  291.   long                  arRc;
  292.   long                  numberOfArrests;
  293.   long                  numberOfArrestResults;
  294.   long                  arrestsToGo;
  295.   ARREST_STRUCT         MyArs;
  296.  
  297. //-------------------------------------------------------------------------------
  298. // See how many arrest records are in the
  299. // database and use that value to control their retrieval
  300. //-------------------------------------------------------------------------------
  301.     numberOfArrests =  howManyArrests(bookNumber);
  302.     numberOfArrestResults =  numberOfArrests;
  303.     arrestResultRecord.setNumResults(numberOfArrests);
  304.  
  305.     arRc = openArC();             // Open the arrest table cursor
  306.  
  307.     for (arrestsToGo = numberOfArrests;arrestsToGo > 0 ;arrestsToGo--)
  308.     {
  309.      //---------------------------------------------
  310.      // Get the next arrest record from the database
  311.      //---------------------------------------------
  312.      arRc = getNextArrest(&MyArs, bookNumber);
  313.      if (arRc == 0)
  314.      {
  315.        arrestRecord.setCharge(MyArs.arrestCharge);
  316.        arrestRecord.setStatus(MyArs.arrestStatus);
  317.        arrestRecord.setStatusDate(MyArs.arrestDate);
  318.      //  arrestRecord.setReport(MyArs.arrestReport);
  319.  
  320.        /* setup resultRecord */
  321.  
  322.        //-----------------------------------------------------------------
  323.        // If this is the first arrest record then copy it to a temporary
  324.        // area. Otherwise, append it to the temporary area
  325.        // When all records are copied/appended, copy the temporary
  326.        // arrest record to the result record.
  327.        //-----------------------------------------------------------------
  328.        if (firstArrestRecord)
  329.        {
  330.         firstArrestRecord = false;
  331.         tempRecords = arrestRecord.asString();
  332.        }
  333.        else
  334.        {
  335.         tempRecords += arrestRecord.asString();
  336.        }
  337.      }
  338.      else 
  339.      {
  340.    //     arrestResultRecord.setReturnCode(arRc);
  341.      } /* end DATA BASE READ  */
  342.  
  343.     } /* end processing of suspect list for loop */
  344.  
  345.  
  346.     arRc = closeArC();             // close the arrest table cursor
  347.  
  348.     //------------------------------------------------------
  349.     // Finished building suspect records. Build the result record
  350.     //------------------------------------------------------
  351.     arrestResultRecord.setResultData(tempRecords);
  352.  return arrestResultRecord;
  353.  
  354. }
  355.  
  356.  
  357.  
  358. /*****************************************************************/ 
  359. /*                                                               */
  360. /* getAllLastSeen                                                */
  361. /*                                                               */
  362. /*Function: Gets the list of last seen reports from the database */
  363. /*          using the book number from the suspect object        */
  364. /*                                                               */
  365. /*****************************************************************/
  366. IResultRecord getAllLastSeen(unsigned long bookNumber)
  367. {
  368.   IBoolean              firstLastSeenRecord = true;
  369.   IString               tempBuffer;
  370.   IString               tempRecords;
  371.   IString               lastSeenVariableData;           /* accumulate the lastSeen data to           */
  372.   ILastSeenRecord       lastSeenRecord;
  373.   ILastSeenRecord       tempLastSeenRecord;
  374.   IResultRecord         lastSeenResultRecord;
  375.   long                  lsRc;
  376.   long                  numberOfLastSeens;
  377.   long                  numberOfLastSeenResults;
  378.   long                  lastSeensToGo;
  379.   LAST_SEEN_STRUCT      MyLSs;
  380.  
  381. //-------------------------------------------------------------------------------
  382. // See how many lastSeen records are in the
  383. // database and use that value to control their retrieval
  384. //-------------------------------------------------------------------------------
  385.     numberOfLastSeens =  howManyLastSeens(bookNumber);
  386.     numberOfLastSeenResults =  numberOfLastSeens;
  387.     lastSeenResultRecord.setNumResults(numberOfLastSeens);
  388.  
  389.     lsRc = openLsC();   // open the las seen cursor
  390.  
  391.     for (lastSeensToGo = numberOfLastSeens;lastSeensToGo > 0 ;lastSeensToGo--)
  392.     {
  393.      //---------------------------------------------
  394.      // Get the next lastSeen record from the database
  395.      //---------------------------------------------
  396.      lsRc = getNextLastSeen(&MyLSs, bookNumber);
  397.      if (lsRc == 0)
  398.      {
  399.        lastSeenRecord.setLocation(MyLSs.lastSeenLocation);
  400.        lastSeenRecord.setWitness(MyLSs.lastSeenWitness);
  401.        lastSeenRecord.setLastSeenDate(MyLSs.lastSeenDate);
  402.        lastSeenRecord.setStreet(MyLSs.lastSeenStreet);
  403.        lastSeenRecord.setCity(MyLSs.lastSeenCity);
  404.        lastSeenRecord.setState(MyLSs.lastSeenState);
  405.        lastSeenRecord.setComment(MyLSs.lastSeenComment);
  406.  
  407.        /* setup resultRecord */
  408.  
  409.        //-----------------------------------------------------------------
  410.        // If this is the first lastSeen record then copy it to a temporary
  411.        // area. Otherwise, append it to the temporary area
  412.        // When all records are copied/appended, copy the temporary
  413.        // lastSeen record to the result record.
  414.        //-----------------------------------------------------------------
  415.        if (firstLastSeenRecord)
  416.        {
  417.         firstLastSeenRecord = false;
  418.         tempRecords = lastSeenRecord.asString();
  419.        }
  420.        else
  421.        {
  422.         tempRecords += lastSeenRecord.asString();
  423.        }
  424.      }
  425.      else 
  426.      {
  427.     //    lastSeenResultRecord.setReturnCode(lsRc);
  428.      } /* end DATA BASE READ  */
  429.  
  430.     } /* end processing of suspect list for loop */
  431.  
  432.      lsRc = closeLsC();   // close the last seen cursor
  433.  
  434.     //------------------------------------------------------
  435.     // Finished building suspect records. Build the result record
  436.     //------------------------------------------------------
  437.     lastSeenResultRecord.setResultData(tempRecords);
  438.  return lastSeenResultRecord;
  439.  
  440. }
  441.  
  442.  
  443.  
  444. /*****************************************************************************
  445.  ! error(const char *message)
  446.  ! 
  447.  !   Display error message and exit.
  448.  *****************************************************************************/
  449. void error(const char *message)
  450. {
  451.    cout << "\n\nERROR: %s\n\n", message;
  452.    exit(1);
  453. }
  454.