forked from laurenz/oracle_fdw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oracle_fdw.h
150 lines (136 loc) · 5.56 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
/*-------------------------------------------------------------------------
*
* 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 <sys/types.h>
/* oracle_fdw version */
#define ORACLE_FDW_VERSION "1.0.0"
/* opaque type encapsulating the real Oracle connection */
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_INTERVALY2M,
ORA_TYPE_INTERVALD2S,
ORA_TYPE_BLOB,
ORA_TYPE_CLOB,
ORA_TYPE_BFILE,
ORA_TYPE_LONG,
ORA_TYPE_LONGRAW,
ORA_TYPE_OTHER
} oraType;
/* PostgreSQL has no constant definition for the OID of type uuid */
#ifndef UUIDOID
#define UUIDOID 2950
#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 pkey; /* nonzero for primary keys, later set to the resjunk attribute number */
char *val; /* buffer for Oracle to return results in (LOB locator for LOBs) */
long val_size; /* allocated size in val */
unsigned short val_len; /* actual length of val */
unsigned int val_len4; /* actual length of val - for bind callbacks */
short val_null; /* indicator for NULL value */
};
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_TIMESTAMP,
BIND_BLOB,
BIND_CLOB,
BIND_LONG,
BIND_LONGRAW,
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 for output parameters */
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
} oraError;
/*
* functions defined in oracle_utils.c
*/
extern oracleSession *oracleGetSession(const char *connectstring, char *user, char *password, const char *nls_lang, const char *tablename, int curlevel);
extern void oracleCloseStatement(oracleSession *session);
extern void oracleCloseConnections(void);
extern void oracleShutdown(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 *schema, char *table, char *pgname, long max_long);
extern void oracleEstimate(oracleSession *session, const char *query, double seq_page_cost, int block_size, double *startup_cost, double *total_cost, double *rows, int *width);
extern void oracleExplain(oracleSession *session, const char *query, int *nrows, char ***plan);
extern void oraclePrepareQuery(oracleSession *session, const char *query, const struct oraTable *oraTable);
extern int oracleExecuteQuery(oracleSession *session, const struct oraTable *oraTable, struct paramDesc *paramList);
extern int oracleFetchNext(oracleSession *session);
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);
/*
* functions defined in oracle_fdw.c
*/
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 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_i(oraError sqlstate, const char *message, int arg);
extern void oracleError(oraError sqlstate, const char *message);
extern void oracleDebug2(const char *message);