6
6
* Comments: See "notice.txt" for copyright and license information.
8
* $Id: psqlodbc.h,v 1.94 2006/01/26 18:44:28 luf Exp $
8
* $Id: psqlodbc.h,v 1.122 2008/05/03 05:57:42 hinoue Exp $
12
12
#ifndef __PSQLODBC_H__
13
13
#define __PSQLODBC_H__
15
/* #define __MS_REPORTS_ANSI_CHAR__ */
16
18
#include "config.h"
20
#define WIN32_LEAN_AND_MEAN
18
21
#include <windows.h>
21
24
#include <stdio.h> /* for FILE* pointers: see GLOBAL_VALUES */
22
25
#ifdef POSIX_MULTITHREAD_SUPPORT
24
26
#include <pthread.h>
26
28
#include "version.h"
32
#ifndef _MEMORY_DEBUG_
34
#if (_MSC_VER < 1400) /* in case of VC7 or under */
37
#define _CRTDBG_MAP_ALLOC
39
#endif /* _MEMORY_DEBUG_ */
28
46
/* Must come before sql.h */
30
#define ODBCVER 0x0300
48
#define ODBCVER 0x0250
49
#endif /* ODBCVER_REP */
33
51
#define NAMEDATALEN_V72 32
34
52
#define NAMEDATALEN_V73 64
41
59
#undef WIN_MULTITHREAD_SUPPORT
61
#if defined(WIN32) || defined(WITH_UNIXODBC) || defined(WITH_IODBC)
45
63
#include <sqlext.h>
46
#if defined(UNICODE_SUPPORT) && !defined(WIN32)
47
# include <sqlucode.h>
64
#if defined(WIN32) && (_MSC_VER < 1300) /* in case of VC6 or under */
65
#define SQLLEN SQLINTEGER
66
#define SQLULEN SQLUINTEGER
67
#define SQLSETPOSIROW SQLUSMALLINT
68
/* VC6 bypasses 64bit mode. */
69
#define DWLP_USER DWL_USER
70
#define ULONG_PTR ULONG
72
#define SetWindowLongPtr(hdlg, DWLP_USER, lParam) SetWindowLong(hdlg, DWLP_USER, lParam)
73
#define GetWindowLongPtr(hdlg, DWLP_USER) GetWindowLong(hdlg, DWLP_USER);
51
82
#include <odbcinst.h>
54
85
#elif defined(WITH_IODBC)
55
86
#include <iodbcinst.h>
57
#error "don't know where to get odbcinst.h"
96
#define UInt4 unsigned int
98
#define UInt2 unsigned short
102
#define ssize_t SSIZE_T
103
#define FORMAT_SIZE_T "%Iu" /* size_t */
104
#define FORMAT_SSIZE_T "%Id" /* ssize_t */
105
#define FORMAT_INTEGER "%ld" /* SQLINTEGER */
106
#define FORMAT_UINTEGER "%lu" /* SQLUINTEGER */
108
#define FORMAT_LEN "%I64d" /* SQLLEN */
109
#define FORMAT_ULEN "%I64u" /* SQLULEN */
110
#define FORMAT_LPTR "%I64d" /* LONG_PTR */
111
#define FORMAT_ULPTR "%I64u" /* ULONG_PTR */
113
#define FORMAT_LEN "%ld" /* SQLLEN */
114
#define FORMAT_ULEN "%lu" /* SQLULEN */
115
#define FORMAT_LPTR "%ld" /* LONG_PTR */
116
#define FORMAT_ULPTR "%lu" /* ULONG_PTR */
119
#define FORMAT_SIZE_T "%xu" /* size_t */
120
#define FORMAT_SSIZE_T "%xd" /* ssize_t */
123
#endif /* HAVE_SSIZE_T */
124
#if (SIZEOF_VOID_P == SIZEOF_LONG)
125
typedef long LONG_PTR;
126
typedef unsigned long ULONG_PTR;
127
#define FORMAT_LPTR "%ld" /* LONG_PTR */
128
#define FORMAT_ULPTR "%lu" /* ULONG_PTR */
129
#elif defined (HAVE_LONG_LONG)
130
typedef long long LONG_PTR;
131
typedef unsigned long long ULONG_PTR;
132
#define FORMAT_LPTR "%lld" /* LONG_PTR */
133
#define FORMAT_ULPTR "%llu" /* ULONG_PTR */
135
#error appropriate long pointer type not found
136
#endif /* SIZEOF_VOID_P */
137
#if (SIZEOF_VOID_P == 8)
138
#define FORMAT_INTEGER "%d" /* SQLINTEGER */
139
#define FORMAT_UINTEGER "%u" /* SQLUINTEGER */
140
#if defined(WITH_UNIXODBC) && !defined(BUILD_REAL_64_BIT_MODE)
141
#define FORMAT_LEN "%d" /* SQLLEN */
142
#define FORMAT_ULEN "%u" /* SQLULEN */
144
#define FORMAT_LEN "%ld" /* SQLLEN */
145
#define FORMAT_ULEN "%lu" /* SQLULEN */
146
#endif /* WITH_UNIXODBC */
148
#define FORMAT_LEN "%ld" /* SQLLEN */
149
#define FORMAT_ULEN "%lu" /* SQLULEN */
150
#define FORMAT_INTEGER "%ld" /* SQLINTEGER */
151
#define FORMAT_UINTEGER "%lu" /* SQLUINTEGER */
152
#endif /* SIZEOF_VOID_P */
154
#define CAST_PTR(type, ptr) (type)((LONG_PTR)(ptr))
155
#define CAST_UPTR(type, ptr) (type)((ULONG_PTR)(ptr))
157
#define SQL_IS_LEN (-1000)
158
#endif /* SQL_IS_LEN */
63
# if defined(HAVE_INTTYPES_H)
64
# include <inttypes.h>
66
# if defined(HAVE_STDINT_H)
72
# define UInt4 uint32_t
74
# define UInt2 uint16_t
76
# if !defined(WITH_UNIXODBC) && !defined(WITH_IODBC)
161
#if !defined(WITH_UNIXODBC) && !defined(WITH_IODBC)
77
162
typedef float SFLOAT;
78
163
typedef double SDOUBLE;
88
# define UInt4 unsigned int
90
# define UInt2 unsigned short
164
#endif /* WITH_UNIXODBC */
168
#endif /* CALLBACK */
103
172
#define stricmp strcasecmp
104
173
#define strnicmp strncasecmp
178
#define FALSE (BOOL)0
106
181
#define snprintf _snprintf
183
#define strdup _strdup
185
#define strnicmp _strnicmp
186
#define stricmp _stricmp
187
#define vsnprintf _vsnprintf
109
190
#ifndef SQL_ATTR_APP_ROW_DESC
110
191
#define SQL_ATTR_APP_ROW_DESC 10010
122
203
/* Driver stuff */
123
#define DBMS_NAME "PostgreSQL"
205
#define DRIVERNAME "PostgreSQL ODBC"
206
#if (ODBCVER >= 0x0300)
207
#if (ODBCVER >= 0x0351)
208
#define DRIVER_ODBC_VER "03.51"
124
210
#define DRIVER_ODBC_VER "03.00"
126
#ifdef UNICODE_SUPPORT
127
#define DRIVERNAME "PostgreSQL Unicode"
211
#endif /* ODBCVER 0x0351 */
213
#ifdef UNICODE_SUPPORT
214
#define DBMS_NAME "PostgreSQL Unicode"
129
#define DRIVERNAME "PostgreSQL ANSI"
216
#define DBMS_NAME "PostgreSQL ANSI"
130
217
#endif /* UNICODE_SUPPORT */
218
#endif /* DBMS_NAME */
220
#define DRIVER_ODBC_VER "02.50"
221
#define DBMS_NAME "PostgreSQL Legacy"
225
#if (ODBCVER >= 0x0300)
226
#ifdef UNICODE_SUPPORT
227
#if (ODBCVER >= 0x0350)
228
#define DRIVER_FILE_NAME "PSQLODBC35W.DLL"
230
#define DRIVER_FILE_NAME "PSQLODBC30W.DLL"
231
#endif /* ODBCVER 0x0350 */
233
#define DRIVER_FILE_NAME "PSQLODBC.DLL"
234
#endif /* UNICODE_SUPPORT */
236
#define DRIVER_FILE_NAME "PSQLODBC25.DLL"
237
#endif /* ODBCVER 0x0300 */
133
242
#ifdef UNICODE_SUPPORT
134
#define DRIVER_FILE_NAME "PSQLODBCW.DLL"
243
#define DRIVER_FILE_NAME "psqlodbcw.so"
136
#define DRIVER_FILE_NAME "PSQLODBCA.DLL"
245
#define DRIVER_FILE_NAME "psqlodbca.so"
139
#define DRIVER_FILE_NAME "libpsqlodbc.so"
140
247
#endif /* WIN32 */
249
#define NULL_CATALOG_NAME ""
252
#define ESCAPE_IN_LITERAL '\\'
253
#define BYTEA_ESCAPE_CHAR '\\'
254
#define SEARCH_PATTERN_ESCAPE '\\'
255
#define LITERAL_QUOTE '\''
256
#define IDENTIFIER_QUOTE '\"'
257
#define DOLLAR_QUOTE '$'
258
#define LITERAL_EXT 'E'
259
#define PG_CARRIAGE_RETURN '\r'
260
#define PG_LINEFEED '\n'
143
263
#define BLCKSZ 4096
144
264
#define MAXPGPATH 1024
146
#define MAX_MESSAGE_LEN 65536 /* This puts a limit on
147
* query size but I don't */
148
/* see an easy way round this - DJP 24-1-2001 */
266
#define MAX_MESSAGE_LEN 65536 /* This puts a limit on
267
* query size but I don't */
268
/* see an easy way round this - DJP 24-1-2001 */
149
269
#define MAX_CONNECT_STRING 4096
150
270
#define ERROR_MSG_LENGTH 4096
151
#define SQLSTATE_LENGTH 8
152
#define FETCH_MAX 100 /* default number of rows to cache
153
* for declare/fetch */
271
#define FETCH_MAX 100 /* default number of rows to cache
272
* for declare/fetch */
154
273
#define TUPLE_MALLOC_INC 100
155
#define SOCK_BUFFER_SIZE 8192 /* default socket buffer
157
#define MAX_CONNECTIONS 128 /* conns per environment
274
#define SOCK_BUFFER_SIZE 4096 /* default socket buffer
276
#define MAX_CONNECTIONS 128 /* conns per environment
159
278
#define MAX_FIELDS 512
160
279
#define BYTELEN 8
161
280
#define VARHDRSZ sizeof(Int4)
178
297
#define INDEX_KEYS_STORAGE_COUNT 32
180
299
/* Registry length limits */
181
#define LARGE_REGISTRY_LEN 4096 /* used for special cases */
182
#define MEDIUM_REGISTRY_LEN 256 /* normal size for
183
* user,database,etc. */
300
#define LARGE_REGISTRY_LEN 4096 /* used for special cases */
301
#define MEDIUM_REGISTRY_LEN 256 /* normal size for
302
* user,database,etc. */
184
303
#define SMALL_REGISTRY_LEN 10 /* for 1/0 settings */
187
306
/* These prefixes denote system tables */
188
307
#define POSTGRES_SYS_PREFIX "pg_"
189
#define KEYS_TABLE "dd_fkey"
308
#define KEYS_TABLE "dd_fkey"
191
310
/* Info limits */
192
311
#define MAX_INFO_STRING 128
193
312
#define MAX_KEYPARTS 20
194
#define MAX_KEYLEN 512 /* max key of the form
195
* "date+outlet+invoice" */
196
#define MAX_ROW_SIZE 0 /* Unlimited rowsize with the
198
#define MAX_STATEMENT_LEN 0 /* Unlimited statement size with
313
#define MAX_KEYLEN 512 /* max key of the form
315
* "date+outlet+invoice" */
316
/* POSIX defines a PATH_MAX.( wondows is _MAX_PATH ..) */
319
#define PATH_MAX _MAX_PATH
321
#define PATH_MAX 1024
322
#endif /* _MAX_PATH */
323
#endif /* PATH_MAX */
325
#define MAX_ROW_SIZE 0 /* Unlimited rowsize with the
327
#define MAX_STATEMENT_LEN 0 /* Unlimited statement size with
201
330
/* Previously, numerous query strings were defined of length MAX_STATEMENT_LEN */
202
331
/* Now that's 0, lets use this instead. DJP 24-1-2001 */
203
332
#define STD_STATEMENT_LEN MAX_MESSAGE_LEN
334
#define PG62 "6.2" /* "Protocol" key setting
335
* to force Postgres 6.2 */
336
#define PG63 "6.3" /* "Protocol" key setting
337
* to force postgres 6.3 */
339
#define PG74REJECTED "reject7.4"
342
typedef int (*PQFUNC)();
205
344
typedef struct ConnectionClass_ ConnectionClass;
206
345
typedef struct StatementClass_ StatementClass;
207
346
typedef struct QResultClass_ QResultClass;
347
typedef struct SocketClass_ SocketClass;
208
348
typedef struct BindInfoClass_ BindInfoClass;
209
349
typedef struct ParameterInfoClass_ ParameterInfoClass;
210
350
typedef struct ParameterImplClass_ ParameterImplClass;
211
351
typedef struct ColumnInfoClass_ ColumnInfoClass;
212
typedef struct TupleListClass_ TupleListClass;
213
352
typedef struct EnvironmentClass_ EnvironmentClass;
214
typedef struct TupleNode_ TupleNode;
215
353
typedef struct TupleField_ TupleField;
216
354
typedef struct KeySet_ KeySet;
217
355
typedef struct Rollback_ Rollback;
246
384
char cancel_as_freestmt;
247
385
char extra_systable_prefixes[MEDIUM_REGISTRY_LEN];
248
386
char conn_settings[LARGE_REGISTRY_LEN];
387
char protocol[SMALL_REGISTRY_LEN];
251
390
typedef struct StatementOptions_
257
int scroll_concurrency;
395
SQLUINTEGER cursor_type;
396
SQLUINTEGER scroll_concurrency;
397
SQLUINTEGER retrieve_data;
398
SQLUINTEGER use_bookmarks;
260
399
void *bookmark_ptr;
400
#if (ODBCVER >= 0x0300)
401
SQLUINTEGER metadata_id;
262
403
} StatementOptions;
264
405
/* Used to pass extra query info to send_query */
265
406
typedef struct QueryInfo_
268
409
QResultClass *result_in;
272
413
/* Used to save the error information */
279
char sqlstate[SQLSTATE_LENGTH];
421
SQLLEN diag_row_count;
281
422
char __error_message[1];
284
424
PG_ErrorInfo *ER_Constructor(SDWORD errornumber, const char *errormsg);
425
PG_ErrorInfo *ER_Dup(const PG_ErrorInfo *from);
285
426
void ER_Destructor(PG_ErrorInfo *);
286
RETCODE SQL_API ER_ReturnError(PG_ErrorInfo *, SWORD, UCHAR FAR *,
287
SDWORD FAR *, UCHAR FAR *, SWORD, SWORD FAR *, UWORD);
427
RETCODE SQL_API ER_ReturnError(PG_ErrorInfo **, SQLSMALLINT, UCHAR FAR *,
428
SQLINTEGER FAR *, UCHAR FAR *, SQLSMALLINT, SQLSMALLINT FAR *, UWORD);
289
430
void logs_on_off(int cnopen, int, int);
291
#define PG_TYPE_LO_UNDEFINED (-999) /* hack until permanent
293
#define PG_TYPE_LO_NAME "lo"
294
#define OID_ATTNUM (-2) /* the attnum in pg_index
432
#define PG_TYPE_LO_UNDEFINED (-999) /* hack until permanent
434
#define PG_TYPE_LO_NAME "lo"
435
#define CTID_ATTNUM (-1) /* the attnum of ctid */
436
#define OID_ATTNUM (-2) /* the attnum of oid */
437
#define XMIN_ATTNUM (-3) /* the attnum of xmin */
298
#define TEXT_FIELD_SIZE 8190 /* size of text fields
299
* (not including null
301
#define MAX_VARCHAR_SIZE 254 /* maximum size of a varchar (not
302
* including null term) */
440
#define TEXT_FIELD_SIZE 8190 /* size of default text fields
441
* (not including null term) */
442
#define MAX_VARCHAR_SIZE 255 /* default maximum size of
443
* varchar fields (not including null term) */
444
#define INFO_VARCHAR_SIZE 254 /* varchar field size
304
447
#define PG_NUMERIC_MAX_PRECISION 1000
305
448
#define PG_NUMERIC_MAX_SCALE 1000
307
450
#define INFO_INQUIRY_LEN 8192 /* this seems sufficiently big for
308
* queries used in info.c inoue
451
* queries used in info.c inoue
454
#define LENADDR_SHIFT(x, sft) ((x) ? (SQLLEN *)((char *)(x) + (sft)) : NULL)
313
456
int initialize_global_cs(void);
314
457
#ifdef POSIX_MULTITHREAD_SUPPORT
320
463
#ifdef POSIX_THREADMUTEX_SUPPORT
321
464
const pthread_mutexattr_t *getMutexAttr(void);
322
465
#endif /* POSIX_THREADMUTEX_SUPPORT */
323
#ifdef UNICODE_SUPPORT
466
#ifdef UNICODE_SUPPORT
324
467
#define WCLEN sizeof(SQLWCHAR)
325
UInt4 ucs2strlen(const SQLWCHAR *ucs2str);
326
char *ucs2_to_utf8(const SQLWCHAR *ucs2str, Int4 ilen, UInt4 *olen, BOOL tolower);
327
UInt4 utf8_to_ucs2_lf(const char * utf8str, Int4 ilen, BOOL lfconv, SQLWCHAR *ucs2str, UInt4 buflen);
468
SQLULEN ucs2strlen(const SQLWCHAR *ucs2str);
469
char *ucs2_to_utf8(const SQLWCHAR *ucs2str, SQLLEN ilen, SQLLEN *olen, BOOL tolower);
470
SQLULEN utf8_to_ucs2_lf(const char * utf8str, SQLLEN ilen, BOOL lfconv, SQLWCHAR *ucs2str, SQLULEN buflen);
328
471
#define utf8_to_ucs2(utf8str, ilen, ucs2str, buflen) utf8_to_ucs2_lf(utf8str, ilen, FALSE, ucs2str, buflen)
329
472
#endif /* UNICODE_SUPPORT */
331
/*#define _MEMORY_DEBUG_ */
332
475
#ifdef _MEMORY_DEBUG_
333
476
void *debug_alloc(size_t);
334
477
void *debug_calloc(size_t, size_t);
335
478
void *debug_realloc(void *, size_t);
336
479
char *debug_strdup(const char *);
480
void *debug_memcpy(void *, const void *, size_t);
481
void *debug_memset(void *, int c, size_t);
482
char *debug_strcpy(char *, const char *);
483
char *debug_strncpy(char *, const char *, size_t);
484
char *debug_strncpy_null(char *, const char *, size_t);
337
485
void debug_free(void *);
338
486
void debug_memory_check(void);
340
491
#define malloc debug_alloc
341
492
#define realloc debug_realloc
342
493
#define calloc debug_calloc
343
494
#define strdup debug_strdup
344
495
#define free debug_free
496
#define strcpy debug_strcpy
497
#define strncpy debug_strncpy
498
/* #define strncpy_null debug_strncpy_null */
499
#define memcpy debug_memcpy
500
#define memset debug_memset
345
501
#endif /* _MEMORY_DEBUG_ */
509
CSTR NULL_STRING = "";
510
CSTR PRINT_NULL = "(null)";
511
CSTR OID_NAME = "oid";
512
#endif /* __PSQLODBC_H__ */