home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sqlcla.zip / SQL.HPP < prev    next >
C/C++ Source or Header  |  1993-07-15  |  3KB  |  110 lines

  1. /* (C) Copyright Stephen B. Behman, 1993 -- All rights reserved. */
  2. // $Header: d:/sh/RCS/sql.hpp 2.0 93/07/14 09:42:53 Steve Exp $
  3.  
  4. #ifndef __SQL_HPP__
  5. #define __SQL_HPP__
  6.  
  7. #pragma pack(1)
  8. struct SQLCA
  9. {
  10.    unsigned char  sqlcaid[8];        /* Eyecatcher = 'SQLCA   ' */
  11.    long       sqlcabc;        /* SQLCA size in bytes = 136 */
  12.    long       sqlcode;        /* SQL return code */
  13.    short      sqlerrml;        /* Length for SQLERRMC */
  14.    unsigned char  sqlerrmc[70];     /* Error message tokens */
  15.    unsigned char  sqlerrp[8];        /* Diagnostic information */
  16.    long       sqlerrd[6];        /* Diagnostic information */
  17.    unsigned char  sqlwarn[11];        /* Warning flags */
  18.    unsigned char  sqlstate[5];        /* State corresponding to SQLCODE */
  19. };
  20. #pragma pack()
  21.  
  22. static SQLCA sqlca;
  23.  
  24. class DATABASE
  25.   {
  26.    static int started;
  27.   public:
  28.    DATABASE( char * dbname, unsigned char db_usage, SQLCA* sqlca);
  29.    int isstarted();
  30.    long COMMIT( SQLCA* sqlca, char* pid  );
  31.    long ROLLBACK( SQLCA* sqlca, char* pid  );
  32.   };
  33.  
  34.  
  35. #pragma pack( 1 )
  36. struct SQLVAR
  37.   {
  38.    short      sqltype;         /* Variable data type */
  39.    short      sqllen;         /* Variable data length */
  40.    void  * _Seg16  sqldata;          /* Pointer to variable data value */
  41.    short * _Seg16  sqlind;         /* Pointer to Null indicator */
  42.    struct sqlname             /* Variable Name */
  43.      {
  44.       short         length;         /* Name length [1..30] */
  45.       unsigned char  data[30];         /* Variable or Column name */
  46.      }    sqlname;
  47.   };
  48.  
  49. struct Sqlda
  50.   {
  51.    char  sqldaid[8];            /* Eye catcher = 'SQLDA   ' */
  52.    long       sqldabc;        /* SQLDA size in bytes = 16+44*SQLN */
  53.    short      sqln;         /* Number of SQLVAR elements */
  54.    short      sqld;         /* # of used SQLVAR elements */
  55.    SQLVAR sqlvar[1];
  56.   };
  57.  
  58. #pragma pack( )
  59.  
  60. class SQLDA
  61.   {
  62.    static short nosqldas;          // counter used to name sqlda's
  63.    short sqlid;               // number for this sqlda
  64.    Sqlda *ada;                  // actual sqlda
  65.   public:
  66.    SQLDA( char *t,short noargs );
  67.    ~SQLDA(){ delete [] ada; }
  68.    void setv( int i, short tp, short ln, void *da, short *ind );
  69.    inline short id(){ return sqlid; }
  70.    SQLVAR* var(  ){return ( SQLVAR* )&ada->sqlvar;}
  71.   };
  72.  
  73.  
  74. class CURSOR
  75.   {
  76.    SQLDA outda;
  77.    SQLDA inda;
  78.    SQLCA *ca;
  79.    unsigned char *top;
  80.    short stmntno;
  81.   public:
  82.    CURSOR( SQLCA* c,unsigned char * t,short sno, short nooargs,
  83.        short noinargs, ...);
  84.  
  85.    long close();
  86.    long fetch();
  87.    long open();
  88.    SQLVAR* invars(  );
  89.    SQLVAR* outvars(  );
  90.   };
  91.  
  92.  
  93. class QUERY
  94.   {
  95.    SQLDA outda;
  96.    SQLDA inda;
  97.    SQLCA *ca;
  98.    unsigned char *top;
  99.    short stmntno;
  100.    unsigned short action;
  101.   public:
  102.    QUERY( SQLCA* c, unsigned char * t, short sno, unsigned short act,
  103.          short nooargs, short noinargs,... );
  104.    long exec();
  105.    SQLVAR * invars(){return inda.var();}
  106.    SQLVAR * outvars(){return outda.var();}
  107.   };
  108.  
  109. #endif
  110.