-
Notifications
You must be signed in to change notification settings - Fork 156
/
oracle_fdw.h
255 lines (233 loc) · 8.94 KB
/
oracle_fdw.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*-------------------------------------------------------------------------
*
* oracle_fdw.h
* This header file contains all definitions that are shared by
* oracle_fdw.c and oracle_utils.c.
* It is necessary to split oracle_fdw into two source files because
* PostgreSQL and Oracle headers cannot be #included at the same time.
*
*-------------------------------------------------------------------------
*/
/* this one is safe to include and gives us Oid */
#include "postgres_ext.h"
#include <stdint.h>
#include <sys/types.h>
/* oracle_fdw version */
#define ORACLE_FDW_VERSION "2.8.0devel"
/* definitions that need OCI */
#ifdef OCI_ORACLE
/*
* Types for a linked list for various handles.
* Oracle sessions can be multiplexed over one server connection.
*/
struct connEntry
{
char *user;
OCISvcCtx *svchp;
OCISession *userhp;
OCIType *geomtype;
struct stmtHandleEntry *stmtlist;
int xact_level; /* 0 = none, 1 = main, else subtransaction */
struct connEntry *next;
};
struct srvEntry
{
char *connectstring;
OCIServer *srvhp;
struct srvEntry *next;
struct connEntry *connlist;
int server_version[5];
};
struct envEntry
{
char *nls_lang;
char *timezone;
OCIEnv *envhp;
OCIError *errhp;
struct envEntry *next;
struct srvEntry *srvlist;
};
/*
* Represents one Oracle connection, points to cached entries.
* This is necessary to be able to pass them back to
* oracle_fdw.c without having to #include oci.h there.
*/
struct oracleSession
{
struct envEntry *envp;
struct srvEntry *srvp;
struct connEntry *connp;
OCIStmt *stmthp;
int have_nchar;
int server_version[5];
unsigned int last_batch; /* got OCI_NO_DATA */
unsigned int fetched_rows;
unsigned int current_row; /* first row is 1 */
};
#endif
typedef struct oracleSession oracleSession;
/* types for the Oracle table description */
typedef enum
{
ORA_TYPE_VARCHAR2,
ORA_TYPE_CHAR,
ORA_TYPE_NVARCHAR2,
ORA_TYPE_NCHAR,
ORA_TYPE_NUMBER,
ORA_TYPE_FLOAT,
ORA_TYPE_BINARYFLOAT,
ORA_TYPE_BINARYDOUBLE,
ORA_TYPE_RAW,
ORA_TYPE_DATE,
ORA_TYPE_TIMESTAMP,
ORA_TYPE_TIMESTAMPTZ,
ORA_TYPE_TIMESTAMPLTZ, /* TIMESTAMP WITH LOCAL TIME ZONE */
ORA_TYPE_INTERVALY2M,
ORA_TYPE_INTERVALD2S,
ORA_TYPE_BLOB,
ORA_TYPE_CLOB,
ORA_TYPE_BFILE,
ORA_TYPE_LONG,
ORA_TYPE_LONGRAW,
ORA_TYPE_GEOMETRY,
ORA_TYPE_XMLTYPE,
ORA_TYPE_OTHER
} oraType;
/* Some PostgreSQL versions have no constant definition for the OID of type uuid */
#ifndef UUIDOID
#define UUIDOID 2950
#endif
/* PostgreSQL before 9.6 doesn't have this macro */
#ifndef ALLOCSET_SMALL_SIZES
#define ALLOCSET_SMALL_SIZES \
ALLOCSET_SMALL_MINSIZE, ALLOCSET_SMALL_INITSIZE, ALLOCSET_SMALL_MAXSIZE
#endif
struct oraColumn
{
char *name; /* name in Oracle */
oraType oratype; /* data type in Oracle */
int scale; /* "scale" type modifier, used for NUMBERs */
char *pgname; /* PostgreSQL column name */
int pgattnum; /* PostgreSQL attribute number */
Oid pgtype; /* PostgreSQL data type */
int pgtypmod; /* PostgreSQL type modifier */
int used; /* is the column used in the query? */
int strip_zeros; /* should ASCII zero be removed from Oracle strings? */
int pkey; /* nonzero for primary keys, later set to the resjunk attribute number */
char *val; /* buffer for Oracle to return results in (LOB locators for LOBs) */
int32_t val_size; /* allocated size of one element in val */
uint16_t *val_len; /* array of actual lengths of val */
uint32_t val_len4; /* actual length of val - for bind callbacks */
int16_t *val_null; /* indicators for NULL values */
int varno; /* range table index of this column's relation */
};
struct oraTable
{
char *name; /* name in Oracle */
char *pgname; /* for error messages */
int ncols; /* number of columns */
int npgcols; /* number of columns (including dropped) in the PostgreSQL foreign table */
struct oraColumn **cols;
};
/* types to store parameter descriprions */
typedef enum {
BIND_STRING,
BIND_NUMBER,
BIND_LONG,
BIND_LONGRAW,
BIND_GEOMETRY,
BIND_OUTPUT
} oraBindType;
struct paramDesc
{
char *name; /* name we give the parameter */
Oid type; /* PostgreSQL data type */
oraBindType bindType; /* which type to use for binding to Oracle statement */
char *value; /* value rendered for Oracle */
void *node; /* the executable expression */
int colnum; /* corresponding column in oraTable (-1 in SELECT queries unless output column) */
void *bindh; /* bind handle */
struct paramDesc *next;
};
/* PostgreSQL error messages we need */
typedef enum
{
FDW_ERROR,
FDW_UNABLE_TO_ESTABLISH_CONNECTION,
FDW_UNABLE_TO_CREATE_REPLY,
FDW_UNABLE_TO_CREATE_EXECUTION,
FDW_TABLE_NOT_FOUND,
FDW_OUT_OF_MEMORY,
FDW_SERIALIZATION_FAILURE,
FDW_UNIQUE_VIOLATION,
FDW_DEADLOCK_DETECTED,
FDW_NOT_NULL_VIOLATION,
FDW_CHECK_VIOLATION,
FDW_FOREIGN_KEY_VIOLATION
} oraError;
/* encapsulates an Oracle geometry object */
typedef struct
{
struct sdo_geometry *geometry;
struct sdo_geometry_ind *indicator;
/* the following fields are extracted from "geometry" by unpack() */
int num_elems; /* number of SDO_ELEM_INFO entries, -1 for "not unpacked" */
unsigned *elem; /* unpacked SDO_ELEM_INFO entries */
int num_coords; /* number of SDO_ORDINATES entries, -1 for "not unpacked" */
double *coord; /* unpacked SDO_ORDINATES entries */
} ora_geometry;
/* Oracle transaction isolation levels */
typedef enum
{
ORA_TRANS_READ_COMMITTED,
ORA_TRANS_READ_ONLY,
ORA_TRANS_SERIALIZABLE
} oraIsoLevel;
/*
* functions defined in oracle_utils.c
*/
extern oracleSession *oracleGetSession(const char *connectstring, oraIsoLevel isolation_level, char *user, char *password, const char *nls_lang, const char *timezone, int have_nchar, const char *tablename, int curlevel);
extern void oracleCloseStatement(oracleSession *session);
extern void oracleCloseConnections(void);
extern void oracleShutdown(void);
extern void oracleCancel(void);
extern void oracleEndTransaction(void *arg, int is_commit, int silent);
extern void oracleEndSubtransaction(void *arg, int nest_level, int is_commit);
extern int oracleIsStatementOpen(oracleSession *session);
extern struct oraTable *oracleDescribe(oracleSession *session, char *dblink, char *schema, char *table, char *pgname, long max_long, int *has_geometry);
extern void oracleExplain(oracleSession *session, const char *query, int *nrows, char ***plan);
extern void oraclePrepareQuery(oracleSession *session, const char *query, const struct oraTable *oraTable, unsigned int prefetch, unsigned int lob_prefetch);
extern unsigned int oracleExecuteQuery(oracleSession *session, const struct oraTable *oraTable, struct paramDesc *paramList, unsigned int prefetch);
extern unsigned int oracleFetchNext(oracleSession *session, unsigned int prefetch);
extern void oracleExecuteCall(oracleSession *session, char * const stmt);
extern void oracleGetLob(oracleSession *session, void *locptr, oraType type, char **value, long *value_len, unsigned long trunc);
extern void oracleClientVersion(int *major, int *minor, int *update, int *patch, int *port_patch);
extern void oracleServerVersion(oracleSession *session, int *major, int *minor, int *update, int *patch, int *port_patch);
extern void *oracleGetGeometryType(oracleSession *session);
extern int oracleGetImportColumn(oracleSession *session, char *dblink, char *schema, char *limit_to, char **tabname, char **colname, oraType *type, int *charlen, int *typeprec, int *typescale, int *nullable, int *key, int skip_tables, int skip_views, int skip_matviews);
/*
* functions defined in oracle_fdw.c
*/
extern char *oracleGetShareFileName(const char *relativename);
extern void oracleRegisterCallback(void *arg);
extern void oracleUnregisterCallback(void *arg);
extern void *oracleAlloc(size_t size);
extern void *oracleRealloc(void *p, size_t size);
extern void oracleFree(void *p);
extern void oracleSetHandlers(void);
extern void oracleError_d(oraError sqlstate, const char *message, const char *detail);
extern void oracleError_sd(oraError sqlstate, const char *message, const char *arg, const char *detail);
extern void oracleError_ssdh(oraError sqlstate, const char *message, const char *arg1, const char* arg2, const char *detail, const char *hint);
extern void oracleError_ii(oraError sqlstate, const char *message, int arg1, int arg2);
extern void oracleError_i(oraError sqlstate, const char *message, int arg);
extern void oracleError(oraError sqlstate, const char *message);
extern void oracleDebug2(const char *message);
extern void initializePostGIS(void);
/*
* functions defined in oracle_gis.c
*/
extern ora_geometry *oracleEWKBToGeom(oracleSession *session, unsigned int ewkb_length, char *ewkb_data);
extern unsigned int oracleGetEWKBLen(oracleSession *session, ora_geometry *geom);
extern char *oracleFillEWKB(oracleSession *session, ora_geometry *geom, unsigned int size, char *dest);
extern void oracleGeometryFree(oracleSession *session, ora_geometry *geom);
extern void oracleGeometryAlloc(oracleSession *session, ora_geometry *geom);