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 usefull 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.51 definitions. should define ODBCVER before here if you want an older set of defines 24 ***************************/ 25 #ifndef ODBCVER 26 #define ODBCVER 0x0351 27 #endif 28 29 /* 30 * if thi sis set, then use a 4 byte unicode definition, insteead of the 2 bye 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 #include <sal/types.h> 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 #ifndef SIZEOF_LONG_INT 49 # define SIZEOF_LONG_INT SAL_TYPES_SIZEOFLONG 50 #endif 51 #ifndef ODBCINT64 52 # define ODBCINT64 sal_Int64 53 #endif 54 #ifndef UODBCINT64 55 # define UODBCINT64 sal_uInt64 56 #endif 57 58 /* 59 * this is defined by configure, but will not be on a normal application build 60 * the install creates a unixodbc_conf.h file that contains the current build settings 61 */ 62 63 #ifndef SIZEOF_LONG_INT 64 #include <unixodbc_conf.h> 65 #endif 66 67 #ifndef SIZEOF_LONG_INT 68 #error "Needs to know how big a long int is to continue!!!" 69 #endif 70 71 /**************************** 72 * These make up for having no windows.h 73 ***************************/ 74 #ifndef ALLREADY_HAVE_WINDOWS_TYPE 75 76 #define FAR 77 #define CALLBACK 78 #ifdef __OS2__ 79 #define SQL_API _System 80 #else 81 #define SQL_API 82 #endif 83 #define BOOL int 84 typedef void* HWND; 85 typedef char CHAR; 86 #ifdef UNICODE 87 88 /* 89 * NOTE: The Microsoft unicode define is only for apps that want to use TCHARs and 90 * be able to compile for both unicode and non-unicode with the same source. 91 * This is not recommanded for linux applications and is not supported 92 * by the standard linux string header files. 93 */ 94 #ifdef SQL_WCHART_CONVERT 95 typedef wchar_t TCHAR; 96 #else 97 typedef signed short TCHAR; 98 #endif 99 100 #else 101 typedef char TCHAR; 102 #endif 103 104 #ifndef DONT_TD_VOID 105 typedef void VOID; 106 #endif 107 108 typedef unsigned short WORD; 109 #if (SIZEOF_LONG_INT == 4) 110 typedef unsigned long DWORD; 111 #else 112 typedef unsigned int DWORD; 113 #endif 114 typedef unsigned char BYTE; 115 116 #ifdef SQL_WCHART_CONVERT 117 typedef wchar_t WCHAR; 118 #else 119 typedef unsigned short WCHAR; 120 #endif 121 122 typedef WCHAR* LPWSTR; 123 typedef const char* LPCSTR; 124 typedef const WCHAR* LPCWSTR; 125 typedef TCHAR* LPTSTR; 126 typedef char* LPSTR; 127 typedef DWORD* LPDWORD; 128 129 typedef void* HINSTANCE; 130 131 #endif 132 133 134 /**************************** 135 * standard SQL* data types. use these as much as possible when using ODBC calls/vars 136 ***************************/ 137 typedef unsigned char SQLCHAR; 138 139 #if (ODBCVER >= 0x0300) 140 typedef unsigned char SQLDATE; 141 typedef unsigned char SQLDECIMAL; 142 typedef double SQLDOUBLE; 143 typedef double SQLFLOAT; 144 #endif 145 146 /* 147 * can't use a long it fails on 64 platforms 148 */ 149 150 /* 151 * Hopefully by now it should be safe to assume most drivers know about SQLLEN now 152 * and the defaukt is now sizeof( SQLLEN ) = 8 on 64 bit platforms 153 * 154 */ 155 156 #if (SIZEOF_LONG_INT == 8) 157 #ifdef BUILD_LEGACY_64_BIT_MODE 158 typedef int SQLINTEGER; 159 typedef unsigned int SQLUINTEGER; 160 #define SQLLEN SQLINTEGER 161 #define SQLULEN SQLUINTEGER 162 #define SQLSETPOSIROW SQLUSMALLINT 163 /* 164 * These are not supprted on 64bit ODBC according to MS, removed, so use at your peril 165 * 166 typedef SQLULEN SQLROWCOUNT; 167 typedef SQLULEN SQLROWSETSIZE; 168 typedef SQLULEN SQLTRANSID; 169 typedef SQLLEN SQLROWOFFSET; 170 */ 171 #else 172 typedef int SQLINTEGER; 173 typedef unsigned int SQLUINTEGER; 174 typedef long SQLLEN; 175 typedef unsigned long SQLULEN; 176 typedef unsigned long SQLSETPOSIROW; 177 /* 178 * These are not supprted on 64bit ODBC according to MS, removed, so use at your peril 179 * 180 typedef SQLULEN SQLTRANSID; 181 typedef SQLULEN SQLROWCOUNT; 182 typedef SQLUINTEGER SQLROWSETSIZE; 183 typedef SQLLEN SQLROWOFFSET; 184 */ 185 typedef SQLULEN SQLROWCOUNT; 186 typedef SQLULEN SQLROWSETSIZE; 187 typedef SQLULEN SQLTRANSID; 188 typedef SQLLEN SQLROWOFFSET; 189 #endif 190 #else 191 typedef long SQLINTEGER; 192 typedef unsigned long SQLUINTEGER; 193 #define SQLLEN SQLINTEGER 194 #define SQLULEN SQLUINTEGER 195 #define SQLSETPOSIROW SQLUSMALLINT 196 typedef SQLULEN SQLROWCOUNT; 197 typedef SQLULEN SQLROWSETSIZE; 198 typedef SQLULEN SQLTRANSID; 199 typedef SQLLEN SQLROWOFFSET; 200 #endif 201 202 #if (ODBCVER >= 0x0300) 203 typedef unsigned char SQLNUMERIC; 204 #endif 205 206 typedef void * SQLPOINTER; 207 208 #if (ODBCVER >= 0x0300) 209 typedef float SQLREAL; 210 #endif 211 212 typedef signed short int SQLSMALLINT; 213 typedef unsigned short SQLUSMALLINT; 214 215 #if (ODBCVER >= 0x0300) 216 typedef unsigned char SQLTIME; 217 typedef unsigned char SQLTIMESTAMP; 218 typedef unsigned char SQLVARCHAR; 219 #endif 220 221 typedef SQLSMALLINT SQLRETURN; 222 223 #if (ODBCVER >= 0x0300) 224 typedef void * SQLHANDLE; 225 typedef SQLHANDLE SQLHENV; 226 typedef SQLHANDLE SQLHDBC; 227 typedef SQLHANDLE SQLHSTMT; 228 typedef SQLHANDLE SQLHDESC; 229 #else 230 typedef void * SQLHENV; 231 typedef void * SQLHDBC; 232 typedef void * SQLHSTMT; 233 /* 234 * some things like PHP won't build without this 235 */ 236 typedef void * SQLHANDLE; 237 #endif 238 239 /**************************** 240 * These are cast into the actual struct that is being passed around. The 241 * DriverManager knows what its structs look like and the Driver knows about its 242 * structs... the app knows nothing about them... just void* 243 * These are deprecated in favour of SQLHENV, SQLHDBC, SQLHSTMT 244 ***************************/ 245 246 #if (ODBCVER >= 0x0300) 247 typedef SQLHANDLE HENV; 248 typedef SQLHANDLE HDBC; 249 typedef SQLHANDLE HSTMT; 250 #else 251 typedef void * HENV; 252 typedef void * HDBC; 253 typedef void * HSTMT; 254 #endif 255 256 257 /**************************** 258 * more basic data types to augment what windows.h provides 259 ***************************/ 260 #ifndef ALLREADY_HAVE_WINDOWS_TYPE 261 262 typedef unsigned char UCHAR; 263 typedef signed char SCHAR; 264 typedef SCHAR SQLSCHAR; 265 #if (SIZEOF_LONG_INT == 4) 266 typedef long int SDWORD; 267 typedef unsigned long int UDWORD; 268 #else 269 typedef int SDWORD; 270 typedef unsigned int UDWORD; 271 #endif 272 typedef signed short int SWORD; 273 typedef unsigned short int UWORD; 274 typedef unsigned int UINT; 275 typedef signed long SLONG; 276 typedef signed short SSHORT; 277 typedef unsigned long ULONG; 278 typedef unsigned short USHORT; 279 typedef double SDOUBLE; 280 typedef double LDOUBLE; 281 typedef float SFLOAT; 282 typedef void* PTR; 283 typedef signed short RETCODE; 284 typedef void* SQLHWND; 285 286 #endif 287 288 /**************************** 289 * standard structs for working with date/times 290 ***************************/ 291 #ifndef __SQLDATE 292 #define __SQLDATE 293 typedef struct tagDATE_STRUCT 294 { 295 SQLSMALLINT year; 296 SQLUSMALLINT month; 297 SQLUSMALLINT day; 298 } DATE_STRUCT; 299 300 #if (ODBCVER >= 0x0300) 301 typedef DATE_STRUCT SQL_DATE_STRUCT; 302 #endif 303 304 typedef struct tagTIME_STRUCT 305 { 306 SQLUSMALLINT hour; 307 SQLUSMALLINT minute; 308 SQLUSMALLINT second; 309 } TIME_STRUCT; 310 311 #if (ODBCVER >= 0x0300) 312 typedef TIME_STRUCT SQL_TIME_STRUCT; 313 #endif 314 315 typedef struct tagTIMESTAMP_STRUCT 316 { 317 SQLSMALLINT year; 318 SQLUSMALLINT month; 319 SQLUSMALLINT day; 320 SQLUSMALLINT hour; 321 SQLUSMALLINT minute; 322 SQLUSMALLINT second; 323 SQLUINTEGER fraction; 324 } TIMESTAMP_STRUCT; 325 326 #if (ODBCVER >= 0x0300) 327 typedef TIMESTAMP_STRUCT SQL_TIMESTAMP_STRUCT; 328 #endif 329 330 331 #if (ODBCVER >= 0x0300) 332 typedef enum 333 { 334 SQL_IS_YEAR = 1, 335 SQL_IS_MONTH = 2, 336 SQL_IS_DAY = 3, 337 SQL_IS_HOUR = 4, 338 SQL_IS_MINUTE = 5, 339 SQL_IS_SECOND = 6, 340 SQL_IS_YEAR_TO_MONTH = 7, 341 SQL_IS_DAY_TO_HOUR = 8, 342 SQL_IS_DAY_TO_MINUTE = 9, 343 SQL_IS_DAY_TO_SECOND = 10, 344 SQL_IS_HOUR_TO_MINUTE = 11, 345 SQL_IS_HOUR_TO_SECOND = 12, 346 SQL_IS_MINUTE_TO_SECOND = 13 347 } SQLINTERVAL; 348 349 #endif 350 351 #if (ODBCVER >= 0x0300) 352 typedef struct tagSQL_YEAR_MONTH 353 { 354 SQLUINTEGER year; 355 SQLUINTEGER month; 356 } SQL_YEAR_MONTH_STRUCT; 357 358 typedef struct tagSQL_DAY_SECOND 359 { 360 SQLUINTEGER day; 361 SQLUINTEGER hour; 362 SQLUINTEGER minute; 363 SQLUINTEGER second; 364 SQLUINTEGER fraction; 365 } SQL_DAY_SECOND_STRUCT; 366 367 typedef struct tagSQL_INTERVAL_STRUCT 368 { 369 SQLINTERVAL interval_type; 370 SQLSMALLINT interval_sign; 371 union { 372 SQL_YEAR_MONTH_STRUCT year_month; 373 SQL_DAY_SECOND_STRUCT day_second; 374 } intval; 375 376 } SQL_INTERVAL_STRUCT; 377 378 #endif 379 380 #endif 381 382 /**************************** 383 * 384 ***************************/ 385 #ifndef ODBCINT64 386 # if (ODBCVER >= 0x0300) 387 # if (SIZEOF_LONG_INT == 8) 388 # define ODBCINT64 long 389 # define UODBCINT64 unsigned long 390 # else 391 # ifdef HAVE_LONG_LONG 392 # define ODBCINT64 long long 393 # define UODBCINT64 unsigned long long 394 # else 395 /* 396 * may fail in some cases, but what else can we do ? 397 */ 398 struct __bigint_struct 399 { 400 int hiword; 401 unsigned int loword; 402 }; 403 struct __bigint_struct_u 404 { 405 unsigned int hiword; 406 unsigned int loword; 407 }; 408 # define ODBCINT64 struct __bigint_struct 409 # define UODBCINT64 struct __bigint_struct_u 410 # endif 411 # endif 412 #endif 413 #endif 414 415 #ifdef ODBCINT64 416 typedef ODBCINT64 SQLBIGINT; 417 #endif 418 #ifdef UODBCINT64 419 typedef UODBCINT64 SQLUBIGINT; 420 #endif 421 422 423 /**************************** 424 * cursor and bookmark 425 ***************************/ 426 #if (ODBCVER >= 0x0300) 427 #define SQL_MAX_NUMERIC_LEN 16 428 typedef struct tagSQL_NUMERIC_STRUCT 429 { 430 SQLCHAR precision; 431 SQLSCHAR scale; 432 SQLCHAR sign; /* 1=pos 0=neg */ 433 SQLCHAR val[SQL_MAX_NUMERIC_LEN]; 434 } SQL_NUMERIC_STRUCT; 435 #endif 436 437 #if (ODBCVER >= 0x0350) 438 #ifdef GUID_DEFINED 439 #ifndef ALLREADY_HAVE_WINDOWS_TYPE 440 typedef GUID SQLGUID; 441 #else 442 typedef struct tagSQLGUID 443 { 444 DWORD Data1; 445 WORD Data2; 446 WORD Data3; 447 BYTE Data4[ 8 ]; 448 } SQLGUID; 449 #endif 450 #else 451 typedef struct tagSQLGUID 452 { 453 DWORD Data1; 454 WORD Data2; 455 WORD Data3; 456 BYTE Data4[ 8 ]; 457 } SQLGUID; 458 #endif 459 #endif 460 461 typedef SQLULEN BOOKMARK; 462 463 typedef WCHAR SQLWCHAR; 464 465 #ifdef UNICODE 466 typedef SQLWCHAR SQLTCHAR; 467 #else 468 typedef SQLCHAR SQLTCHAR; 469 #endif 470 471 #ifdef __cplusplus 472 } 473 #endif 474 475 #endif 476 477 478 479