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#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_
77typedef void* HWND;
78#endif
79typedef 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
89typedef wchar_t TCHAR;
90#else
91typedef signed short TCHAR;
92#endif
93
94#else
95typedef char TCHAR;
96#endif
97
98typedef unsigned short WORD;
99#if (SIZEOF_LONG_INT == 4)
100typedef unsigned long DWORD;
101#else
102typedef unsigned int DWORD;
103#endif
104typedef unsigned char BYTE;
105
106#ifdef SQL_WCHART_CONVERT
107typedef wchar_t WCHAR;
108#else
109typedef unsigned short WCHAR;
110#endif
111
112typedef WCHAR* LPWSTR;
113typedef const char* LPCSTR;
114typedef const WCHAR* LPCWSTR;
115typedef TCHAR* LPTSTR;
116typedef char* LPSTR;
117typedef DWORD* LPDWORD;
118
119#ifndef _WINDOWS_
120typedef 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 ***************************/
129typedef unsigned char SQLCHAR;
130
131#if (ODBCVER >= 0x0300)
132typedef unsigned char SQLDATE;
133typedef unsigned char SQLDECIMAL;
134typedef double SQLDOUBLE;
135typedef 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
150typedef int SQLINTEGER;
151typedef 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
164typedef int SQLINTEGER;
165typedef unsigned int SQLUINTEGER;
166typedef long SQLLEN;
167typedef unsigned long SQLULEN;
168typedef 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
179typedef long SQLINTEGER;
180typedef unsigned long SQLUINTEGER;
181
182/* Handle case of building on mingw-w64 */
183
184#ifdef _WIN64
185typedef long long SQLLEN;
186typedef unsigned long long SQLULEN;
187typedef unsigned long long SQLSETPOSIROW;
188#else
189#define SQLLEN SQLINTEGER
190#define SQLULEN SQLUINTEGER
191#define SQLSETPOSIROW SQLUSMALLINT
192#endif
193
194typedef SQLULEN SQLROWCOUNT;
195typedef SQLULEN SQLROWSETSIZE;
196typedef SQLULEN SQLTRANSID;
197typedef SQLLEN SQLROWOFFSET;
198#endif
199
200#if (ODBCVER >= 0x0300)
201typedef unsigned char SQLNUMERIC;
202#endif
203
204typedef void * SQLPOINTER;
205
206#if (ODBCVER >= 0x0300)
207typedef float SQLREAL;
208#endif
209
210typedef signed short int SQLSMALLINT;
211typedef unsigned short SQLUSMALLINT;
212
213#if (ODBCVER >= 0x0300)
214typedef unsigned char SQLTIME;
215typedef unsigned char SQLTIMESTAMP;
216typedef unsigned char SQLVARCHAR;
217#endif
218
219typedef SQLSMALLINT SQLRETURN;
220
221#if (ODBCVER >= 0x0300)
222typedef void * SQLHANDLE;
223typedef SQLHANDLE SQLHENV;
224typedef SQLHANDLE SQLHDBC;
225typedef SQLHANDLE SQLHSTMT;
226typedef SQLHANDLE SQLHDESC;
227#else
228typedef void * SQLHENV;
229typedef void * SQLHDBC;
230typedef void * SQLHSTMT;
231/*
232 * some things like PHP won't build without this
233 */
234typedef 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)
245typedef SQLHANDLE HENV;
246typedef SQLHANDLE HDBC;
247typedef SQLHANDLE HSTMT;
248#else
249typedef void * HENV;
250typedef void * HDBC;
251typedef 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
260typedef unsigned char UCHAR;
261typedef signed char SCHAR;
262typedef SCHAR SQLSCHAR;
263#if (SIZEOF_LONG_INT == 4)
264typedef long int SDWORD;
265typedef unsigned long int UDWORD;
266#else
267typedef int SDWORD;
268typedef unsigned int UDWORD;
269#endif
270typedef signed short int SWORD;
271typedef unsigned short int UWORD;
272typedef unsigned int UINT;
273typedef signed long SLONG;
274typedef signed short SSHORT;
275typedef unsigned long ULONG;
276typedef unsigned short USHORT;
277typedef double SDOUBLE;
278typedef double LDOUBLE;
279typedef float SFLOAT;
280typedef void* PTR;
281typedef signed short RETCODE;
282typedef void* SQLHWND;
283
284#endif
285
286/****************************
287 * standard structs for working with date/times
288 ***************************/
289#ifndef __SQLDATE
290#define __SQLDATE
291typedef struct tagDATE_STRUCT
292{
293 SQLSMALLINT year;
294 SQLUSMALLINT month;
295 SQLUSMALLINT day;
296} DATE_STRUCT;
297
298#if (ODBCVER >= 0x0300)
299typedef DATE_STRUCT SQL_DATE_STRUCT;
300#endif
301
302typedef struct tagTIME_STRUCT
303{
304 SQLUSMALLINT hour;
305 SQLUSMALLINT minute;
306 SQLUSMALLINT second;
307} TIME_STRUCT;
308
309#if (ODBCVER >= 0x0300)
310typedef TIME_STRUCT SQL_TIME_STRUCT;
311#endif
312
313typedef 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)
325typedef TIMESTAMP_STRUCT SQL_TIMESTAMP_STRUCT;
326#endif
327
328
329#if (ODBCVER >= 0x0300)
330typedef 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)
350typedef struct tagSQL_YEAR_MONTH
351{
352 SQLUINTEGER year;
353 SQLUINTEGER month;
354} SQL_YEAR_MONTH_STRUCT;
355
356typedef 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
365typedef 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 */
400struct __bigint_struct
401{
402 int hiword;
403 unsigned int loword;
404};
405struct __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
420typedef ODBCINT64 SQLBIGINT;
421#endif
422#ifdef UODBCINT64
423typedef UODBCINT64 SQLUBIGINT;
424#endif
425
426
427/****************************
428 * cursor and bookmark
429 ***************************/
430#if (ODBCVER >= 0x0300)
431#define SQL_MAX_NUMERIC_LEN 16
432typedef 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
444typedef GUID SQLGUID;
445#else
446typedef struct tagSQLGUID
447{
448 DWORD Data1;
449 WORD Data2;
450 WORD Data3;
451 BYTE Data4[ 8 ];
452} SQLGUID;
453#endif
454#else
455typedef struct tagSQLGUID
456{
457 DWORD Data1;
458 WORD Data2;
459 WORD Data3;
460 BYTE Data4[ 8 ];
461} SQLGUID;
462#endif
463#endif
464
465typedef SQLULEN BOOKMARK;
466
467typedef WCHAR SQLWCHAR;
468
469#ifdef UNICODE
470typedef SQLWCHAR SQLTCHAR;
471#else
472typedef SQLCHAR SQLTCHAR;
473#endif
474
475#ifdef __cplusplus
476}
477#endif
478
479#endif
480
481
482
483

source code of include/sqltypes.h