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