]> granicus.if.org Git - postgresql/blob - src/interfaces/ecpg/ecpglib/ecpglib_extern.h
Fix inconsistencies in the code
[postgresql] / src / interfaces / ecpg / ecpglib / ecpglib_extern.h
1 /* src/interfaces/ecpg/ecpglib/ecpglib_extern.h */
2
3 #ifndef _ECPG_ECPGLIB_EXTERN_H
4 #define _ECPG_ECPGLIB_EXTERN_H
5
6 #include "libpq-fe.h"
7 #include "sqlca.h"
8 #include "sqlda-native.h"
9 #include "sqlda-compat.h"
10 #include "ecpg_config.h"
11 #include "ecpgtype.h"
12
13 #ifndef CHAR_BIT
14 #include <limits.h>
15 #endif
16 #ifdef LOCALE_T_IN_XLOCALE
17 #include <xlocale.h>
18 #endif
19
20 enum COMPAT_MODE
21 {
22         ECPG_COMPAT_PGSQL = 0, ECPG_COMPAT_INFORMIX, ECPG_COMPAT_INFORMIX_SE, ECPG_COMPAT_ORACLE
23 };
24
25 extern bool ecpg_internal_regression_mode;
26
27 #define INFORMIX_MODE(X) ((X) == ECPG_COMPAT_INFORMIX || (X) == ECPG_COMPAT_INFORMIX_SE)
28 #define ORACLE_MODE(X) ((X) == ECPG_COMPAT_ORACLE)
29
30 enum ARRAY_TYPE
31 {
32         ECPG_ARRAY_ERROR, ECPG_ARRAY_NOT_SET, ECPG_ARRAY_ARRAY, ECPG_ARRAY_VECTOR, ECPG_ARRAY_NONE
33 };
34
35 #define ECPG_IS_ARRAY(X) ((X) == ECPG_ARRAY_ARRAY || (X) == ECPG_ARRAY_VECTOR)
36
37 /* A generic varchar type. */
38 struct ECPGgeneric_varchar
39 {
40         int                     len;
41         char            arr[FLEXIBLE_ARRAY_MEMBER];
42 };
43
44 /* A generic bytea type. */
45 struct ECPGgeneric_bytea
46 {
47         int                     len;
48         char            arr[FLEXIBLE_ARRAY_MEMBER];
49 };
50
51 /*
52  * type information cache
53  */
54
55 struct ECPGtype_information_cache
56 {
57         struct ECPGtype_information_cache *next;
58         int                     oid;
59         enum ARRAY_TYPE isarray;
60 };
61
62 /* structure to store one statement */
63 struct statement
64 {
65         int                     lineno;
66         char       *command;
67         char       *name;
68         struct connection *connection;
69         enum COMPAT_MODE compat;
70         bool            force_indicator;
71         enum ECPG_statement_type statement_type;
72         bool            questionmarks;
73         struct variable *inlist;
74         struct variable *outlist;
75 #ifdef HAVE_USELOCALE
76         locale_t        clocale;
77         locale_t        oldlocale;
78 #else
79         char       *oldlocale;
80 #ifdef HAVE__CONFIGTHREADLOCALE
81         int                     oldthreadlocale;
82 #endif
83 #endif
84         int                     nparams;
85         char      **paramvalues;
86         int                *paramlengths;
87         int                *paramformats;
88         PGresult   *results;
89 };
90
91 /* structure to store declared statements */
92 struct declared_statement
93 {
94         char       *name;                       /* declared name */
95         char       *connection_name;
96         char       *cursor_name;
97         struct declared_statement *next;
98 };
99
100 /* structure to store prepared statements for a connection */
101 struct prepared_statement
102 {
103         char       *name;
104         bool            prepared;
105         struct statement *stmt;
106         struct prepared_statement *next;
107 };
108
109 struct cursor_statement
110 {
111         char       *name;                       /* cursor name */
112         struct cursor_statement *next;
113 };
114
115 /* structure to store connections */
116 struct connection
117 {
118         char       *name;
119         PGconn     *connection;
120         bool            autocommit;
121         struct ECPGtype_information_cache *cache_head;
122         struct prepared_statement *prep_stmts;
123         struct cursor_statement *cursor_stmts;
124         struct connection *next;
125 };
126
127 /* structure to store descriptors */
128 struct descriptor
129 {
130         char       *name;
131         PGresult   *result;
132         struct descriptor *next;
133         int                     count;
134         struct descriptor_item *items;
135 };
136
137 struct descriptor_item
138 {
139         int                     num;
140         char       *data;
141         int                     indicator;
142         int                     length;
143         int                     precision;
144         int                     scale;
145         int                     type;
146         bool            is_binary;
147         int                     data_len;
148         struct descriptor_item *next;
149 };
150
151 struct variable
152 {
153         enum ECPGttype type;
154         void       *value;
155         void       *pointer;
156         long            varcharsize;
157         long            arrsize;
158         long            offset;
159         enum ECPGttype ind_type;
160         void       *ind_value;
161         void       *ind_pointer;
162         long            ind_varcharsize;
163         long            ind_arrsize;
164         long            ind_offset;
165         struct variable *next;
166 };
167
168 struct var_list
169 {
170         int                     number;
171         void       *pointer;
172         struct var_list *next;
173 };
174
175 extern struct var_list *ivlist;
176
177 /* Here are some methods used by the lib. */
178
179 bool            ecpg_add_mem(void *ptr, int lineno);
180
181 bool            ecpg_get_data(const PGresult *, int, int, int, enum ECPGttype type,
182                                                   enum ECPGttype, char *, char *, long, long, long,
183                                                   enum ARRAY_TYPE, enum COMPAT_MODE, bool);
184
185 #ifdef ENABLE_THREAD_SAFETY
186 void            ecpg_pthreads_init(void);
187 #endif
188 struct connection *ecpg_get_connection(const char *);
189 char       *ecpg_alloc(long, int);
190 char       *ecpg_auto_alloc(long, int);
191 char       *ecpg_realloc(void *, long, int);
192 void            ecpg_free(void *);
193 bool            ecpg_init(const struct connection *, const char *, const int);
194 char       *ecpg_strdup(const char *, int);
195 const char *ecpg_type_name(enum ECPGttype);
196 int                     ecpg_dynamic_type(Oid);
197 int                     sqlda_dynamic_type(Oid, enum COMPAT_MODE);
198 void            ecpg_clear_auto_mem(void);
199
200 struct descriptor *ecpg_find_desc(int line, const char *name);
201
202 struct prepared_statement *ecpg_find_prepared_statement(const char *,
203                                                                                                                 struct connection *, struct prepared_statement **);
204
205 void            ecpg_update_declare_statement(const char *, const char *, const int);
206 char       *ecpg_get_con_name_by_declared_name(const char *);
207 const char *ecpg_get_con_name_by_cursor_name(const char *);
208 void            ecpg_release_declared_statement(const char *);
209
210 bool            ecpg_store_result(const PGresult *results, int act_field,
211                                                           const struct statement *stmt, struct variable *var);
212 bool            ecpg_store_input(const int, const bool, const struct variable *, char **, bool);
213 void            ecpg_free_params(struct statement *stmt, bool print);
214 bool            ecpg_do_prologue(int, const int, const int, const char *, const bool,
215                                                          enum ECPG_statement_type, const char *, va_list,
216                                                          struct statement **);
217 bool            ecpg_build_params(struct statement *);
218 bool            ecpg_autostart_transaction(struct statement *stmt);
219 bool            ecpg_execute(struct statement *stmt);
220 bool            ecpg_process_output(struct statement *, bool);
221 void            ecpg_do_epilogue(struct statement *);
222 bool            ecpg_do(const int, const int, const int, const char *, const bool,
223                                         const int, const char *, va_list);
224
225 bool            ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE);
226 void            ecpg_raise(int line, int code, const char *sqlstate, const char *str);
227 void            ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat);
228 char       *ecpg_prepared(const char *, struct connection *);
229 bool            ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *conn);
230 void            ecpg_log(const char *format,...) pg_attribute_printf(1, 2);
231 bool            ecpg_auto_prepare(int, const char *, const int, char **, const char *);
232 bool            ecpg_register_prepared_stmt(struct statement *);
233 void            ecpg_init_sqlca(struct sqlca_t *sqlca);
234
235 struct sqlda_compat *ecpg_build_compat_sqlda(int, PGresult *, int, enum COMPAT_MODE);
236 void            ecpg_set_compat_sqlda(int, struct sqlda_compat **, const PGresult *, int, enum COMPAT_MODE);
237 struct sqlda_struct *ecpg_build_native_sqlda(int, PGresult *, int, enum COMPAT_MODE);
238 void            ecpg_set_native_sqlda(int, struct sqlda_struct **, const PGresult *, int, enum COMPAT_MODE);
239 unsigned        ecpg_hex_dec_len(unsigned srclen);
240 unsigned        ecpg_hex_enc_len(unsigned srclen);
241 unsigned        ecpg_hex_encode(const char *src, unsigned len, char *dst);
242
243 /* SQLSTATE values generated or processed by ecpglib (intentionally
244  * not exported -- users should refer to the codes directly) */
245
246 #define ECPG_SQLSTATE_NO_DATA                           "02000"
247 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS    "07001"
248 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS               "07002"
249 #define ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION  "07006"
250 #define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX          "07009"
251 #define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION       "08001"
252 #define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST         "08003"
253 #define ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN    "08007"
254 #define ECPG_SQLSTATE_CARDINALITY_VIOLATION "21000"
255 #define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER "22002"
256 #define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION            "25001"
257 #define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION         "25P01"
258 #define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME        "26000"
259 #define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME       "33000"
260 #define ECPG_SQLSTATE_INVALID_CURSOR_NAME       "34000"
261 #define ECPG_SQLSTATE_SYNTAX_ERROR                      "42601"
262 #define ECPG_SQLSTATE_DATATYPE_MISMATCH         "42804"
263 #define ECPG_SQLSTATE_DUPLICATE_CURSOR          "42P03"
264
265 /* implementation-defined internal errors of ecpg */
266 #define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR       "YE000"
267 #define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY        "YE001"
268
269 #endif                                                  /* _ECPG_ECPGLIB_EXTERN_H */