home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dbutil.zip / BUFOP.ZIP / HOSTVARS.HPP < prev    next >
Text File  |  1993-09-11  |  4KB  |  110 lines

  1. #ifndef _HOSTVAR_
  2. #define _HOSTVAR_
  3. #include <IString.hpp>
  4. #include "pctypes.hpp"
  5. #include <fstream.h>
  6.  
  7.  
  8.  
  9. /*********************************************************************
  10. *  CPP SQL PRECOMPILER
  11. *     HOST VARIABLE ROUTINES
  12. *     extract host variables from source program(s)
  13. *     registar host variables with precompiler services
  14. *
  15. *  during the preparing of an SQL statement
  16. *     find host variable by name return ID
  17. *     create new host varaible(s) for SQLDA and nul indicators
  18. *     set the host variable prefix to support struct, pointers and class
  19. *
  20. *  during the generation of code
  21. *     find host variable by ID
  22. *     restore prefix to host variable
  23. *     generate SetV
  24. *
  25. *
  26. *********************************************************************/
  27.  
  28. Boolean InDeclare();            // returns true if in a SQL declare section
  29. void setDeclare(Boolean B);
  30.  
  31. void initSQLTypes();
  32. void processDeclare(IString & sqlstring);  // add a variable to list
  33.  
  34. class Variable
  35. {
  36. public:
  37.     //  constructors
  38.     Variable();
  39.     Variable(IString & theName, int Thelen, int theType, Boolean anObj=false);
  40.      Variable(IString & theName);
  41.     ~Variable();
  42.  
  43.      //  operator definitions
  44. inline Boolean  operator ==(Variable const & V)const {return (name == V.name);}
  45.     Variable & operator=(Variable const & v);   
  46.  
  47. friend ostream& operator<<(ostream & os, Variable & V);
  48.  
  49.  void registerHV();                               // register the hostvar
  50.  void setName(const IString & thename);
  51.  void setV(unsigned short sqlaID, unsigned short idx,ofstream & fout);
  52.  void setVNull(unsigned short sqlaID, unsigned short idx,ofstream & fout, 
  53.        int nullID);
  54.  IString Variable:: getFullName();
  55.  
  56. inline    void setID()                                   {ID = ++nxtID;}
  57. inline   void changeID(int theID)              {ID = theID;}
  58. inline   void setLen(int theLen)               {len = theLen;}
  59. inline    void setType(int theType)             {type = theType;}
  60. inline    void setPointer(Boolean p = true)     {aPointer = p;}
  61. inline    void setPrefix(IString const & thePrefix) {prefix = thePrefix;}
  62. inline    IString const & getName() const       {return name;}          
  63. inline    IString const & getPrefix() const     {return prefix;}
  64. inline    IString const & getTypeName() const   {return vTypeTxt;}
  65. inline    int  getLen()                         {return len;}
  66. inline    int  getType()                        {return type;}
  67. inline    unsigned long  getID()                          {return ID;}
  68. inline    Boolean isaPointer()                  {return aPointer;}
  69.  
  70.   void setDefaults(Vtype const & V );
  71.   void setUnknown();
  72.  
  73.  
  74. private:
  75.     IString name;       // Variable name
  76.     unsigned short   len;        // Variable length
  77.     unsigned short   type;       // Databsse type
  78.     Boolean Obj;        // set true if processing an object
  79.     unsigned long ID;         // used by variable array
  80.     Boolean aPointer;   // this var is a pointer to type
  81.     IString prefix;      // prefix (in support of struct and class)
  82.     IString vTypeTxt;       // variable type in text format - for debugging
  83.     Boolean IsObject;
  84. static unsigned long nxtID;   // next ID number to assign
  85. };
  86.  
  87.  
  88.  
  89.  
  90. /********************************************************************
  91. *  supporting functions
  92. ********************************************************************/
  93. // given a host variable name - get the ID
  94.  
  95. Variable * getVarByName(IString const & theName); // return the variable
  96.  
  97.  
  98. // given an ID, get the variable
  99. Variable & getVarByID(long theID);
  100.  
  101. void dumpVars();            // debug to dump all variables
  102.  
  103.  
  104.  
  105.  
  106. inline IString const & key (Variable const & V){
  107.     return V.getName();
  108. }
  109. #endif
  110.