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