PostgreSQL Source Code  git master
ecpglib_extern.h
Go to the documentation of this file.
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 
21 {
23 };
24 
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 
31 {
33 };
34 
35 #define ECPG_IS_ARRAY(X) ((X) == ECPG_ARRAY_ARRAY || (X) == ECPG_ARRAY_VECTOR)
36 
37 /* A generic varchar type. */
39 {
40  int len;
41  char arr[FLEXIBLE_ARRAY_MEMBER];
42 };
43 
44 /* A generic bytea type. */
46 {
47  int len;
48  char arr[FLEXIBLE_ARRAY_MEMBER];
49 };
50 
51 /*
52  * type information cache
53  */
54 
56 {
58  int oid;
60 };
61 
62 /* structure to store one statement */
63 struct statement
64 {
65  int lineno;
66  char *command;
67  char *name;
71  enum ECPG_statement_type statement_type;
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;
89 };
90 
91 /* structure to store declared statements */
93 {
94  char *name; /* declared name */
96  char *cursor_name;
98 };
99 
100 /* structure to store prepared statements for a connection */
102 {
103  char *name;
104  bool prepared;
105  struct statement *stmt;
107 };
108 
110 {
111  char *name; /* cursor name */
113 };
114 
115 /* structure to store connections */
117 {
118  char *name;
124  struct connection *next;
125 };
126 
127 /* structure to store descriptors */
129 {
130  char *name;
132  struct descriptor *next;
133  int count;
135 };
136 
138 {
139  int num;
140  char *data;
142  int length;
144  int scale;
145  int type;
146  bool is_binary;
147  int data_len;
149 };
150 
151 struct variable
152 {
154  void *value;
155  void *pointer;
157  long arrsize;
158  long offset;
159  enum ECPGttype ind_type;
160  void *ind_value;
161  void *ind_pointer;
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);
198 void ecpg_clear_auto_mem(void);
199 
200 struct descriptor *ecpg_find_desc(int line, const char *name);
201 
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 *);
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 *);
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 */
long ind_arrsize
bool ecpg_register_prepared_stmt(struct statement *)
Definition: prepare.c:60
bool ecpg_execute(struct statement *stmt)
Definition: execute.c:1598
bool ecpg_add_mem(void *ptr, int lineno)
Definition: memory.c:124
struct var_list * next
COMPAT_MODE
bool ecpg_store_input(const int, const bool, const struct variable *, char **, bool)
Definition: execute.c:510
void ecpg_release_declared_statement(const char *)
Definition: prepare.c:815
char arr[FLEXIBLE_ARRAY_MEMBER]
bool ecpg_build_params(struct statement *)
Definition: execute.c:1219
void print(const void *obj)
Definition: print.c:36
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
int ecpg_dynamic_type(Oid)
Definition: typename.c:74
ARRAY_TYPE
#define sqlca
Definition: sqlca.h:59
char * ecpg_realloc(void *, long, int)
Definition: memory.c:33
void ecpg_free(void *)
Definition: memory.c:13
struct connection * ecpg_get_connection(const char *)
Definition: connect.c:74
char * ecpg_strdup(const char *, int)
Definition: memory.c:47
void * pointer
unsigned ecpg_hex_encode(const char *src, unsigned len, char *dst)
Definition: data.c:191
void * pointer
void ecpg_do_epilogue(struct statement *)
Definition: execute.c:2213
struct cursor_statement * cursor_stmts
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition: descriptor.c:842
PGresult * results
const char * ecpg_get_con_name_by_cursor_name(const char *)
Definition: prepare.c:790
void ecpg_set_compat_sqlda(int, struct sqlda_compat **, const PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:256
struct variable * next
unsigned int Oid
Definition: postgres_ext.h:31
unsigned ecpg_hex_dec_len(unsigned srclen)
Definition: data.c:134
char * oldlocale
#define pg_attribute_printf(f, a)
Definition: c.h:132
ECPG_statement_type
Definition: ecpgtype.h:95
bool ecpg_process_output(struct statement *, bool)
Definition: execute.c:1667
struct ECPGtype_information_cache * next
int * paramformats
char * ecpg_auto_alloc(long, int)
Definition: memory.c:108
struct descriptor * next
PGconn * conn
Definition: streamutil.c:56
struct connection * connection
struct ECPGtype_information_cache * cache_head
bool ecpg_do(const int, const int, const int, const char *, const bool, const int, const char *, va_list)
Definition: execute.c:2245
Definition: sqlca.h:19
char * c
struct connection * next
char * ecpg_prepared(const char *, struct connection *)
Definition: prepare.c:390
void ecpg_free_params(struct statement *stmt, bool print)
Definition: execute.c:1112
struct statement * stmt
struct sqlda_struct * ecpg_build_native_sqlda(int, PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:413
void * value
PGresult * result
bool ecpg_internal_regression_mode
Definition: misc.c:30
#define locale_t
Definition: win32_port.h:372
void ecpg_log(const char *format,...) pg_attribute_printf(1
struct sqlda_compat * ecpg_build_compat_sqlda(int, PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:206
enum COMPAT_MODE compat
Definition: ecpg.c:25
void ecpg_update_declare_statement(const char *, const char *, const int)
Definition: prepare.c:747
char * ecpg_alloc(long, int)
Definition: memory.c:19
void bool ecpg_auto_prepare(int, const char *, const int, char **, const char *)
Definition: prepare.c:598
void ecpg_clear_auto_mem(void)
Definition: memory.c:158
bool ecpg_autostart_transaction(struct statement *stmt)
Definition: execute.c:1577
const char * ecpg_type_name(enum ECPGttype)
Definition: typename.c:18
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:99
bool ecpg_do_prologue(int, const int, const int, const char *, const bool, enum ECPG_statement_type, const char *, va_list, struct statement **)
Definition: execute.c:1941
struct prepared_statement * next
struct cursor_statement * next
struct declared_statement * next
struct prepared_statement * ecpg_find_prepared_statement(const char *, struct connection *, struct prepared_statement **)
Definition: prepare.c:261
void * ind_pointer
bool ecpg_get_data(const PGresult *, int, int, int, enum ECPGttype type, enum ECPGttype, char *, char *, long, long, long, enum ARRAY_TYPE, enum COMPAT_MODE, bool)
Definition: data.c:206
char * command
struct var_list * ivlist
Definition: misc.c:528
struct variable * inlist
bool ecpg_store_result(const PGresult *results, int act_field, const struct statement *stmt, struct variable *var)
Definition: execute.c:307
bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE)
Definition: error.c:290
PGconn * connection
char * ecpg_get_con_name_by_declared_name(const char *)
Definition: prepare.c:771
long ind_varcharsize
bool force_indicator
void ecpg_set_native_sqlda(int, struct sqlda_struct **, const PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:445
int sqlda_dynamic_type(Oid, enum COMPAT_MODE)
Definition: typename.c:108
char * name
struct descriptor_item * items
const char * name
Definition: encode.c:521
long ind_offset
char ** paramvalues
struct descriptor_item * next
bool questionmarks
void * ind_value
int * paramlengths
static char format
Definition: pg_basebackup.c:89
bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *conn)
Definition: prepare.c:370
bool ecpg_init(const struct connection *, const char *, const int)
Definition: misc.c:105
void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
Definition: error.c:226
long varcharsize
struct variable * outlist
unsigned ecpg_hex_enc_len(unsigned srclen)
Definition: data.c:128
struct prepared_statement * prep_stmts
ECPGttype
Definition: ecpgtype.h:41