home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bufop.zip / TSTA.HPP < prev    next >
C/C++ Source or Header  |  1993-09-11  |  3KB  |  127 lines

  1. // 
  2. // processed by precompiler  09-11-93  09:32:24
  3. // 
  4. #include <iostream.h>
  5. #include <iksbag.h>
  6.  
  7.  
  8. //
  9. //  This is a source sql file
  10. //  it will be transformed into "tsta.hpp"
  11. //
  12.  
  13.  
  14.  
  15.  
  16. class testCls
  17. {
  18. public:
  19.   testCls ();
  20.   ~testCls();
  21.   create( char * name, char * Addr, int age, int id);  // init and create
  22.   create();  // create with whats in the record
  23.   insertDBRec();
  24.   changeName(char * name);
  25.   changeID(int id);
  26.   changeAge(int age);
  27.   read(int recID);
  28.   update();
  29.  
  30. //  Assigment
  31.  
  32. testCls & operator=(testCls const & a);
  33.  
  34.  
  35.  
  36. friend ostream
  37.  &operator <<(ostream & aStream, testCls const & arec);
  38.  
  39.  
  40. inline  Boolean operator == (char * n)const  {return strcmp(name,n);}
  41. inline char * const & getName()const  {return pn;}
  42.  
  43. protected:
  44.  
  45. //###  EXEC SQL BEGIN DECLARE SECTION;
  46.   char * pn;            // pointer to name (needed for key access in container)
  47.  char name[40];
  48.  char addr[60];
  49.  int age;
  50.  unsigned short nullInd;
  51.  int recID;
  52.  
  53. //###  EXEC  SQL END DECLARE SECTION;
  54.   };  // end of class testCls
  55.  
  56.  
  57. //
  58. //  support functions
  59. //
  60.  
  61. void startit();
  62. void stopit();
  63.  
  64.  
  65.  
  66. //========================================================
  67. //   define a collection (Key Sorted Set) of the elements
  68. //  use SQL select to get all entries from the table and
  69. //  store them in the collection
  70. //  Notice - the testCls elements (which are protected) are used in the
  71. //  the inherited class.
  72. //=============================================================
  73.  
  74.  
  75. typedef IKeySortedBag<testCls,char *> nameSet;
  76.  
  77. class selectTest : public testCls         // derived from testcla
  78. {
  79. //
  80. // use the overload << function to place elements into
  81. // the collection
  82. // could use the overload >> function to add/update elements
  83. // in the collection
  84. //
  85.  
  86. public:
  87.   selectTest();
  88.   selectTest(char * const & selectStr);
  89.   setSelect(char * const & selectStr);
  90.  
  91. //
  92. // overload the << to fill the container
  93. //
  94. friend
  95.   nameSet & operator<<(nameSet & aset, selectTest & s);
  96.  
  97.  
  98. //### EXEC SQL BEGIN DECLARE SECTION;
  99.  private:
  100.    char theSelectStr[800];
  101.  
  102. //### EXEC SQL END DECLARE SECTION;
  103.  };
  104.  
  105.  
  106. //
  107. //  key access needed for collection class
  108. //
  109. inline char *  const & key(testCls const & a) {return a.getName();}
  110.  
  111.  
  112. //==================================================
  113. //  read/write into/out of structures
  114. //====================================================
  115.  
  116. //### EXEC SQL BEGIN DECLARE SECTION;
  117.  struct stest {
  118.   char sname[40];
  119.   char saddr[80];
  120.   int sage;
  121. };
  122.  
  123. //### EXEC SQL END DECLARE SECTION;
  124.  
  125. void readDB(stest * );   // read indirect using pointer
  126. void readDB(stest * );   // read indirect using pointer
  127.