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