xref: /AOO41X/main/unixODBC/inc/sqltypes.h (revision 1c78a5d6c0093dece4c096ba53051800fbad6e33)
1 /*
2  *  sqltypes.h
3  *
4  *  $Id: sqltypes.h,v 1.25 2009/09/09 20:06:24 source Exp $
5  *
6  *  ODBC typedefs
7  *
8  *  The iODBC driver manager.
9  *
10  *  Copyright (C) 1995 by Ke Jin <kejin@empress.com>
11  *  Copyright (C) 1996-2009 by OpenLink Software <iodbc@openlinksw.com>
12  *  All Rights Reserved.
13  *
14  *  This software is released under the terms of either of the following
15  *  licenses:
16  *
17  *      - GNU Library General Public License (see LICENSE.LGPL)
18  *      - The BSD License (see LICENSE.BSD).
19  *
20  *  Note that the only valid version of the LGPL license as far as this
21  *  project is concerned is the original GNU Library General Public License
22  *  Version 2, dated June 1991.
23  *
24  *  While not mandated by the BSD license, any patches you make to the
25  *  iODBC source code may be contributed back into the iODBC project
26  *  at your discretion. Contributions will benefit the Open Source and
27  *  Data Access community as a whole. Submissions may be made at:
28  *
29  *      http://www.iodbc.org
30  *
31  *
32  *  GNU Library Generic Public License Version 2
33  *  ============================================
34  *  This library is free software; you can redistribute it and/or
35  *  modify it under the terms of the GNU Library General Public
36  *  License as published by the Free Software Foundation; only
37  *  Version 2 of the License dated June 1991.
38  *
39  *  This library is distributed in the hope that it will be useful,
40  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
41  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
42  *  Library General Public License for more details.
43  *
44  *  You should have received a copy of the GNU Library General Public
45  *  License along with this library; if not, write to the Free
46  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
47  *
48  *
49  *  The BSD License
50  *  ===============
51  *  Redistribution and use in source and binary forms, with or without
52  *  modification, are permitted provided that the following conditions
53  *  are met:
54  *
55  *  1. Redistributions of source code must retain the above copyright
56  *     notice, this list of conditions and the following disclaimer.
57  *  2. Redistributions in binary form must reproduce the above copyright
58  *     notice, this list of conditions and the following disclaimer in
59  *     the documentation and/or other materials provided with the
60  *     distribution.
61  *  3. Neither the name of OpenLink Software Inc. nor the names of its
62  *     contributors may be used to endorse or promote products derived
63  *     from this software without specific prior written permission.
64  *
65  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
66  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
67  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
68  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OPENLINK OR
69  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
70  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
71  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
72  *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
73  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
74  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
75  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
76  */
77 
78 #ifndef _SQLTYPES_H
79 #define _SQLTYPES_H
80 
81 /*
82  *  Set default specification to  ODBC 3.51
83  */
84 #ifndef ODBCVER
85 #define ODBCVER		0x0351
86 #endif
87 
88 /*
89  *  Include Windows style defines and typedefs on Unix
90  */
91 #ifndef _IODBCUNIX_H
92 #include <odbc/iodbcunix.h>
93 #endif
94 
95 #ifdef __cplusplus
96 extern "C" {
97 #endif
98 
99 
100 /*
101  *  Environment specific definitions
102  */
103 #ifndef EXPORT
104 #define EXPORT
105 #endif
106 
107 #ifdef WIN32
108 #define SQL_API	__stdcall
109 #else
110 #define SQL_API
111 #endif
112 
113 
114 /*
115  *  API declaration data types
116  */
117 typedef unsigned char		SQLCHAR;
118 typedef signed short		SQLSMALLINT;
119 typedef unsigned short		SQLUSMALLINT;
120 #if (SIZEOF_LONG == 8)
121 typedef signed int		SQLINTEGER;
122 typedef unsigned int		SQLUINTEGER;
123 #else
124 typedef signed long		SQLINTEGER;
125 typedef unsigned long		SQLUINTEGER;
126 #endif
127 typedef void *              	SQLPOINTER;
128 
129 #if (ODBCVER >= 0x0300)
130 typedef signed char		SQLSCHAR;
131 typedef unsigned char		SQLDATE;
132 typedef unsigned char		SQLDECIMAL;
133 typedef unsigned char		SQLNUMERIC;
134 typedef double			SQLDOUBLE;
135 typedef double			SQLFLOAT;
136 typedef float			SQLREAL;
137 typedef unsigned char		SQLTIME;
138 typedef unsigned char		SQLTIMESTAMP;
139 typedef unsigned char		SQLVARCHAR;
140 #endif	/* ODBCVER >= 0x0300 */
141 
142 
143 /*
144  *  New Win64 datatypes
145  */
146 #ifdef _WIN64
147 typedef INT64			SQLLEN;
148 typedef UINT64			SQLULEN;
149 typedef UINT64			SQLSETPOSIROW;
150 #elif defined(STRICT_ODBC_TYPES)
151 typedef long			SQLLEN;
152 typedef unsigned long		SQLULEN;
153 typedef unsigned short		SQLSETPOSIROW;
154 #else
155 #define SQLLEN			long
156 #define SQLULEN 		unsigned long
157 #define SQLSETPOSIROW		unsigned short
158 #endif
159 
160 
161 /*
162  *  Backward compatibility with older platform sdks
163  */
164 typedef SQLULEN 		SQLROWCOUNT;
165 typedef SQLULEN 		SQLROWSETSIZE;
166 typedef SQLULEN 		SQLTRANSID;
167 typedef SQLLEN			SQLROWOFFSET;
168 
169 
170 /*
171  *  Generic pointer types
172  */
173 typedef void *              	PTR;
174 typedef void *			SQLHANDLE;
175 
176 
177 /*
178  *  Handles
179  */
180 typedef void *			HENV;
181 typedef void *			HDBC;
182 typedef void *			HSTMT;
183 
184 typedef SQLHANDLE		SQLHENV;
185 typedef SQLHANDLE		SQLHDBC;
186 typedef SQLHANDLE		SQLHSTMT;
187 #if (ODBCVER >= 0x0300)
188 typedef SQLHANDLE		SQLHDESC;
189 #endif	/* ODBCVER >= 0x0300 */
190 
191 
192 /*
193  *  Window Handle
194  */
195 #if defined(WIN32) || defined (_WIN64) || defined(OS2)
196 typedef void*			HWND;	/* Make up for no windows.h */
197 typedef HWND			SQLHWND;
198 #elif defined(macintosh)
199 #include <Dialogs.h>
200 typedef WindowPtr 		HWND;
201 typedef HWND 			SQLHWND;
202 #else
203 typedef SQLPOINTER 		HWND;
204 typedef SQLPOINTER 		SQLHWND;
205 #endif
206 
207 
208 /*
209  *  SQL portable types for C
210  */
211 typedef unsigned char		UCHAR;
212 typedef signed char		SCHAR;
213 typedef short int		SWORD;
214 typedef unsigned short int	UWORD;
215 typedef long int		SDWORD;
216 typedef unsigned long int	UDWORD;
217 
218 typedef signed short		SSHORT;
219 typedef unsigned short		USHORT;
220 typedef signed long		SLONG;
221 typedef unsigned long		ULONG;
222 typedef float			SFLOAT;
223 typedef double			SDOUBLE;
224 typedef double			LDOUBLE;
225 
226 
227 /*
228  *  Return type for functions
229  */
230 typedef signed short		RETCODE;
231 typedef SQLSMALLINT		SQLRETURN;
232 
233 
234 /*
235  *  SQL portable types for C - DATA, TIME, TIMESTAMP, and BOOKMARK
236  */
237 typedef SQLULEN			BOOKMARK;
238 
239 
240 typedef struct tagDATE_STRUCT
241   {
242     SQLSMALLINT year;
243     SQLUSMALLINT month;
244     SQLUSMALLINT day;
245   }
246 DATE_STRUCT;
247 
248 #if (ODBCVER >= 0x0300)
249 typedef DATE_STRUCT		SQL_DATE_STRUCT;
250 #endif	/* ODBCVER >= 0x0300 */
251 
252 
253 typedef struct tagTIME_STRUCT
254   {
255     SQLUSMALLINT hour;
256     SQLUSMALLINT minute;
257     SQLUSMALLINT second;
258   }
259 TIME_STRUCT;
260 
261 #if (ODBCVER >= 0x0300)
262 typedef TIME_STRUCT		SQL_TIME_STRUCT;
263 #endif	/* ODBCVER >= 0x0300 */
264 
265 
266 typedef struct tagTIMESTAMP_STRUCT
267   {
268     SQLSMALLINT year;
269     SQLUSMALLINT month;
270     SQLUSMALLINT day;
271     SQLUSMALLINT hour;
272     SQLUSMALLINT minute;
273     SQLUSMALLINT second;
274     SQLUINTEGER fraction;
275   }
276 TIMESTAMP_STRUCT;
277 
278 #if (ODBCVER >= 0x0300)
279 typedef TIMESTAMP_STRUCT	SQL_TIMESTAMP_STRUCT;
280 #endif	/* ODBCVER >= 0x0300 */
281 
282 
283 /*
284  *  Enumeration for DATETIME_INTERVAL_SUBCODE values for interval data types
285  *
286  *  These values are from SQL-92
287  */
288 #if (ODBCVER >= 0x0300)
289 typedef enum
290   {
291     SQL_IS_YEAR			= 1,
292     SQL_IS_MONTH		= 2,
293     SQL_IS_DAY			= 3,
294     SQL_IS_HOUR			= 4,
295     SQL_IS_MINUTE		= 5,
296     SQL_IS_SECOND		= 6,
297     SQL_IS_YEAR_TO_MONTH	= 7,
298     SQL_IS_DAY_TO_HOUR		= 8,
299     SQL_IS_DAY_TO_MINUTE	= 9,
300     SQL_IS_DAY_TO_SECOND	= 10,
301     SQL_IS_HOUR_TO_MINUTE	= 11,
302     SQL_IS_HOUR_TO_SECOND	= 12,
303     SQL_IS_MINUTE_TO_SECOND	= 13
304   }
305 SQLINTERVAL;
306 
307 
308 typedef struct tagSQL_YEAR_MONTH
309   {
310     SQLUINTEGER year;
311     SQLUINTEGER month;
312   }
313 SQL_YEAR_MONTH_STRUCT;
314 
315 
316 typedef struct tagSQL_DAY_SECOND
317   {
318     SQLUINTEGER day;
319     SQLUINTEGER hour;
320     SQLUINTEGER minute;
321     SQLUINTEGER second;
322     SQLUINTEGER fraction;
323   }
324 SQL_DAY_SECOND_STRUCT;
325 
326 
327 typedef struct tagSQL_INTERVAL_STRUCT
328   {
329     SQLINTERVAL interval_type;
330     SQLSMALLINT interval_sign;
331     union
332       {
333 	SQL_YEAR_MONTH_STRUCT year_month;
334 	SQL_DAY_SECOND_STRUCT day_second;
335       }
336     intval;
337   }
338 SQL_INTERVAL_STRUCT;
339 #endif	/* ODBCVER >= 0x0300 */
340 
341 
342 /*
343  *  The ODBC C types for SQL_C_SBIGINT and SQL_C_UBIGINT
344  */
345 #if (ODBCVER >= 0x0300)
346 
347 #if (_MSC_VER >= 900)
348 #  define ODBCINT64 		__int64
349 #endif
350 
351 #ifndef ODBCINT64
352 # if (SIZEOF_LONG == 8)
353 #   define ODBCINT64		long
354 # else
355 #   define ODBCINT64		long long
356 # endif
357 #endif /* ODBCINT64 */
358 
359 #if defined (ODBCINT64)
360 typedef signed   ODBCINT64	SQLBIGINT;
361 typedef unsigned ODBCINT64	SQLUBIGINT;
362 #endif	/* ODBCINT64 */
363 
364 #endif	/* ODBCVER >= 0x0300 */
365 
366 
367 /*
368  *  The internal representation of the numeric data type
369  */
370 #if (ODBCVER >= 0x0300)
371 #define SQL_MAX_NUMERIC_LEN	16
372 typedef struct tagSQL_NUMERIC_STRUCT
373   {
374     SQLCHAR	precision;
375     SQLSCHAR	scale;
376     SQLCHAR	sign;		/* 0 for negative, 1 for positive */
377     SQLCHAR	val[SQL_MAX_NUMERIC_LEN];
378   }
379 SQL_NUMERIC_STRUCT;
380 #endif	/* ODBCVER >= 0x0300 */
381 
382 
383 #if (ODBCVER >= 0x0350)
384 #ifdef GUID_DEFINED
385 typedef GUID 			SQLGUID;
386 #else
387 typedef struct tagSQLGUID
388   {
389     unsigned int	Data1;
390     unsigned short	Data2;
391     unsigned short	Data3;
392     unsigned char	Data4[8];	/* BYTE */
393   }
394 SQLGUID;
395 #endif	/* GUID_DEFINED */
396 #endif	/* ODBCVER >= 0x0350 */
397 
398 
399 #if defined(WIN32)
400 typedef unsigned short SQLWCHAR;
401 #else
402 #  include <stdlib.h>
403 
404 #  if defined(__cplusplus)		|| \
405       defined(_WCHAR_T)			|| \
406       defined(_WCHAR_T_DEFINED)		|| \
407       defined(_WCHAR_T_DEFINED_)	|| \
408       defined(_WCHAR_T_DECLARED)	|| \
409       defined(_BSD_WCHAR_T_DEFINED_)	|| \
410       defined(_BSD_WCHAR_T_)		|| \
411       defined(_BSD_CT_RUNE_T_)
412 typedef wchar_t SQLWCHAR;
413 #  else
414 #    error Please make sure your system supports the wchar_t type
415 #  endif
416 #endif /* WIN32 */
417 
418 
419 #ifdef UNICODE
420 typedef SQLWCHAR        	SQLTCHAR;
421 #else
422 typedef SQLCHAR         	SQLTCHAR;
423 #endif  /* UNICODE */
424 
425 #ifdef __cplusplus
426 }
427 #endif
428 
429 #endif	/* _SQLTYPES_H */
430