1 /***********************************************************************/
2 /*  PLGODBC.H - This is the ODBC PlugDB driver include file.           */
3 /***********************************************************************/
4 //efine WINVER 0x0300 // prevent Windows 3.1 feature usage
5 #include <windows.h>                           /* Windows include file */
6 #include <windowsx.h>                          /* Message crackers     */
7 #include <commctrl.h>
8 
9 /***********************************************************************/
10 /*  Included C-definition files required by the interface.             */
11 /***********************************************************************/
12 #include <string.h>                  /* String manipulation declares   */
13 #include <stdlib.h>                  /* C standard library             */
14 #include <ctype.h>                   /* C language specific types      */
15 #include <stdio.h>                   /* FOPEN_MAX   declaration        */
16 #include <time.h>                    /* time_t type declaration        */
17 
18 /***********************************************************************/
19 /*  ODBC interface of PlugDB driver declares.                          */
20 /***********************************************************************/
21 #include "podbcerr.h"                /* Resource ID for PlugDB Driver  */
22 #if !defined(WIN32)
23 #include "w16macro.h"
24 #endif
25 
26 #define ODBCVER    0x0300
27 
28 #include "sqltypes.h"
29 #include "sql.h"
30 #include "sqlext.h"
31 
32 /***********************************************************************/
33 /*  Definitions to be used in function prototypes.                     */
34 /*  The SQL_API is to be used only for those functions exported for    */
35 /*    driver manager use.                                              */
36 /*  The EXPFUNC is to be used only for those functions exported but    */
37 /*    used internally, ie, dialog procs.                               */
38 /*  The INTFUNC is to be used for all other functions.                 */
39 /***********************************************************************/
40 #if defined(WIN32)
41 #define INTFUNC  __stdcall
42 #define EXPFUNC  __stdcall
43 #else
44 #define INTFUNC FAR PASCAL
45 #define EXPFUNC __export CALLBACK
46 #endif
47 
48 /***********************************************************************/
49 /*  External variables.                                                */
50 /***********************************************************************/
51 extern HINSTANCE NEAR s_hModule;  // DLL handle.
52 #ifdef DEBTRACE
53 extern FILE *debug;
54 #endif
55 extern bool clearerror;
56 
57 /***********************************************************************/
58 /*  Additional values used by PlugDB for ODBC.                         */
59 /***********************************************************************/
60 #define RES_TYPE_PREPARE       1        /* Result from SQLPrepare      */
61 #define RES_TYPE_CATALOG       2        /* Result from catalog funcs   */
62 #define MAXPATHLEN     _MAX_PATH        /* Max path length             */
63 #define MAXKEYLEN             16        /* Max keyword length          */
64 #define MAXDESC              256        /* Max description length      */
65 #define MAXDSNAME             33        /* Max data source name length */
66 #define MAXCRNAME             18        /* Max stmt cursor name length */
67 #define DEFMAXRES           6300        /* Default MaxRes value        */
68 #define NAM_LEN              128        /* Length of col and tab names */
69 
70 #define MAXRESULT           1000        /* ? */
71 #define MAXCOMMAND           200        /* ? */
72 #define RC_ERROR       RC_LAST-1
73 #define RC_FREE                3
74 
75 #if !defined(NOLIB)
76 #define CNXKEY         uint             /* C Key returned by Conn DLL  */
77 #else
78 typedef struct _conninfo *PCONN;
79 #endif   /* !NOLIB */
80 
81 #if defined(DEBTRACE)
82 #define TRACE0(X)              fprintf(debug,X);
83 #define TRACE1(X,A)            fprintf(debug,X,A);
84 #define TRACE2(X,A,B)          fprintf(debug,X,A,B);
85 #define TRACE3(X,A,B,C)        fprintf(debug,X,A,B,C);
86 #define TRACE4(X,A,B,C,D)      fprintf(debug,X,A,B,C,D);
87 #define TRACE5(X,A,B,C,D,E)    fprintf(debug,X,A,B,C,D,E);
88 #define TRACE6(X,A,B,C,D,E,F)  fprintf(debug,X,A,B,C,D,E,F);
89 #else    /* !DEBTRACE*/
90 #define TRACE0(X)
91 #define TRACE1(X,A)
92 #define TRACE2(X,A,B)
93 #define TRACE3(X,A,B,C)
94 #define TRACE4(X,A,B,C,D)
95 #define TRACE5(X,A,B,C,D,E)
96 #define TRACE6(X,A,B,C,D,E,F)
97 #endif  /* !DEBTRACE*/
98 
99 // This definition MUST be identical to the value in plgdbsem.h
100 #define XMOD_PREPARE  1
101 
102 /***********************************************************************/
103 /*  ODBC.INI keywords (use extern definition in SETUP.C)               */
104 /***********************************************************************/
105 extern char const *EMPTYSTR;              /* Empty String              */
106 extern char const *OPTIONON;
107 extern char const *OPTIONOFF;
108 extern char const *INI_SDEFAULT;          /* Default data source name  */
109 extern char const *ODBC_INI;              /* ODBC initialization file  */
110 extern char const *INI_KDEFL;             /* Is SQL to use by default? */
111 extern char const *INI_KLANG;             /* Application language      */
112 extern char const *INI_KDATA;             /* Data description file     */
113 extern char const *INI_KSVR;              /* PLG Server                */
114 
115 /************************************************************************/
116 /*  Attribute key indexes (into an array of Attr structs, see below)    */
117 /************************************************************************/
118 #define KEY_DSN         0
119 #define KEY_DEFL        1
120 #define KEY_LANG        2
121 #define KEY_DATA        3
122 #define KEY_SERVER      4
123 #define LAST_KEY        5                 /* Number of keys in TAG's   */
124 #define KEY_DESC        5
125 #define KEY_TRANSNAME   6
126 #define KEY_TRANSOPTION 7
127 #define KEY_TRANSDLL    8
128 #define NUMOFKEYS       9                 /* Number of keys supported   */
129 
130 #define FOURYEARS    126230400    // Four years in seconds (1 leap)
131 
132 /***********************************************************************/
133 /*  This is used when an "out of memory" error happens, because this   */
134 /*  error recording system allocates memory when it logs an error,     */
135 /*  and it would be bad if it tried to allocate memory when it got an  */
136 /*  out of memory error.                                               */
137 /***********************************************************************/
138 typedef enum _ERRSTAT {
139   errstatOK,
140   errstatNO_MEMORY,
141   } ERRSTAT;
142 
143 /***********************************************************************/
144 /*  Types                                                              */
145 /***********************************************************************/
146 typedef struct TagAttr {
147   bool fSupplied;
148   char Attr[MAXPATHLEN];
149   } TAG, *PTAG;
150 
151 typedef struct _parscons {              /* Parse constants             */
152   int  Slen;                            /* String length               */
153   int  Ntag;                            /* Number of entries in tags   */
154   int  Nlook;                           /* Number of entries in lookup */
155   char Sep;                             /* Separator                   */
156   } PARC, *PPARC;
157 
158 /***********************************************************************/
159 /*  Attribute string look-up table (maps keys to associated indexes)   */
160 /***********************************************************************/
161 typedef struct _Look {
162   const char *szKey;
163   int         iKey;
164   } LOOK, *PLOOK;
165 
166 /***********************************************************************/
167 /*  This is info about a single error.                                 */
168 /***********************************************************************/
169 typedef struct _ERRBLK  *PERRBLK;
170 
171 typedef struct _ERRBLK {
172   PERRBLK Next;           /* Next block in linked list of error blocks */
173   DWORD   Native_Error;                                /* Native error */
174   DWORD   Stderr;                                   /* SQLC error code */
175   PSZ     Message;                        /* Points to text of message */
176   } ERRBLK;
177 
178 /***********************************************************************/
179 /*  This is a header block, it records information about a list of     */
180 /*  errors (ERRBLOCK's).                                               */
181 /***********************************************************************/
182 typedef struct _ERRINFO {
183   PERRBLK First;        /* First block in linked list of error blocks. */
184   PERRBLK Last;         /* Last block in above list.                   */
185   ERRSTAT Errstat;      /* Status for special condition out of memory  */
186   } ERRINFO, *PERRINFO;
187 
188 /***********************************************************************/
189 /*  Environment information.                                           */
190 /***********************************************************************/
191 typedef struct _env {
192   ERRINFO Errinfo;                                       /* Error list */
193   UDWORD ODBCver;
194   UDWORD ODBCdateformat;
195   } ENV,  *PENV;
196 
197 /***********************************************************************/
198 /*  Classes used in the PlugDB ODBC Driver.                            */
199 /***********************************************************************/
200 typedef class DBC        *PDBC;
201 typedef class STMT       *PSTMT;
202 typedef class CURSOR     *PCURSOR;
203 typedef class RESULT     *PRESULT;
204 typedef class BINDDATA   *PBIND;
205 typedef class BINDPARM   *PBDPARM;
206 typedef class CPLGdrv    *PSCDRV;
207 typedef class DESCRIPTOR *PDSC;
208 
209 /***********************************************************************/
210 /*  ODBC Prototypes.                                                   */
211 /***********************************************************************/
212 void    PostSQLError(HENV, HDBC, HSTMT, DWORD, DWORD, PSZ);
213 void    ClearSQLError(HENV, HDBC, HSTMT);
214 short   LoadRcString(UWORD, LPSTR, short);
215 RETCODE RetcodeCopyBytes(HDBC, HSTMT, UCHAR FAR *, SWORD,
216                          SWORD FAR *, UCHAR FAR *, SWORD, bool);
217 
218 /***********************************************************************/
219 /*  Private functions used by the driver.                              */
220 /***********************************************************************/
221 bool    EXPFUNC FDriverConnectProc(HWND, WORD, WPARAM, LPARAM);
222 extern  void    ParseAttrString(PLOOK, PTAG, UCHAR FAR *, PPARC);
223 RETCODE PASCAL  StringCopy(HDBC, HSTMT, PTR, SWORD, SWORD FAR *,
224                                                      char FAR *);
225 RETCODE PASCAL  ShortCopy(HDBC, HSTMT, PTR, SWORD, SWORD FAR *, short);
226 RETCODE PASCAL  LongCopy(HDBC, HSTMT, PTR, SWORD, SWORD FAR *, int);
227 RETCODE PASCAL  GeneralCopy(HDBC, HSTMT, PTR, SWORD,
228                             SWORD FAR *, PTR, SWORD);
229 
230 /* --------------------- End of PLGODBC.H ---------------------------- */
231