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 #elif defined(OS2) 110 #define SQL_API _System 111 #else 112 #define SQL_API 113 #endif 114 115 116 /* 117 * API declaration data types 118 */ 119 typedef unsigned char SQLCHAR; 120 typedef signed short SQLSMALLINT; 121 typedef unsigned short SQLUSMALLINT; 122 #if (SIZEOF_LONG == 8) 123 typedef signed int SQLINTEGER; 124 typedef unsigned int SQLUINTEGER; 125 #else 126 typedef signed long SQLINTEGER; 127 typedef unsigned long SQLUINTEGER; 128 #endif 129 typedef void * SQLPOINTER; 130 131 #if (ODBCVER >= 0x0300) 132 typedef signed char SQLSCHAR; 133 typedef unsigned char SQLDATE; 134 typedef unsigned char SQLDECIMAL; 135 typedef unsigned char SQLNUMERIC; 136 typedef double SQLDOUBLE; 137 typedef double SQLFLOAT; 138 typedef float SQLREAL; 139 typedef unsigned char SQLTIME; 140 typedef unsigned char SQLTIMESTAMP; 141 typedef unsigned char SQLVARCHAR; 142 #endif /* ODBCVER >= 0x0300 */ 143 144 145 /* 146 * New Win64 datatypes 147 */ 148 #ifdef _WIN64 149 #include <basetsd.h> /* INT64 / UINT64 (not otherwise pulled in here) */ 150 typedef INT64 SQLLEN; 151 typedef UINT64 SQLULEN; 152 typedef UINT64 SQLSETPOSIROW; 153 #elif defined(STRICT_ODBC_TYPES) 154 typedef long SQLLEN; 155 typedef unsigned long SQLULEN; 156 typedef unsigned short SQLSETPOSIROW; 157 #else 158 #define SQLLEN long 159 #define SQLULEN unsigned long 160 #define SQLSETPOSIROW unsigned short 161 #endif 162 163 164 /* 165 * Backward compatibility with older platform sdks 166 */ 167 typedef SQLULEN SQLROWCOUNT; 168 typedef SQLULEN SQLROWSETSIZE; 169 typedef SQLULEN SQLTRANSID; 170 typedef SQLLEN SQLROWOFFSET; 171 172 173 /* 174 * Generic pointer types 175 */ 176 typedef void * PTR; 177 typedef void * SQLHANDLE; 178 179 180 /* 181 * Handles 182 */ 183 typedef void * HENV; 184 typedef void * HDBC; 185 typedef void * HSTMT; 186 187 typedef SQLHANDLE SQLHENV; 188 typedef SQLHANDLE SQLHDBC; 189 typedef SQLHANDLE SQLHSTMT; 190 #if (ODBCVER >= 0x0300) 191 typedef SQLHANDLE SQLHDESC; 192 #endif /* ODBCVER >= 0x0300 */ 193 194 195 /* 196 * Window Handle 197 */ 198 #if defined(WIN32) || defined (_WIN64) 199 typedef void* HWND; /* Make up for no windows.h */ 200 typedef HWND SQLHWND; 201 #elif defined(macintosh) 202 #include <Dialogs.h> 203 typedef WindowPtr HWND; 204 typedef HWND SQLHWND; 205 #elif defined(OS2) 206 #ifndef _OS2_H // YD define only if system headers are not included 207 typedef SQLPOINTER HWND; 208 #endif 209 typedef SQLPOINTER SQLHWND; 210 #else 211 typedef SQLPOINTER HWND; 212 typedef SQLPOINTER SQLHWND; 213 #endif 214 215 216 /* 217 * SQL portable types for C 218 */ 219 typedef unsigned char UCHAR; 220 typedef signed char SCHAR; 221 typedef short int SWORD; 222 typedef unsigned short int UWORD; 223 typedef long int SDWORD; 224 typedef unsigned long int UDWORD; 225 226 typedef signed short SSHORT; 227 typedef unsigned short USHORT; 228 typedef signed long SLONG; 229 typedef unsigned long ULONG; 230 typedef float SFLOAT; 231 typedef double SDOUBLE; 232 typedef double LDOUBLE; 233 234 235 /* 236 * Return type for functions 237 */ 238 typedef signed short RETCODE; 239 typedef SQLSMALLINT SQLRETURN; 240 241 242 /* 243 * SQL portable types for C - DATA, TIME, TIMESTAMP, and BOOKMARK 244 */ 245 typedef SQLULEN BOOKMARK; 246 247 248 typedef struct tagDATE_STRUCT 249 { 250 SQLSMALLINT year; 251 SQLUSMALLINT month; 252 SQLUSMALLINT day; 253 } 254 DATE_STRUCT; 255 256 #if (ODBCVER >= 0x0300) 257 typedef DATE_STRUCT SQL_DATE_STRUCT; 258 #endif /* ODBCVER >= 0x0300 */ 259 260 261 typedef struct tagTIME_STRUCT 262 { 263 SQLUSMALLINT hour; 264 SQLUSMALLINT minute; 265 SQLUSMALLINT second; 266 } 267 TIME_STRUCT; 268 269 #if (ODBCVER >= 0x0300) 270 typedef TIME_STRUCT SQL_TIME_STRUCT; 271 #endif /* ODBCVER >= 0x0300 */ 272 273 274 typedef struct tagTIMESTAMP_STRUCT 275 { 276 SQLSMALLINT year; 277 SQLUSMALLINT month; 278 SQLUSMALLINT day; 279 SQLUSMALLINT hour; 280 SQLUSMALLINT minute; 281 SQLUSMALLINT second; 282 SQLUINTEGER fraction; 283 } 284 TIMESTAMP_STRUCT; 285 286 #if (ODBCVER >= 0x0300) 287 typedef TIMESTAMP_STRUCT SQL_TIMESTAMP_STRUCT; 288 #endif /* ODBCVER >= 0x0300 */ 289 290 291 /* 292 * Enumeration for DATETIME_INTERVAL_SUBCODE values for interval data types 293 * 294 * These values are from SQL-92 295 */ 296 #if (ODBCVER >= 0x0300) 297 typedef enum 298 { 299 SQL_IS_YEAR = 1, 300 SQL_IS_MONTH = 2, 301 SQL_IS_DAY = 3, 302 SQL_IS_HOUR = 4, 303 SQL_IS_MINUTE = 5, 304 SQL_IS_SECOND = 6, 305 SQL_IS_YEAR_TO_MONTH = 7, 306 SQL_IS_DAY_TO_HOUR = 8, 307 SQL_IS_DAY_TO_MINUTE = 9, 308 SQL_IS_DAY_TO_SECOND = 10, 309 SQL_IS_HOUR_TO_MINUTE = 11, 310 SQL_IS_HOUR_TO_SECOND = 12, 311 SQL_IS_MINUTE_TO_SECOND = 13 312 } 313 SQLINTERVAL; 314 315 316 typedef struct tagSQL_YEAR_MONTH 317 { 318 SQLUINTEGER year; 319 SQLUINTEGER month; 320 } 321 SQL_YEAR_MONTH_STRUCT; 322 323 324 typedef struct tagSQL_DAY_SECOND 325 { 326 SQLUINTEGER day; 327 SQLUINTEGER hour; 328 SQLUINTEGER minute; 329 SQLUINTEGER second; 330 SQLUINTEGER fraction; 331 } 332 SQL_DAY_SECOND_STRUCT; 333 334 335 typedef struct tagSQL_INTERVAL_STRUCT 336 { 337 SQLINTERVAL interval_type; 338 SQLSMALLINT interval_sign; 339 union 340 { 341 SQL_YEAR_MONTH_STRUCT year_month; 342 SQL_DAY_SECOND_STRUCT day_second; 343 } 344 intval; 345 } 346 SQL_INTERVAL_STRUCT; 347 #endif /* ODBCVER >= 0x0300 */ 348 349 350 /* 351 * The ODBC C types for SQL_C_SBIGINT and SQL_C_UBIGINT 352 */ 353 #if (ODBCVER >= 0x0300) 354 355 #if (_MSC_VER >= 900) 356 # define ODBCINT64 __int64 357 #endif 358 359 #ifndef ODBCINT64 360 # if (SIZEOF_LONG == 8) 361 # define ODBCINT64 long 362 # else 363 # define ODBCINT64 long long 364 # endif 365 #endif /* ODBCINT64 */ 366 367 #if defined (ODBCINT64) 368 typedef signed ODBCINT64 SQLBIGINT; 369 typedef unsigned ODBCINT64 SQLUBIGINT; 370 #endif /* ODBCINT64 */ 371 372 #endif /* ODBCVER >= 0x0300 */ 373 374 375 /* 376 * The internal representation of the numeric data type 377 */ 378 #if (ODBCVER >= 0x0300) 379 #define SQL_MAX_NUMERIC_LEN 16 380 typedef struct tagSQL_NUMERIC_STRUCT 381 { 382 SQLCHAR precision; 383 SQLSCHAR scale; 384 SQLCHAR sign; /* 0 for negative, 1 for positive */ 385 SQLCHAR val[SQL_MAX_NUMERIC_LEN]; 386 } 387 SQL_NUMERIC_STRUCT; 388 #endif /* ODBCVER >= 0x0300 */ 389 390 391 #if (ODBCVER >= 0x0350) 392 #ifdef GUID_DEFINED 393 typedef GUID SQLGUID; 394 #else 395 typedef struct tagSQLGUID 396 { 397 unsigned int Data1; 398 unsigned short Data2; 399 unsigned short Data3; 400 unsigned char Data4[8]; /* BYTE */ 401 } 402 SQLGUID; 403 #endif /* GUID_DEFINED */ 404 #endif /* ODBCVER >= 0x0350 */ 405 406 407 #if defined(WIN32) 408 typedef unsigned short SQLWCHAR; 409 #else 410 # include <stdlib.h> 411 412 # if defined(__cplusplus) || \ 413 defined(_WCHAR_T) || \ 414 defined(_WCHAR_T_DEFINED) || \ 415 defined(_WCHAR_T_DEFINED_) || \ 416 defined(_WCHAR_T_DECLARED) || \ 417 defined(_BSD_WCHAR_T_DEFINED_) || \ 418 defined(_BSD_WCHAR_T_) || \ 419 defined(_BSD_CT_RUNE_T_) 420 typedef wchar_t SQLWCHAR; 421 # else 422 # error Please make sure your system supports the wchar_t type 423 # endif 424 #endif /* WIN32 */ 425 426 427 #ifdef UNICODE 428 typedef SQLWCHAR SQLTCHAR; 429 #else 430 typedef SQLCHAR SQLTCHAR; 431 #endif /* UNICODE */ 432 433 #ifdef __cplusplus 434 } 435 #endif 436 437 #endif /* _SQLTYPES_H */ 438