Add unit test for recent WvLog/WvDelayedString bug.
[versaplex.git] / vxodbc / psqlodbc.h
blob459dad0ecd058d096995d877ecb56bad6b03591b
1 /* File: psqlodbc.h
3 * Description: This file contains defines and declarations that are related to
4 * the entire driver.
6 * Comments: See "notice.txt" for copyright and license information.
8 * $Id: psqlodbc.h,v 1.118 2007/04/11 16:36:47 h-saito Exp $
12 #ifndef __PSQLODBC_H__
13 #define __PSQLODBC_H__
15 /* #define __MS_REPORTS_ANSI_CHAR__ */
17 #ifdef __cplusplus
18 #define EXTERN_C extern "C"
19 #else
20 #define EXTERN_C
21 #endif
23 #ifndef WIN32
24 #include "config.h"
25 #else
26 #define WIN32_LEAN_AND_MEAN
27 #include <windows.h>
28 #endif
30 #include <stdio.h> /* for FILE* pointers: see GLOBAL_VALUES */
31 #ifdef POSIX_MULTITHREAD_SUPPORT
32 #include <pthread.h>
33 #endif
34 #include "version.h"
36 #ifdef WIN32
37 #ifdef _DEBUG
38 #ifndef _MEMORY_DEBUG_
39 #include <stdlib.h>
40 #include <malloc.h>
41 #define _CRTDBG_MAP_ALLOC
42 #include <crtdbg.h>
43 #endif /* _MEMORY_DEBUG_ */
44 #endif /* _DEBUG */
45 #endif /* WIN32 */
47 #ifdef WIN32
48 //#include <delayimp.h>
49 #endif /* WIN32 */
50 /* Must come before sql.h */
51 #ifndef ODBCVER
52 #define ODBCVER 0x0351
53 #endif /* ODBCVER_REP */
55 #define NAMEDATALEN_V72 32
56 #define NAMEDATALEN_V73 64
57 #ifndef NAMESTORAGELEN
58 #define NAMESTORAGELEN 64
59 #endif /* NAMESTORAGELEN */
62 #ifndef WIN32
63 #undef WIN_MULTITHREAD_SUPPORT
64 #endif
65 #if defined(WIN32) || defined(WITH_UNIXODBC) || defined(WITH_IODBC)
66 #include <sql.h>
67 #include <sqlext.h>
68 #if defined(WIN32) && (_MSC_VER < 1300) /* in case of VC6 or under */
69 #define SQLLEN SQLINTEGER
70 #define SQLULEN SQLUINTEGER
71 #define SQLSETPOSIROW SQLUSMALLINT
72 /* VC6 bypasses 64bit mode. */
73 #define DWLP_USER DWL_USER
74 #define ULONG_PTR ULONG
75 #define LONG_PTR LONG
76 #define SetWindowLongPtr(hdlg, DWLP_USER, lParam) SetWindowLong(hdlg, DWLP_USER, lParam)
77 #define GetWindowLongPtr(hdlg, DWLP_USER) GetWindowLong(hdlg, DWLP_USER);
78 #endif
79 #else
80 #include "iodbc.h"
81 #include "isql.h"
82 #include "isqlext.h"
83 #endif /* WIN32 */
85 #if defined(WIN32)
86 #include <odbcinst.h>
87 #elif defined(WITH_UNIXODBC)
88 #include <odbcinst.h>
89 #elif defined(WITH_IODBC)
90 #include <iodbcinst.h>
91 #else
92 #include "gpps.h"
93 #endif
95 #ifdef __cplusplus
96 extern "C" {
97 #endif
99 #define Int4 int
100 #define UInt4 unsigned int
101 #define Int2 short
102 #define UInt2 unsigned short
103 typedef UInt4 OID;
105 #ifdef WIN32
106 #define ssize_t SSIZE_T
107 #define FORMAT_SIZE_T "%Iu" /* size_t */
108 #define FORMAT_SSIZE_T "%Id" /* ssize_t */
109 #define FORMAT_INTEGER "%ld" /* SQLINTEGER */
110 #define FORMAT_UINTEGER "%lu" /* SQLUINTEGER */
111 #ifdef _WIN64
112 #define FORMAT_LEN "%I64d" /* SQLLEN */
113 #define FORMAT_ULEN "%I64u" /* SQLULEN */
114 #define FORMAT_LPTR "%I64d" /* LONG_PTR */
115 #define FORMAT_ULPTR "%I64u" /* ULONG_PTR */
116 #else
117 #define FORMAT_LEN "%ld" /* SQLLEN */
118 #define FORMAT_ULEN "%lu" /* SQLULEN */
119 #define FORMAT_LPTR "%ld" /* LONG_PTR */
120 #define FORMAT_ULPTR "%lu" /* ULONG_PTR */
121 #endif /* _WIN64 */
122 #else
123 #define FORMAT_SIZE_T "%xu" /* size_t */
124 #define FORMAT_SSIZE_T "%xd" /* ssize_t */
125 #ifndef HAVE_SSIZE_T
126 typedef long ssize_t
127 #endif /* HAVE_SSIZE_T */
128 #if (SIZEOF_VOID_P == SIZEOF_LONG)
129 typedef long LONG_PTR;
130 typedef unsigned long ULONG_PTR;
131 #define FORMAT_LPTR "%ld" /* LONG_PTR */
132 #define FORMAT_ULPTR "%lu" /* ULONG_PTR */
133 #elif defined (HAVE_LONG_LONG)
134 typedef long long LONG_PTR;
135 typedef unsigned long long ULONG_PTR;
136 #define FORMAT_LPTR "%lld" /* LONG_PTR */
137 #define FORMAT_ULPTR "%llu" /* ULONG_PTR */
138 #else
139 #error appropriate long pointer type not found
140 #endif /* SIZEOF_VOID_P */
141 #if (SIZEOF_VOID_P == 8)
142 #define FORMAT_INTEGER "%d" /* SQLINTEGER */
143 #define FORMAT_UINTEGER "%u" /* SQLUINTEGER */
144 #if defined(WITH_UNIXODBC) && !defined(BUILD_REAL_64_BIT_MODE)
145 #define FORMAT_LEN "%d" /* SQLLEN */
146 #define FORMAT_ULEN "%u" /* SQLULEN */
147 #else
148 #define FORMAT_LEN "%ld" /* SQLLEN */
149 #define FORMAT_ULEN "%lu" /* SQLULEN */
150 #endif /* WITH_UNIXODBC */
151 #else
152 #define FORMAT_LEN "%ld" /* SQLLEN */
153 #define FORMAT_ULEN "%lu" /* SQLULEN */
154 #define FORMAT_INTEGER "%ld" /* SQLINTEGER */
155 #define FORMAT_UINTEGER "%lu" /* SQLUINTEGER */
156 #endif /* SIZEOF_VOID_P */
157 #endif /* WIN32 */
158 #define CAST_PTR(type, ptr) (type)((LONG_PTR)(ptr))
159 #define CAST_UPTR(type, ptr) (type)((ULONG_PTR)(ptr))
160 #ifndef SQL_IS_LEN
161 #define SQL_IS_LEN (-1000)
162 #endif /* SQL_IS_LEN */
164 #ifndef WIN32
165 #if !defined(WITH_UNIXODBC) && !defined(WITH_IODBC)
166 typedef float SFLOAT;
167 typedef double SDOUBLE;
168 #endif /* WITH_UNIXODBC */
170 #ifndef CALLBACK
171 #define CALLBACK
172 #endif /* CALLBACK */
173 #endif /* WIN32 */
175 #ifndef WIN32
176 #define stricmp strcasecmp
177 #define strnicmp strncasecmp
178 #ifndef TRUE
179 #define TRUE (BOOL)1
180 #endif /* TRUE */
181 #ifndef FALSE
182 #define FALSE (BOOL)0
183 #endif /* FALSE */
184 #else
185 #define snprintf _snprintf
186 #define strdup _strdup
187 #define strnicmp _strnicmp
188 #define stricmp _stricmp
189 #define vsnprintf _vsnprintf
190 #endif /* WIN32 */
192 #ifndef SQL_ATTR_APP_ROW_DESC
193 #define SQL_ATTR_APP_ROW_DESC 10010
194 #endif
195 #ifndef SQL_ATTR_APP_PARAM_DESC
196 #define SQL_ATTR_APP_PARAM_DESC 10011
197 #endif
198 #ifndef SQL_ATTR_IMP_ROW_DESC
199 #define SQL_ATTR_IMP_ROW_DESC 10012
200 #endif
201 #ifndef SQL_ATTR_IMP_PARAM_DESC
202 #define SQL_ATTR_IMP_PARAM_DESC 10013
203 #endif
205 /* Driver stuff */
207 #define DRIVERNAME "Versaplex ODBC"
208 #define DRIVER_ODBC_VER "03.51"
209 #define DBMS_NAME "Versaplex"
211 #ifdef WIN32
212 #define DRIVER_FILE_NAME "VXODBC.DLL"
213 #else
214 #define DRIVER_FILE_NAME "vxodbc.so"
215 #endif /* WIN32 */
217 #define NULL_CATALOG_NAME ""
219 /* ESCAPEs */
220 #define ESCAPE_IN_LITERAL '\\'
221 #define BYTEA_ESCAPE_CHAR '\\'
222 #define SEARCH_PATTERN_ESCAPE '\\'
223 #define LITERAL_QUOTE '\''
224 #define IDENTIFIER_QUOTE '\"'
225 #define DOLLAR_QUOTE '$'
226 #define LITERAL_EXT 'E'
227 #define PG_CARRIAGE_RETURN '\r'
228 #define PG_LINEFEED '\n'
230 /* Limits */
231 #define BLCKSZ 4096
232 #define MAXPGPATH 1024
234 #define MAX_MESSAGE_LEN 65536 /* This puts a limit on
235 * query size but I don't */
236 /* see an easy way round this - DJP 24-1-2001 */
237 #define MAX_CONNECT_STRING 4096
238 #define ERROR_MSG_LENGTH 4096
239 #define FETCH_MAX 100 /* default number of rows to cache
240 * for declare/fetch */
241 #define TUPLE_MALLOC_INC 100
242 #define SOCK_BUFFER_SIZE 4096 /* default socket buffer
243 * size */
244 #define MAX_CONNECTIONS 128 /* conns per environment
245 * (arbitrary) */
246 #define MAX_FIELDS 512
247 #define BYTELEN 8
248 #define VARHDRSZ sizeof(Int4)
250 #ifdef NAMEDATALEN
251 #define MAX_SCHEMA_LEN NAMEDATALEN
252 #define MAX_TABLE_LEN NAMEDATALEN
253 #define MAX_COLUMN_LEN NAMEDATALEN
254 #define NAME_FIELD_SIZE NAMEDATALEN /* size of name fields */
255 #if (NAMEDATALEN > NAMESTORAGELEN)
256 #undef NAMESTORAGELEN
257 #define NAMESTORAGELEN NAMEDATALEN
258 #endif
259 #endif /* NAMEDATALEN */
260 #define MAX_CURSOR_LEN 32
262 #define SCHEMA_NAME_STORAGE_LEN NAMESTORAGELEN
263 #define TABLE_NAME_STORAGE_LEN NAMESTORAGELEN
264 #define COLUMN_NAME_STORAGE_LEN NAMESTORAGELEN
265 #define INDEX_KEYS_STORAGE_COUNT 32
267 /* Registry length limits */
268 #define LARGE_REGISTRY_LEN 4096 /* used for special cases */
269 #define MEDIUM_REGISTRY_LEN 256 /* normal size for
270 * user,database,etc. */
271 #define SMALL_REGISTRY_LEN 10 /* for 1/0 settings */
274 /* These prefixes denote system tables */
275 #define POSTGRES_SYS_PREFIX "pg_"
276 #define KEYS_TABLE "dd_fkey"
278 /* Info limits */
279 #define MAX_INFO_STRING 128
280 #define MAX_KEYPARTS 20
281 #define MAX_KEYLEN 512 /* max key of the form
283 * "date+outlet+invoice" */
284 /* POSIX defines a PATH_MAX.( wondows is _MAX_PATH ..) */
285 #ifndef PATH_MAX
286 #define PATH_MAX 1024
287 #endif
289 #define MAX_ROW_SIZE 0 /* Unlimited rowsize with the
290 * Tuple Toaster */
291 #define MAX_STATEMENT_LEN 0 /* Unlimited statement size with
292 * 7.0 */
294 /* Previously, numerous query strings were defined of length MAX_STATEMENT_LEN */
295 /* Now that's 0, lets use this instead. DJP 24-1-2001 */
296 #define STD_STATEMENT_LEN MAX_MESSAGE_LEN
298 #define PG62 "6.2" /* "Protocol" key setting
299 * to force Postgres 6.2 */
300 #define PG63 "6.3" /* "Protocol" key setting
301 * to force postgres 6.3 */
302 #define PG64 "6.4"
303 #define PG74REJECTED "reject7.4"
304 #define PG74 "7.4"
306 typedef int (*PQFUNC)();
308 typedef struct ConnectionClass_ ConnectionClass;
309 typedef struct StatementClass_ StatementClass;
310 typedef struct QResultClass_ QResultClass;
311 typedef struct BindInfoClass_ BindInfoClass;
312 typedef struct ParameterInfoClass_ ParameterInfoClass;
313 typedef struct ParameterImplClass_ ParameterImplClass;
314 typedef struct ColumnInfoClass_ ColumnInfoClass;
315 typedef struct EnvironmentClass_ EnvironmentClass;
316 typedef struct TupleField_ TupleField;
317 typedef struct KeySet_ KeySet;
318 typedef struct Rollback_ Rollback;
319 typedef struct ARDFields_ ARDFields;
320 typedef struct APDFields_ APDFields;
321 typedef struct IRDFields_ IRDFields;
322 typedef struct IPDFields_ IPDFields;
324 typedef struct col_info COL_INFO;
326 typedef struct GlobalValues_
328 char onlyread; /* readonly is reserved on Digital C++
329 * compiler */
330 } GLOBAL_VALUES;
332 typedef struct StatementOptions_
334 SQLLEN maxRows;
335 SQLLEN maxLength;
336 SQLLEN keyset_size;
337 SQLUINTEGER cursor_type;
338 SQLUINTEGER scroll_concurrency;
339 SQLUINTEGER retrieve_data;
340 SQLUINTEGER use_bookmarks;
341 void *bookmark_ptr;
342 SQLUINTEGER metadata_id;
343 } StatementOptions;
345 /* Used to pass extra query info to send_query */
346 typedef struct QueryInfo_
348 SQLLEN row_size;
349 QResultClass *result_in;
350 const char *cursor;
351 } QueryInfo;
353 /* Used to save the error information */
354 typedef struct
356 UInt4 status;
357 Int4 errorsize;
358 Int2 recsize;
359 Int2 errorpos;
360 char sqlstate[8];
361 SQLLEN diag_row_count;
362 char __error_message[1];
363 } PG_ErrorInfo;
364 PG_ErrorInfo *ER_Constructor(SDWORD errornumber, const char *errormsg);
365 PG_ErrorInfo *ER_Dup(const PG_ErrorInfo *from);
366 void ER_Destructor(PG_ErrorInfo *);
367 RETCODE SQL_API ER_ReturnError(PG_ErrorInfo **, SQLSMALLINT, UCHAR FAR *,
368 SQLINTEGER FAR *, UCHAR FAR *, SQLSMALLINT, SQLSMALLINT FAR *, UWORD);
370 void logs_on_off(int cnopen, int, int);
372 #define PG_TYPE_LO_UNDEFINED (-999) /* hack until permanent
373 * type available */
374 #define PG_TYPE_LO_NAME "lo"
375 #define CTID_ATTNUM (-1) /* the attnum of ctid */
376 #define OID_ATTNUM (-2) /* the attnum of oid */
377 #define XMIN_ATTNUM (-3) /* the attnum of xmin */
379 /* sizes */
380 #define TEXT_FIELD_SIZE 8190 /* size of default text fields
381 * (not including null term) */
382 #define MAX_VARCHAR_SIZE 255 /* default maximum size of
383 * varchar fields (not including null term) */
384 #define INFO_VARCHAR_SIZE 254 /* varchar field size
385 * used in info.c */
387 #define PG_NUMERIC_MAX_PRECISION 1000
388 #define PG_NUMERIC_MAX_SCALE 1000
390 #define INFO_INQUIRY_LEN 8192 /* this seems sufficiently big for
391 * queries used in info.c inoue
392 * 2001/05/17 */
394 #define LENADDR_SHIFT(x, sft) ((x) ? (SQLLEN *)((char *)(x) + (sft)) : NULL)
396 int initialize_global_cs(void);
397 #ifdef POSIX_MULTITHREAD_SUPPORT
398 #if !defined(HAVE_ECO_THREAD_LOCKS)
399 #define POSIX_THREADMUTEX_SUPPORT
400 #endif /* HAVE_ECO_THREAD_LOCKS */
401 #endif /* POSIX_MULTITHREAD_SUPPORT */
403 #ifdef POSIX_THREADMUTEX_SUPPORT
404 const pthread_mutexattr_t *getMutexAttr(void);
405 #endif /* POSIX_THREADMUTEX_SUPPORT */
406 #ifdef UNICODE_SUPPORT
407 #define WCLEN sizeof(SQLWCHAR)
408 SQLULEN ucs2strlen(const SQLWCHAR *ucs2str);
409 char *ucs2_to_utf8(const SQLWCHAR *ucs2str, SQLLEN ilen, SQLLEN *olen, BOOL tolower);
410 SQLULEN utf8_to_ucs2_lf(const char * utf8str, SQLLEN ilen, BOOL lfconv, SQLWCHAR *ucs2str, SQLULEN buflen);
411 #define utf8_to_ucs2(utf8str, ilen, ucs2str, buflen) utf8_to_ucs2_lf(utf8str, ilen, FALSE, ucs2str, buflen)
412 #endif /* UNICODE_SUPPORT */
414 #ifdef _MEMORY_DEBUG_
415 void *debug_alloc(size_t);
416 void *debug_calloc(size_t, size_t);
417 void *debug_realloc(void *, size_t);
418 char *debug_strdup(const char *);
419 void *debug_memcpy(void *, const void *, size_t);
420 void *debug_memset(void *, int c, size_t);
421 char *debug_strcpy(char *, const char *);
422 char *debug_strncpy(char *, const char *, size_t);
423 char *debug_strncpy_null(char *, const char *, size_t);
424 void debug_free(void *);
425 void debug_memory_check(void);
427 #ifdef WIN32
428 #undef strdup
429 #undef strnicmp
430 #undef stricmp
431 #endif /* WIN32 */
432 #define malloc debug_alloc
433 #define realloc debug_realloc
434 #define calloc debug_calloc
435 #define strdup debug_strdup
436 #define free debug_free
437 #define strcpy debug_strcpy
438 #define strncpy debug_strncpy
439 /* #define strncpy_null debug_strncpy_null */
440 #define memcpy debug_memcpy
441 #define memset debug_memset
442 #endif /* _MEMORY_DEBUG_ */
444 #ifdef __cplusplus
446 #endif
448 #include "misc.h"
450 CSTR NULL_STRING = "";
451 CSTR PRINT_NULL = "(null)";
452 CSTR OID_NAME = "oid";
453 #endif /* __PSQLODBC_H__ */