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 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 | #ifdef ENABLE_THREAD_SAFETY |
170 | void ecpg_pthreads_init(void); |
171 | #endif |
172 | struct connection *ecpg_get_connection(const char *); |
173 | char *ecpg_alloc(long, int); |
174 | char *ecpg_auto_alloc(long, int); |
175 | char *ecpg_realloc(void *, long, int); |
176 | void ecpg_free(void *); |
177 | bool ecpg_init(const struct connection *, const char *, const int); |
178 | char *ecpg_strdup(const char *, int); |
179 | const char *ecpg_type_name(enum ECPGttype); |
180 | int ecpg_dynamic_type(Oid); |
181 | int sqlda_dynamic_type(Oid, enum COMPAT_MODE); |
182 | void ecpg_free_auto_mem(void); |
183 | void ecpg_clear_auto_mem(void); |
184 | |
185 | struct descriptor *ecpggetdescp(int, char *); |
186 | |
187 | struct descriptor *ecpg_find_desc(int line, const char *name); |
188 | |
189 | struct prepared_statement *ecpg_find_prepared_statement(const char *, |
190 | struct connection *, struct prepared_statement **); |
191 | |
192 | bool ecpg_store_result(const PGresult *results, int act_field, |
193 | const struct statement *stmt, struct variable *var); |
194 | bool ecpg_store_input(const int, const bool, const struct variable *, char **, bool); |
195 | void ecpg_free_params(struct statement *stmt, bool print); |
196 | bool ecpg_do_prologue(int, const int, const int, const char *, const bool, |
197 | enum ECPG_statement_type, const char *, va_list, |
198 | struct statement **); |
199 | bool ecpg_build_params(struct statement *); |
200 | bool ecpg_autostart_transaction(struct statement *stmt); |
201 | bool ecpg_execute(struct statement *stmt); |
202 | bool ecpg_process_output(struct statement *, bool); |
203 | void ecpg_do_epilogue(struct statement *); |
204 | bool ecpg_do(const int, const int, const int, const char *, const bool, |
205 | const int, const char *, va_list); |
206 | |
207 | bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE); |
208 | void ecpg_raise(int line, int code, const char *sqlstate, const char *str); |
209 | void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat); |
210 | char *ecpg_prepared(const char *, struct connection *); |
211 | bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *conn); |
212 | void ecpg_log(const char *format,...) pg_attribute_printf(1, 2); |
213 | bool ecpg_auto_prepare(int, const char *, const int, char **, const char *); |
214 | bool ecpg_register_prepared_stmt(struct statement *); |
215 | void ecpg_init_sqlca(struct sqlca_t *sqlca); |
216 | |
217 | struct sqlda_compat *ecpg_build_compat_sqlda(int, PGresult *, int, enum COMPAT_MODE); |
218 | void ecpg_set_compat_sqlda(int, struct sqlda_compat **, const PGresult *, int, enum COMPAT_MODE); |
219 | struct sqlda_struct *ecpg_build_native_sqlda(int, PGresult *, int, enum COMPAT_MODE); |
220 | void ecpg_set_native_sqlda(int, struct sqlda_struct **, const PGresult *, int, enum COMPAT_MODE); |
221 | unsigned ecpg_hex_dec_len(unsigned srclen); |
222 | unsigned ecpg_hex_enc_len(unsigned srclen); |
223 | unsigned ecpg_hex_encode(const char *src, unsigned len, char *dst); |
224 | |
225 | /* SQLSTATE values generated or processed by ecpglib (intentionally |
226 | * not exported -- users should refer to the codes directly) */ |
227 | |
228 | #define ECPG_SQLSTATE_NO_DATA "02000" |
229 | #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS "07001" |
230 | #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS "07002" |
231 | #define ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION "07006" |
232 | #define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX "07009" |
233 | #define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION "08001" |
234 | #define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST "08003" |
235 | #define ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN "08007" |
236 | #define ECPG_SQLSTATE_CARDINALITY_VIOLATION "21000" |
237 | #define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER "22002" |
238 | #define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION "25001" |
239 | #define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION "25P01" |
240 | #define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME "26000" |
241 | #define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME "33000" |
242 | #define ECPG_SQLSTATE_INVALID_CURSOR_NAME "34000" |
243 | #define ECPG_SQLSTATE_SYNTAX_ERROR "42601" |
244 | #define ECPG_SQLSTATE_DATATYPE_MISMATCH "42804" |
245 | #define ECPG_SQLSTATE_DUPLICATE_CURSOR "42P03" |
246 | |
247 | /* implementation-defined internal errors of ecpg */ |
248 | #define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR "YE000" |
249 | #define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY "YE001" |
250 | |
251 | #endif /* _ECPG_ECPGLIB_EXTERN_H */ |
252 | |