home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / ipobuf.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  5.6 KB  |  145 lines

  1. /********************************************************************************/
  2. /* File:  ipobuf.hpp                                                            */
  3. /* Class: IPOBuffer                                                             */
  4. /*                                                                              */
  5. /* Abstract class IPOBuffer                                                     */
  6. /********************************************************************************/
  7.  
  8. /***********************************************
  9.  
  10.     Licensed Materials - Property of IBM
  11.  
  12.     5622-880   5801-AAR
  13.  
  14.     (c) Copyright IBM Corp 1991, 1996.
  15.  
  16. ************************************************/
  17.  
  18. #ifndef _IPOBUF_HPP_
  19. #define _IPOBUF_HPP_
  20.  
  21. #include <istring.hpp>
  22. #include "idssqlst.hpp"
  23. #include "idstype.hpp"
  24.  
  25. class _Export IPOBufferBase
  26. {
  27.    private:
  28.      Boolean fDataTruncated;
  29.      long lPrecision;
  30.      long lDataLength;
  31.      short sScale;
  32.  
  33.    public:
  34.      IPOBufferBase( Boolean aNull = true
  35.                   , long aLength = 0
  36.                   , long aPrecision = 0
  37.                   , short aScale = 0 );
  38.      virtual ~IPOBufferBase();
  39.  
  40.      virtual long theSqlCType() = 0;
  41.      virtual long theSqlType() = 0;
  42.  
  43.      // for the buffer to bind itself to the statement
  44.      void bindToColumn(short colNum, ISQLStatement* s);
  45.      void bindToParameter(short parmNum, ISQLStatement* s);
  46.  
  47. /*---------------------- PO Buffer Functions -----------------------------------
  48. | These methods deals with POBuffer functions:                                 |
  49. |   bindToColumn - bind column in result set                                   |
  50. |   bindToParameter - bind parameter marker                                    |
  51. |   bufferSize      - get buffer size                                          |
  52. |   buffer          - get buffer address                                       |
  53. |   setNull         - set null                                                 |
  54. |   setLength       - set data length                                          |
  55. |   setPrecision    - set precision                                            |
  56. |   setScale        - set scale                                                |
  57. |    ---------------------- Used after fetch ------------------------------    |
  58. |   length          - get amount of data read                                  |
  59. |   precision       - get the precision                                        |
  60. |   scale           - get the scale                                            |
  61. |   dataTruncated   - returns true if data has been truncated                  |
  62. |   dataNull        - returns true if data is null                             |
  63. ------------------------------------------------------------------------------*/
  64.  
  65.      // methods to get/set the buffer information
  66.      virtual size_t bufferSize() const = 0;
  67.      virtual void* buffer() const = 0;
  68.      void setNull( Boolean aNull = true);
  69.      void setLength( long aLength ) {lDataLength = aLength;}
  70.      void setPrecision(long i) {lPrecision = i;}
  71.      void setScale(short i) {sScale = i;}
  72.      long precision() const {return lPrecision;}
  73.      short scale() const {return sScale;}
  74.      long length() const {return lDataLength;}
  75.      virtual Boolean dataTruncated() const;
  76.      Boolean dataNull() const;
  77.  
  78. };
  79.  
  80. // CPPTYPE is the c++ data type of the buffer
  81. // SQLTYPE is the sql type in the DB
  82. // SQLCTYPE is the sql c type in the DB
  83.  
  84. template < class SQLTYPE, class SQLCTYPE, class CPPTYPE >
  85. class _Export IPONumericBuffer : public SQLTYPE, public SQLCTYPE, public IPOBufferBase
  86. {
  87.    private:
  88.      CPPTYPE theData;
  89.    public:
  90.      IPONumericBuffer( Boolean aNull = true
  91.                      , long aPrecision = 0
  92.                      , short aScale = 0 )
  93.          : IPOBufferBase(aNull,sizeof(CPPTYPE),aPrecision,aScale)
  94.          {}
  95.      ~IPONumericBuffer() {}
  96.      size_t bufferSize() const { return sizeof(theData); }
  97.      void* buffer() const { return (void*) &theData; }
  98.      long theSqlCType() { return SQLCTYPE::sqlCType(); }
  99.      long theSqlType() { return SQLTYPE::sqlType(); }
  100. };
  101.  
  102. template < class SQLTYPE, class SQLCTYPE, class CPPTYPE >
  103. class _Export IPOInBuffer : public SQLTYPE, public SQLCTYPE, public IPOBufferBase
  104. {
  105.   private:
  106.      long lBufferSize;
  107.      CPPTYPE* pBuffer;
  108.    public:
  109.      IPOInBuffer( long aNumberOfElements )
  110.          : IPOBufferBase(true)
  111.          , pBuffer(new CPPTYPE[aNumberOfElements])
  112.          , lBufferSize(sizeof(CPPTYPE)*aNumberOfElements)
  113.          {}
  114.      ~IPOInBuffer() { delete pBuffer; }
  115.      size_t bufferSize() const { return lBufferSize; }
  116.      void* buffer() const { return (void*) pBuffer; }
  117.      long theSqlCType() { return SQLCTYPE::sqlCType(); }
  118.      long theSqlType() { return SQLTYPE::sqlType(); }
  119. };
  120.  
  121. template < class SQLTYPE, class SQLCTYPE, class CPPTYPE >
  122. class _Export IPOOutBuffer : public SQLTYPE, public SQLCTYPE, public IPOBufferBase
  123. {
  124.   private:
  125.      long lBufferSize;
  126.      const CPPTYPE* pBuffer;
  127.    public:
  128.      IPOOutBuffer( const CPPTYPE* aBuffer,
  129.                    long aLength,
  130.                    Boolean aNull = false,
  131.                    long aPrecision = 0,
  132.                    short aScale = 0 )
  133.          : IPOBufferBase(aNull,aLength,aPrecision,aScale)
  134.          , lBufferSize(aLength)
  135.          , pBuffer(aBuffer)
  136.          {}
  137.      ~IPOOutBuffer(){}
  138.      size_t bufferSize() const { return lBufferSize; }
  139.      void* buffer() const { return (void*) pBuffer; }
  140.      long theSqlCType() { return SQLCTYPE::sqlCType(); }
  141.      long theSqlType() { return SQLTYPE::sqlType(); }
  142. };
  143.  
  144. #endif
  145.