home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dbutil.zip / BUFOP.ZIP / DBSTUFF.SQC < prev    next >
Text File  |  1993-10-08  |  3KB  |  115 lines

  1. #include "dbstuff.hpp"
  2. EXEC SQL INCLUDE 'dbstuff.sqh';
  3. EXEC SQL INCLUDE SQLCA;
  4.  
  5. /*******************************************************************
  6. *
  7. *  Database stuff to read table & column information
  8. *
  9. *******************************************************************/
  10.  
  11. char * column::getName(){
  12.     return name;
  13.     }
  14.     
  15. char column::getType(){
  16.     return type;
  17.     }
  18.     
  19. char * column::getRemarks(){
  20.    return remarks;
  21.    }
  22.    
  23. shor column::getLen(){
  24.     return len;}
  25.  
  26. short column::getColNbr(){
  27.     return colNbr();}
  28.     
  29.          
  30. ostream & operator <<(ostream & aStream, column const & aCol){
  31.  
  32.     aStream << name << " " 
  33.               << type << " "
  34.               << len     << " "
  35.               << remarks;
  36.     return aStream;
  37.     }
  38.     
  39. /*******************************************************************
  40. *
  41. *  Specify the tabe to use to find columns
  42. *
  43. *******************************************************************/
  44.     
  45. void colList::selectCol(char * tablename){
  46.     strcpy(name,tablename);
  47.     }
  48.  
  49. /*******************************************************************
  50. *
  51. *  Fill the container
  52. *
  53. *******************************************************************/
  54. columnSet & operator << (columnSet, colList & c){
  55.     
  56.     EXEC SQL DECLARE colCursor CURSOR FOR 
  57.     SELECT 
  58.       NAME,REMARKS,COLTYPE,NULLS,LENGTH,COLCARD,HIGH2KEY,LOW2KEY,
  59.       AVGCOLLEN,KEYSEQ
  60.     FROM SYSIBM.SYSCOLUMNS;
  61.         
  62.     EXEC SQL OPEN colCursor;
  63.     while( sqlca.scqcode = 0){
  64.         EXEC SQL FETCH colCursor
  65.             INTO
  66.                 :name,:remarks,:type,:nulls,:len,:colNbr,
  67.                 :highKey2,:lowKey2,:avgColLen,:keySeq;
  68.         
  69.             if( sqlca.sqlcode = 0){
  70.                   c.add(this);  
  71.             }    
  72.     }  // end while
  73.     EXEC SQL CLOSE colCursor;
  74.     EXEC SQL COMMIT WORK;
  75.     
  76.     return c;
  77.  }  // end fill container
  78.  
  79.  
  80. /*******************************************************************
  81. *
  82. *  read table by specifying the table name
  83. *
  84. *******************************************************************/
  85.  
  86. void  table::getTable(char * tablename) {
  87.     strcopy(name,tablename);
  88.     SELECT CREATOR,TYPE,CTIME,REMARKS,COLCOUNT,CARD    
  89.     PARENTS,CHILDREN,SELFREFS,KEYCOLUMNS 
  90.     INTO
  91.         :creator, :type, :ctime, :remarks,:nbrCols, 
  92.         :nbrRows, :parents, :children, :selfRefs, :keyCol;
  93.     FROM SYSIBM.SYSTABLES                  
  94.     WHERE NAME = :name;
  95. }
  96.  
  97. &operator <<(ostream & aStream, Table const & aTable) {
  98.   aStream << name << creator << type << remarks;
  99.   // all elements do 
  100.   return aStream;
  101.  
  102.  
  103. void bind(char * DBName) {
  104. sqlabind ("DBStuff.bnd",         /* program name */
  105.            DBName,                 /* database */
  106.            NULL,                     /* spare */
  107.            NULL,                     /* message file */
  108.            "USA",                     /* date/time format */
  109.            sqlca);                 /* SQLCA */
  110.  
  111.  
  112.  
  113.