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
43extern "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_
73typedef void* HWND;
74#endif
75typedef 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
85typedef wchar_t TCHAR;
86#else
87typedef signed short TCHAR;
88#endif
89
90#else
91typedef char TCHAR;
92#endif
93
94typedef unsigned short WORD;
95#if (SIZEOF_LONG_INT == 4)
96typedef unsigned long DWORD;
97#else
98typedef unsigned int DWORD;
99#endif
100typedef unsigned char BYTE;
101
102#ifdef SQL_WCHART_CONVERT
103typedef wchar_t WCHAR;
104#else
105typedef unsigned short WCHAR;
106#endif
107
108typedef WCHAR* LPWSTR;
109typedef const char* LPCSTR;
110typedef const WCHAR* LPCWSTR;
111typedef TCHAR* LPTSTR;
112typedef char* LPSTR;
113typedef DWORD* LPDWORD;
114
115#ifndef _WINDOWS_
116typedef 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 ***************************/
125typedef unsigned char SQLCHAR;
126
127#if (ODBCVER >= 0x0300)
128typedef unsigned char SQLDATE;
129typedef unsigned char SQLDECIMAL;
130typedef double SQLDOUBLE;
131typedef 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
146typedef int SQLINTEGER;
147typedef 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
160typedef int SQLINTEGER;
161typedef unsigned int SQLUINTEGER;
162typedef long SQLLEN;
163typedef unsigned long SQLULEN;
164typedef 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
175typedef long SQLINTEGER;
176typedef unsigned long SQLUINTEGER;
177
178/* Handle case of building on mingw-w64 */
179
180#ifdef _WIN64
181typedef long long SQLLEN;
182typedef unsigned long long SQLULEN;
183typedef unsigned long long SQLSETPOSIROW;
184#else
185#define SQLLEN SQLINTEGER
186#define SQLULEN SQLUINTEGER
187#define SQLSETPOSIROW SQLUSMALLINT
188#endif
189
190typedef SQLULEN SQLROWCOUNT;
191typedef SQLULEN SQLROWSETSIZE;
192typedef SQLULEN SQLTRANSID;
193typedef SQLLEN SQLROWOFFSET;
194#endif
195
196#if (ODBCVER >= 0x0300)
197typedef unsigned char SQLNUMERIC;
198#endif
199
200typedef void * SQLPOINTER;
201
202#if (ODBCVER >= 0x0300)
203typedef float SQLREAL;
204#endif
205
206typedef signed short int SQLSMALLINT;
207typedef unsigned short SQLUSMALLINT;
208
209#if (ODBCVER >= 0x0300)
210typedef unsigned char SQLTIME;
211typedef unsigned char SQLTIMESTAMP;
212typedef unsigned char SQLVARCHAR;
213#endif
214
215typedef SQLSMALLINT SQLRETURN;
216
217#if (ODBCVER >= 0x0300)
218typedef void * SQLHANDLE;
219typedef SQLHANDLE SQLHENV;
220typedef SQLHANDLE SQLHDBC;
221typedef SQLHANDLE SQLHSTMT;
222typedef SQLHANDLE SQLHDESC;
223#else
224typedef void * SQLHENV;
225typedef void * SQLHDBC;
226typedef void * SQLHSTMT;
227/*
228 * some things like PHP won't build without this
229 */
230typedef 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)
241typedef SQLHANDLE HENV;
242typedef SQLHANDLE HDBC;
243typedef SQLHANDLE HSTMT;
244#else
245typedef void * HENV;
246typedef void * HDBC;
247typedef 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
256typedef unsigned char UCHAR;
257typedef signed char SCHAR;
258typedef SCHAR SQLSCHAR;
259#if (SIZEOF_LONG_INT == 4)
260typedef long int SDWORD;
261typedef unsigned long int UDWORD;
262#else
263typedef int SDWORD;
264typedef unsigned int UDWORD;
265#endif
266typedef signed short int SWORD;
267typedef unsigned short int UWORD;
268typedef unsigned int UINT;
269typedef signed long SLONG;
270typedef signed short SSHORT;
271typedef unsigned long ULONG;
272typedef unsigned short USHORT;
273typedef double SDOUBLE;
274typedef double LDOUBLE;
275typedef float SFLOAT;
276typedef void* PTR;
277typedef signed short RETCODE;
278typedef void* SQLHWND;
279
280#endif
281
282/****************************
283 * standard structs for working with date/times
284 ***************************/
285#ifndef __SQLDATE
286#define __SQLDATE
287typedef struct tagDATE_STRUCT
288{
289 SQLSMALLINT year;
290 SQLUSMALLINT month;
291 SQLUSMALLINT day;
292} DATE_STRUCT;
293
294#if (ODBCVER >= 0x0300)
295typedef DATE_STRUCT SQL_DATE_STRUCT;
296#endif
297
298typedef struct tagTIME_STRUCT
299{
300 SQLUSMALLINT hour;
301 SQLUSMALLINT minute;
302 SQLUSMALLINT second;
303} TIME_STRUCT;
304
305#if (ODBCVER >= 0x0300)
306typedef TIME_STRUCT SQL_TIME_STRUCT;
307#endif
308
309typedef 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)
321typedef TIMESTAMP_STRUCT SQL_TIMESTAMP_STRUCT;
322#endif
323
324
325#if (ODBCVER >= 0x0300)
326typedef 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)
346typedef struct tagSQL_YEAR_MONTH
347{
348 SQLUINTEGER year;
349 SQLUINTEGER month;
350} SQL_YEAR_MONTH_STRUCT;
351
352typedef 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
361typedef 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 */
396struct __bigint_struct
397{
398 int hiword;
399 unsigned int loword;
400};
401struct __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
416typedef ODBCINT64 SQLBIGINT;
417#endif
418#ifdef UODBCINT64
419typedef UODBCINT64 SQLUBIGINT;
420#endif
421
422
423/****************************
424 * cursor and bookmark
425 ***************************/
426#if (ODBCVER >= 0x0300)
427#define SQL_MAX_NUMERIC_LEN 16
428typedef 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
440typedef GUID SQLGUID;
441#else
442typedef struct tagSQLGUID
443{
444 DWORD Data1;
445 WORD Data2;
446 WORD Data3;
447 BYTE Data4[ 8 ];
448} SQLGUID;
449#endif
450#else
451typedef struct tagSQLGUID
452{
453 DWORD Data1;
454 WORD Data2;
455 WORD Data3;
456 BYTE Data4[ 8 ];
457} SQLGUID;
458#endif
459#endif
460
461typedef SQLULEN BOOKMARK;
462
463typedef WCHAR SQLWCHAR;
464
465#ifdef UNICODE
466typedef SQLWCHAR SQLTCHAR;
467#else
468typedef SQLCHAR SQLTCHAR;
469#endif
470
471#ifdef __cplusplus
472}
473#endif
474
475#endif
476
477
478
479