1 /*************************************************************
2  * sqltypes.h
3  *
4  * This is the lowest level include in unixODBC. It defines
5  * the basic types required by unixODBC and is heavily based
6  * upon the MS include of the same name (it has to be for
7  * binary compatability between drivers developed under different
8  * packages).
9  *
10  * You can include this file directly but it is almost always
11  * included indirectly, by including.. for example sqlext.h
12  *
13  * This include makes no effort to be usefull on any platforms other
14  * than Linux (with some exceptions for UNIX in general).
15  *
16  * !!!DO NOT CONTAMINATE THIS FILE WITH NON-Linux CODE!!!
17  *
18  *************************************************************/
19 #ifndef __SQLTYPES_H
20 #define __SQLTYPES_H
21 
22 /****************************
23  * default to the 3.80 definitions. should define ODBCVER before here if you want an older set of defines
24  ***************************/
25 #ifndef ODBCVER
26 #define ODBCVER	0x0380
27 #endif
28 
29 /*
30  * if thi sis set, then use a 4 byte unicode definition, insteead of the 2 bye that MS use
31  */
32 
33 #ifdef SQL_WCHART_CONVERT
34 /*
35  * Use this if you want to use the C/C++ portable definition of  a wide char, wchar_t
36  *  Microsoft hardcoded a definition of  unsigned short which may not be compatible with
37  *  your platform specific wide char definition.
38  */
39 #include <wchar.h>
40 #endif
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /*
47  * this is defined by configure, but will not be on a normal application build
48  * the install creates a unixodbc_conf.h file that contains the current build settings
49  */
50 
51 #ifndef SIZEOF_LONG_INT
52 #include "unixodbc_conf.h"
53 #endif
54 
55 #ifndef SIZEOF_LONG_INT
56 #error "Needs to know how big a long int is to continue!!!"
57 #endif
58 
59 /****************************
60  * These make up for having no windows.h
61  ***************************/
62 #ifndef ALLREADY_HAVE_WINDOWS_TYPE
63 
64 #define FAR
65 #define CALLBACK
66 #ifdef __OS2__
67 #define SQL_API _System
68 #else
69 #define SQL_API
70 #endif
71 #define	BOOL				int
72 #ifndef _WINDOWS_
73 typedef void*				HWND;
74 #endif
75 typedef char				CHAR;
76 #ifdef UNICODE
77 
78 /*
79  * NOTE: The Microsoft unicode define is only for apps that want to use TCHARs and
80  *  be able to compile for both unicode and non-unicode with the same source.
81  *  This is not recommanded for linux applications and is not supported
82  * 	by the standard linux string header files.
83  */
84 #ifdef SQL_WCHART_CONVERT
85 typedef wchar_t             TCHAR;
86 #else
87 typedef signed short        TCHAR;
88 #endif
89 
90 #else
91 typedef char				TCHAR;
92 #endif
93 
94 typedef unsigned short		WORD;
95 #if (SIZEOF_INT == 2)
96 typedef unsigned long		DWORD;
97 #else
98 typedef unsigned int		DWORD;
99 #endif
100 typedef unsigned char		BYTE;
101 
102 #ifdef SQL_WCHART_CONVERT
103 typedef wchar_t             WCHAR;
104 #else
105 typedef unsigned short 		WCHAR;
106 #endif
107 
108 typedef WCHAR* 	            LPWSTR;
109 typedef const char*         LPCSTR;
110 typedef const WCHAR*        LPCWSTR;
111 typedef TCHAR*              LPTSTR;
112 typedef char*               LPSTR;
113 typedef DWORD*           	LPDWORD;
114 
115 #ifndef _WINDOWS_
116 typedef void*               HINSTANCE;
117 #endif
118 
119 #endif
120 
121 
122 /****************************
123  * standard SQL* data types. use these as much as possible when using ODBC calls/vars
124  ***************************/
125 typedef unsigned char   SQLCHAR;
126 
127 #if (ODBCVER >= 0x0300)
128 typedef unsigned char   SQLDATE;
129 typedef unsigned char   SQLDECIMAL;
130 typedef double          SQLDOUBLE;
131 typedef double          SQLFLOAT;
132 #endif
133 
134 /*
135  * can't use a long it fails on 64 platforms
136  */
137 
138 /*
139  * Hopefully by now it should be safe to assume most drivers know about SQLLEN now
140  * and the defaukt is now sizeof( SQLLEN ) = 8 on 64 bit platforms
141  *
142  */
143 
144 #if (SIZEOF_LONG_INT == 8)
145 #ifdef BUILD_LEGACY_64_BIT_MODE
146 typedef int             SQLINTEGER;
147 typedef unsigned int    SQLUINTEGER;
148 #define SQLLEN          SQLINTEGER
149 #define SQLULEN         SQLUINTEGER
150 #define SQLSETPOSIROW   SQLUSMALLINT
151 /*
152  * These are not supprted on 64bit ODBC according to MS, removed, so use at your peril
153  *
154  typedef SQLULEN         SQLROWCOUNT;
155  typedef SQLULEN         SQLROWSETSIZE;
156  typedef SQLULEN         SQLTRANSID;
157  typedef SQLLEN          SQLROWOFFSET;
158 */
159 #else
160 typedef int             SQLINTEGER;
161 typedef unsigned int    SQLUINTEGER;
162 typedef long            SQLLEN;
163 typedef unsigned long   SQLULEN;
164 typedef unsigned long   SQLSETPOSIROW;
165 /*
166  * These are not supprted on 64bit ODBC according to MS, removed, so use at your peril
167  *
168  typedef SQLULEN 		SQLTRANSID;
169  typedef SQLULEN 		SQLROWCOUNT;
170  typedef SQLUINTEGER 	SQLROWSETSIZE;
171  typedef SQLLEN 		SQLROWOFFSET;
172  */
173 #endif
174 #else
175 #if SIZEOF_INT < 4
176 typedef long            SQLINTEGER;
177 typedef unsigned long   SQLUINTEGER;
178 #else
179 typedef int             SQLINTEGER;
180 typedef unsigned int    SQLUINTEGER;
181 #endif
182 #define SQLLEN          SQLINTEGER
183 #define SQLULEN         SQLUINTEGER
184 #define SQLSETPOSIROW   SQLUSMALLINT
185 typedef SQLULEN         SQLROWCOUNT;
186 typedef SQLULEN         SQLROWSETSIZE;
187 typedef SQLULEN         SQLTRANSID;
188 typedef SQLLEN          SQLROWOFFSET;
189 #endif
190 
191 #if (ODBCVER >= 0x0300)
192 typedef unsigned char   SQLNUMERIC;
193 #endif
194 
195 typedef void *          SQLPOINTER;
196 
197 #if (ODBCVER >= 0x0300)
198 typedef float           SQLREAL;
199 #endif
200 
201 typedef signed short int   SQLSMALLINT;
202 typedef unsigned short  SQLUSMALLINT;
203 
204 #if (ODBCVER >= 0x0300)
205 typedef unsigned char   SQLTIME;
206 typedef unsigned char   SQLTIMESTAMP;
207 typedef unsigned char   SQLVARCHAR;
208 #endif
209 
210 typedef SQLSMALLINT     SQLRETURN;
211 
212 #if (ODBCVER >= 0x0300)
213 typedef void * 			        SQLHANDLE;
214 typedef SQLHANDLE               SQLHENV;
215 typedef SQLHANDLE               SQLHDBC;
216 typedef SQLHANDLE               SQLHSTMT;
217 typedef SQLHANDLE               SQLHDESC;
218 #else
219 typedef void *                  SQLHENV;
220 typedef void *                  SQLHDBC;
221 typedef void *                  SQLHSTMT;
222 /*
223  * some things like PHP won't build without this
224  */
225 typedef void * 			        SQLHANDLE;
226 #endif
227 
228 /****************************
229  * These are cast into the actual struct that is being passed around. The
230  * DriverManager knows what its structs look like and the Driver knows about its
231  * structs... the app knows nothing about them... just void*
232  * These are deprecated in favour of SQLHENV, SQLHDBC, SQLHSTMT
233  ***************************/
234 
235 #if (ODBCVER >= 0x0300)
236 typedef SQLHANDLE          		HENV;
237 typedef SQLHANDLE          		HDBC;
238 typedef SQLHANDLE          		HSTMT;
239 #else
240 typedef void *          	    HENV;
241 typedef void *          	    HDBC;
242 typedef void *          	    HSTMT;
243 #endif
244 
245 
246 /****************************
247  * more basic data types to augment what windows.h provides
248  ***************************/
249 #ifndef ALLREADY_HAVE_WINDOWS_TYPE
250 
251 typedef unsigned char           UCHAR;
252 typedef signed char             SCHAR;
253 typedef SCHAR                   SQLSCHAR;
254 #if (SIZEOF_LONG_INT == 4)
255 typedef long int                SDWORD;
256 typedef unsigned long int       UDWORD;
257 #else
258 typedef int                     SDWORD;
259 typedef unsigned int            UDWORD;
260 #endif
261 typedef signed short int        SWORD;
262 typedef unsigned short int      UWORD;
263 typedef unsigned int            UINT;
264 typedef signed long             SLONG;
265 typedef signed short            SSHORT;
266 typedef unsigned long           ULONG;
267 typedef unsigned short          USHORT;
268 typedef double                  SDOUBLE;
269 typedef double            		LDOUBLE;
270 typedef float                   SFLOAT;
271 typedef void*              		PTR;
272 typedef signed short            RETCODE;
273 typedef void*                   SQLHWND;
274 
275 #endif
276 
277 /****************************
278  * standard structs for working with date/times
279  ***************************/
280 #ifndef	__SQLDATE
281 #define	__SQLDATE
282 typedef struct tagDATE_STRUCT
283 {
284         SQLSMALLINT    year;
285         SQLUSMALLINT   month;
286         SQLUSMALLINT   day;
287 } DATE_STRUCT;
288 
289 #if (ODBCVER >= 0x0300)
290 typedef DATE_STRUCT	SQL_DATE_STRUCT;
291 #endif
292 
293 typedef struct tagTIME_STRUCT
294 {
295         SQLUSMALLINT   hour;
296         SQLUSMALLINT   minute;
297         SQLUSMALLINT   second;
298 } TIME_STRUCT;
299 
300 #if (ODBCVER >= 0x0300)
301 typedef TIME_STRUCT	SQL_TIME_STRUCT;
302 #endif
303 
304 typedef struct tagTIMESTAMP_STRUCT
305 {
306         SQLSMALLINT    year;
307         SQLUSMALLINT   month;
308         SQLUSMALLINT   day;
309         SQLUSMALLINT   hour;
310         SQLUSMALLINT   minute;
311         SQLUSMALLINT   second;
312         SQLUINTEGER    fraction;
313 } TIMESTAMP_STRUCT;
314 
315 #if (ODBCVER >= 0x0300)
316 typedef TIMESTAMP_STRUCT	SQL_TIMESTAMP_STRUCT;
317 #endif
318 
319 
320 #if (ODBCVER >= 0x0300)
321 typedef enum
322 {
323 	SQL_IS_YEAR						= 1,
324 	SQL_IS_MONTH					= 2,
325 	SQL_IS_DAY						= 3,
326 	SQL_IS_HOUR						= 4,
327 	SQL_IS_MINUTE					= 5,
328 	SQL_IS_SECOND					= 6,
329 	SQL_IS_YEAR_TO_MONTH			= 7,
330 	SQL_IS_DAY_TO_HOUR				= 8,
331 	SQL_IS_DAY_TO_MINUTE			= 9,
332 	SQL_IS_DAY_TO_SECOND			= 10,
333 	SQL_IS_HOUR_TO_MINUTE			= 11,
334 	SQL_IS_HOUR_TO_SECOND			= 12,
335 	SQL_IS_MINUTE_TO_SECOND			= 13
336 } SQLINTERVAL;
337 
338 #endif
339 
340 #if (ODBCVER >= 0x0300)
341 typedef struct tagSQL_YEAR_MONTH
342 {
343 		SQLUINTEGER		year;
344 		SQLUINTEGER		month;
345 } SQL_YEAR_MONTH_STRUCT;
346 
347 typedef struct tagSQL_DAY_SECOND
348 {
349 		SQLUINTEGER		day;
350 		SQLUINTEGER		hour;
351 		SQLUINTEGER		minute;
352 		SQLUINTEGER		second;
353 		SQLUINTEGER		fraction;
354 } SQL_DAY_SECOND_STRUCT;
355 
356 typedef struct tagSQL_INTERVAL_STRUCT
357 {
358 	SQLINTERVAL		interval_type;
359 	SQLSMALLINT		interval_sign;
360 	union {
361 		SQL_YEAR_MONTH_STRUCT		year_month;
362 		SQL_DAY_SECOND_STRUCT		day_second;
363 	} intval;
364 
365 } SQL_INTERVAL_STRUCT;
366 
367 #endif
368 
369 #endif
370 
371 /****************************
372  *
373  ***************************/
374 #ifndef ODBCINT64
375 # if (ODBCVER >= 0x0300)
376 # if (SIZEOF_LONG_INT == 8)
377 #   define ODBCINT64	    long
378 #   define UODBCINT64	unsigned long
379 #   define ODBCINT64_TYPE	    "long"
380 #   define UODBCINT64_TYPE	"unsigned long"
381 # else
382 #  ifdef HAVE_LONG_LONG
383 #   define ODBCINT64	    long long
384 #   define UODBCINT64	unsigned long long
385 #   define ODBCINT64_TYPE	    "long long"
386 #   define UODBCINT64_TYPE	"unsigned long long"
387 #  else
388 /*
389  * may fail in some cases, but what else can we do ?
390  */
391 struct __bigint_struct
392 {
393     int             hiword;
394     unsigned int    loword;
395 };
396 struct __bigint_struct_u
397 {
398     unsigned int    hiword;
399     unsigned int    loword;
400 };
401 #   define ODBCINT64	    struct __bigint_struct
402 #   define UODBCINT64	struct __bigint_struct_u
403 #   define ODBCINT64_TYPE	    "struct __bigint_struct"
404 #   define UODBCINT64_TYPE	"struct __bigint_struct_u"
405 #  endif
406 # endif
407 #endif
408 #endif
409 
410 #ifdef ODBCINT64
411 typedef ODBCINT64	SQLBIGINT;
412 #endif
413 #ifdef UODBCINT64
414 typedef UODBCINT64	SQLUBIGINT;
415 #endif
416 
417 
418 /****************************
419  * cursor and bookmark
420  ***************************/
421 #if (ODBCVER >= 0x0300)
422 #define SQL_MAX_NUMERIC_LEN		16
423 typedef struct tagSQL_NUMERIC_STRUCT
424 {
425 	SQLCHAR		precision;
426 	SQLSCHAR	scale;
427 	SQLCHAR		sign;	/* 1=pos 0=neg */
428 	SQLCHAR		val[SQL_MAX_NUMERIC_LEN];
429 } SQL_NUMERIC_STRUCT;
430 #endif
431 
432 #if (ODBCVER >= 0x0350)
433 #ifdef GUID_DEFINED
434 #ifndef ALLREADY_HAVE_WINDOWS_TYPE
435 typedef GUID	SQLGUID;
436 #else
437 typedef struct  tagSQLGUID
438 {
439     DWORD Data1;
440     WORD Data2;
441     WORD Data3;
442     BYTE Data4[ 8 ];
443 } SQLGUID;
444 #endif
445 #else
446 typedef struct  tagSQLGUID
447 {
448     DWORD Data1;
449     WORD Data2;
450     WORD Data3;
451     BYTE Data4[ 8 ];
452 } SQLGUID;
453 #endif
454 #endif
455 
456 typedef SQLULEN         BOOKMARK;
457 
458 typedef  WCHAR         SQLWCHAR;
459 
460 #ifdef UNICODE
461 typedef SQLWCHAR        SQLTCHAR;
462 #else
463 typedef SQLCHAR         SQLTCHAR;
464 #endif
465 
466 #ifdef __cplusplus
467 }
468 #endif
469 
470 #endif
471 
472 
473 
474