home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bufop.zip / TESTPC.CPP < prev    next >
Text File  |  1993-09-06  |  2KB  |  92 lines

  1. #include <iostream.h>
  2. #include "tsta.hpp"
  3.  
  4. class printTest : public IIterator<testCls>   {
  5.  public:
  6.    virtual Boolean applyTo(testCls & p)
  7.          { cout << p << "\n\n "; return True;}
  8. };
  9.  
  10.  
  11.  
  12.  
  13. int  main(void)
  14.  {
  15.  
  16.    testCls a;
  17.    startit();   // start the database (in tsta)
  18.    a.create("Sally Smith", "101 Main st", 35, 101);
  19.    a.create("Fred Mac", "111 South North Ave", 46, 102);
  20.    a.create("Ed Ross" ,"1625 Red Mill",42,103);
  21.    a.create("Mary Smith", "1122 three st", 12,104);
  22.    a.create("George Garcia", "789 ten ave", 55, 105);
  23.    a.create("Darrell Crandel","101 nowhere",42,106);
  24.    a.create("Catherine Michell", "Rt 45",12,107);
  25.    a.create("Debra Jose","121 North",38,108);
  26.    a.read(101);
  27.    cout << a;
  28.    a.changeAge(34);
  29.    a.update();
  30.    a.read(102);
  31.    cout << a;
  32.    a.read(101);
  33.    cout << a;
  34.  
  35. //
  36. //  test the ability to read directly into a structure
  37. //
  38.  
  39.  stest * myStruct = new stest;    // create a new structure
  40.    readDB(myStruct);
  41.  
  42.  
  43.  
  44.  
  45. //
  46. //  these next examples require the IBM C/Set ++ & collection classes
  47. //
  48.  
  49. //
  50. // read a set of items based on dynamic selection (well - dynamic to
  51. // the SQL engine)
  52. //
  53.  
  54.   printTest printit;  // a class to print the elements
  55.  
  56.  
  57.   selectTest b;
  58.   nameSet setA;
  59.  
  60.   b.setSelect("ID > 103");  // get all records with ID > 3
  61.   setA << b;
  62.   cout << " Every one with a record ID > 103 \n";
  63.   setA.allElementsDo(printit);
  64.   setA.removeAll();    // clean up
  65.  
  66.   b.setSelect("age < 35");
  67.   cout << " All records with age < 35 ";
  68.   setA << b;
  69.   setA.allElementsDo(printit);
  70.   setA.removeAll();
  71.  
  72.  
  73.   b.setSelect("name like 'D%' ");
  74.   setA << b;
  75.   cout << "all records with the name starting with D \n";
  76.   setA.allElementsDo(printit);
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. //
  84. //  turn off the database and exit
  85. //
  86.  
  87.  
  88.    stopit();     // stop using the database (in tsta)
  89.    return 0;
  90. }
  91.  
  92.