Debian Codegraph @

src/interfaces/ecpg/ecpglib/ecpglib_extern.h

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