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 | #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 ALREADY_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 recommended 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_LONG_INT == 4) |
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 default 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 | typedef long SQLINTEGER; |
176 | typedef unsigned long SQLUINTEGER; |
177 | |
178 | /* Handle case of building on mingw-w64 */ |
179 | |
180 | #ifdef _WIN64 |
181 | typedef long long SQLLEN; |
182 | typedef unsigned long long SQLULEN; |
183 | typedef unsigned long long SQLSETPOSIROW; |
184 | #else |
185 | #define SQLLEN SQLINTEGER |
186 | #define SQLULEN SQLUINTEGER |
187 | #define SQLSETPOSIROW SQLUSMALLINT |
188 | #endif |
189 | |
190 | typedef SQLULEN SQLROWCOUNT; |
191 | typedef SQLULEN SQLROWSETSIZE; |
192 | typedef SQLULEN SQLTRANSID; |
193 | typedef SQLLEN SQLROWOFFSET; |
194 | #endif |
195 | |
196 | #if (ODBCVER >= 0x0300) |
197 | typedef unsigned char SQLNUMERIC; |
198 | #endif |
199 | |
200 | typedef void * SQLPOINTER; |
201 | |
202 | #if (ODBCVER >= 0x0300) |
203 | typedef float SQLREAL; |
204 | #endif |
205 | |
206 | typedef signed short int SQLSMALLINT; |
207 | typedef unsigned short SQLUSMALLINT; |
208 | |
209 | #if (ODBCVER >= 0x0300) |
210 | typedef unsigned char SQLTIME; |
211 | typedef unsigned char SQLTIMESTAMP; |
212 | typedef unsigned char SQLVARCHAR; |
213 | #endif |
214 | |
215 | typedef SQLSMALLINT SQLRETURN; |
216 | |
217 | #if (ODBCVER >= 0x0300) |
218 | typedef void * SQLHANDLE; |
219 | typedef SQLHANDLE SQLHENV; |
220 | typedef SQLHANDLE SQLHDBC; |
221 | typedef SQLHANDLE SQLHSTMT; |
222 | typedef SQLHANDLE SQLHDESC; |
223 | #else |
224 | typedef void * SQLHENV; |
225 | typedef void * SQLHDBC; |
226 | typedef void * SQLHSTMT; |
227 | /* |
228 | * some things like PHP won't build without this |
229 | */ |
230 | typedef void * SQLHANDLE; |
231 | #endif |
232 | |
233 | /**************************** |
234 | * These are cast into the actual struct that is being passed around. The |
235 | * DriverManager knows what its structs look like and the Driver knows about its |
236 | * structs... the app knows nothing about them... just void* |
237 | * These are deprecated in favour of SQLHENV, SQLHDBC, SQLHSTMT |
238 | ***************************/ |
239 | |
240 | #if (ODBCVER >= 0x0300) |
241 | typedef SQLHANDLE HENV; |
242 | typedef SQLHANDLE HDBC; |
243 | typedef SQLHANDLE HSTMT; |
244 | #else |
245 | typedef void * HENV; |
246 | typedef void * HDBC; |
247 | typedef void * HSTMT; |
248 | #endif |
249 | |
250 | |
251 | /**************************** |
252 | * more basic data types to augment what windows.h provides |
253 | ***************************/ |
254 | #ifndef ALREADY_HAVE_WINDOWS_TYPE |
255 | |
256 | typedef unsigned char UCHAR; |
257 | typedef signed char SCHAR; |
258 | typedef SCHAR SQLSCHAR; |
259 | #if (SIZEOF_LONG_INT == 4) |
260 | typedef long int SDWORD; |
261 | typedef unsigned long int UDWORD; |
262 | #else |
263 | typedef int SDWORD; |
264 | typedef unsigned int UDWORD; |
265 | #endif |
266 | typedef signed short int SWORD; |
267 | typedef unsigned short int UWORD; |
268 | typedef unsigned int UINT; |
269 | typedef signed long SLONG; |
270 | typedef signed short SSHORT; |
271 | typedef unsigned long ULONG; |
272 | typedef unsigned short USHORT; |
273 | typedef double SDOUBLE; |
274 | typedef double LDOUBLE; |
275 | typedef float SFLOAT; |
276 | typedef void* PTR; |
277 | typedef signed short RETCODE; |
278 | typedef void* SQLHWND; |
279 | |
280 | #endif |
281 | |
282 | /**************************** |
283 | * standard structs for working with date/times |
284 | ***************************/ |
285 | #ifndef __SQLDATE |
286 | #define __SQLDATE |
287 | typedef struct tagDATE_STRUCT |
288 | { |
289 | SQLSMALLINT year; |
290 | SQLUSMALLINT month; |
291 | SQLUSMALLINT day; |
292 | } DATE_STRUCT; |
293 | |
294 | #if (ODBCVER >= 0x0300) |
295 | typedef DATE_STRUCT SQL_DATE_STRUCT; |
296 | #endif |
297 | |
298 | typedef struct tagTIME_STRUCT |
299 | { |
300 | SQLUSMALLINT hour; |
301 | SQLUSMALLINT minute; |
302 | SQLUSMALLINT second; |
303 | } TIME_STRUCT; |
304 | |
305 | #if (ODBCVER >= 0x0300) |
306 | typedef TIME_STRUCT SQL_TIME_STRUCT; |
307 | #endif |
308 | |
309 | typedef struct tagTIMESTAMP_STRUCT |
310 | { |
311 | SQLSMALLINT year; |
312 | SQLUSMALLINT month; |
313 | SQLUSMALLINT day; |
314 | SQLUSMALLINT hour; |
315 | SQLUSMALLINT minute; |
316 | SQLUSMALLINT second; |
317 | SQLUINTEGER fraction; |
318 | } TIMESTAMP_STRUCT; |
319 | |
320 | #if (ODBCVER >= 0x0300) |
321 | typedef TIMESTAMP_STRUCT SQL_TIMESTAMP_STRUCT; |
322 | #endif |
323 | |
324 | |
325 | #if (ODBCVER >= 0x0300) |
326 | typedef enum |
327 | { |
328 | SQL_IS_YEAR = 1, |
329 | SQL_IS_MONTH = 2, |
330 | SQL_IS_DAY = 3, |
331 | SQL_IS_HOUR = 4, |
332 | SQL_IS_MINUTE = 5, |
333 | SQL_IS_SECOND = 6, |
334 | SQL_IS_YEAR_TO_MONTH = 7, |
335 | SQL_IS_DAY_TO_HOUR = 8, |
336 | SQL_IS_DAY_TO_MINUTE = 9, |
337 | SQL_IS_DAY_TO_SECOND = 10, |
338 | SQL_IS_HOUR_TO_MINUTE = 11, |
339 | SQL_IS_HOUR_TO_SECOND = 12, |
340 | SQL_IS_MINUTE_TO_SECOND = 13 |
341 | } SQLINTERVAL; |
342 | |
343 | #endif |
344 | |
345 | #if (ODBCVER >= 0x0300) |
346 | typedef struct tagSQL_YEAR_MONTH |
347 | { |
348 | SQLUINTEGER year; |
349 | SQLUINTEGER month; |
350 | } SQL_YEAR_MONTH_STRUCT; |
351 | |
352 | typedef struct tagSQL_DAY_SECOND |
353 | { |
354 | SQLUINTEGER day; |
355 | SQLUINTEGER hour; |
356 | SQLUINTEGER minute; |
357 | SQLUINTEGER second; |
358 | SQLUINTEGER fraction; |
359 | } SQL_DAY_SECOND_STRUCT; |
360 | |
361 | typedef struct tagSQL_INTERVAL_STRUCT |
362 | { |
363 | SQLINTERVAL interval_type; |
364 | SQLSMALLINT interval_sign; |
365 | union { |
366 | SQL_YEAR_MONTH_STRUCT year_month; |
367 | SQL_DAY_SECOND_STRUCT day_second; |
368 | } intval; |
369 | |
370 | } SQL_INTERVAL_STRUCT; |
371 | |
372 | #endif |
373 | |
374 | #endif |
375 | |
376 | /**************************** |
377 | * |
378 | ***************************/ |
379 | #ifndef ODBCINT64 |
380 | # if (ODBCVER >= 0x0300) |
381 | # if (SIZEOF_LONG_INT == 8) |
382 | # define ODBCINT64 long |
383 | # define UODBCINT64 unsigned long |
384 | # define ODBCINT64_TYPE "long" |
385 | # define UODBCINT64_TYPE "unsigned long" |
386 | # else |
387 | # ifdef HAVE_LONG_LONG |
388 | # define ODBCINT64 long long |
389 | # define UODBCINT64 unsigned long long |
390 | # define ODBCINT64_TYPE "long long" |
391 | # define UODBCINT64_TYPE "unsigned long long" |
392 | # else |
393 | /* |
394 | * may fail in some cases, but what else can we do ? |
395 | */ |
396 | struct __bigint_struct |
397 | { |
398 | int hiword; |
399 | unsigned int loword; |
400 | }; |
401 | struct __bigint_struct_u |
402 | { |
403 | unsigned int hiword; |
404 | unsigned int loword; |
405 | }; |
406 | # define ODBCINT64 struct __bigint_struct |
407 | # define UODBCINT64 struct __bigint_struct_u |
408 | # define ODBCINT64_TYPE "struct __bigint_struct" |
409 | # define UODBCINT64_TYPE "struct __bigint_struct_u" |
410 | # endif |
411 | # endif |
412 | #endif |
413 | #endif |
414 | |
415 | #ifdef ODBCINT64 |
416 | typedef ODBCINT64 SQLBIGINT; |
417 | #endif |
418 | #ifdef UODBCINT64 |
419 | typedef UODBCINT64 SQLUBIGINT; |
420 | #endif |
421 | |
422 | |
423 | /**************************** |
424 | * cursor and bookmark |
425 | ***************************/ |
426 | #if (ODBCVER >= 0x0300) |
427 | #define SQL_MAX_NUMERIC_LEN 16 |
428 | typedef struct tagSQL_NUMERIC_STRUCT |
429 | { |
430 | SQLCHAR precision; |
431 | SQLSCHAR scale; |
432 | SQLCHAR sign; /* 1=pos 0=neg */ |
433 | SQLCHAR val[SQL_MAX_NUMERIC_LEN]; |
434 | } SQL_NUMERIC_STRUCT; |
435 | #endif |
436 | |
437 | #if (ODBCVER >= 0x0350) |
438 | #ifdef GUID_DEFINED |
439 | #ifndef ALREADY_HAVE_WINDOWS_TYPE |
440 | typedef GUID SQLGUID; |
441 | #else |
442 | typedef struct tagSQLGUID |
443 | { |
444 | DWORD Data1; |
445 | WORD Data2; |
446 | WORD Data3; |
447 | BYTE Data4[ 8 ]; |
448 | } SQLGUID; |
449 | #endif |
450 | #else |
451 | typedef struct tagSQLGUID |
452 | { |
453 | DWORD Data1; |
454 | WORD Data2; |
455 | WORD Data3; |
456 | BYTE Data4[ 8 ]; |
457 | } SQLGUID; |
458 | #endif |
459 | #endif |
460 | |
461 | typedef SQLULEN BOOKMARK; |
462 | |
463 | typedef WCHAR SQLWCHAR; |
464 | |
465 | #ifdef UNICODE |
466 | typedef SQLWCHAR SQLTCHAR; |
467 | #else |
468 | typedef SQLCHAR SQLTCHAR; |
469 | #endif |
470 | |
471 | #ifdef __cplusplus |
472 | } |
473 | #endif |
474 | |
475 | #endif |
476 | |
477 | |
478 | |
479 | |