home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bufop.zip / TSTA.SQH < prev   
Text File  |  1993-09-10  |  3KB  |  123 lines

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