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 prepared statements for a connection */
93 {
94  char *name;
95  bool prepared;
96  struct statement *stmt;
98 };
99 
100 /* structure to store connections */
102 {
103  char *name;
108  struct connection *next;
109 };
110 
111 /* structure to store descriptors */
113 {
114  char *name;
116  struct descriptor *next;
117  int count;
119 };
120 
122 {
123  int num;
124  char *data;
126  int length;
128  int scale;
129  int type;
130  bool is_binary;
131  int data_len;
133 };
134 
135 struct variable
136 {
138  void *value;
139  void *pointer;
141  long arrsize;
142  long offset;
143  enum ECPGttype ind_type;
144  void *ind_value;
145  void *ind_pointer;
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);
182 void ecpg_clear_auto_mem(void);
183 
184 struct descriptor *ecpg_find_desc(int line, const char *name);
185 
187  struct connection *, struct prepared_statement **);
188 
189 bool ecpg_store_result(const PGresult *results, int act_field,
190  const struct statement *stmt, struct variable *var);
191 bool ecpg_store_input(const int, const bool, const struct variable *, char **, bool);
192 void ecpg_free_params(struct statement *stmt, bool print);
193 bool ecpg_do_prologue(int, const int, const int, const char *, const bool,
194  enum ECPG_statement_type, const char *, va_list,
195  struct statement **);
196 bool ecpg_build_params(struct statement *);
198 bool ecpg_execute(struct statement *stmt);
199 bool ecpg_process_output(struct statement *, bool);
200 void ecpg_do_epilogue(struct statement *);
201 bool ecpg_do(const int, const int, const int, const char *, const bool,
202  const int, const char *, va_list);
203 
204 bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE);
205 void ecpg_raise(int line, int code, const char *sqlstate, const char *str);
206 void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat);
207 char *ecpg_prepared(const char *, struct connection *);
208 bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *conn);
209 void ecpg_log(const char *format,...) pg_attribute_printf(1, 2);
210 bool ecpg_auto_prepare(int, const char *, const int, char **, const char *);
212 void ecpg_init_sqlca(struct sqlca_t *sqlca);
213 
214 struct sqlda_compat *ecpg_build_compat_sqlda(int, PGresult *, int, enum COMPAT_MODE);
215 void ecpg_set_compat_sqlda(int, struct sqlda_compat **, const PGresult *, int, enum COMPAT_MODE);
216 struct sqlda_struct *ecpg_build_native_sqlda(int, PGresult *, int, enum COMPAT_MODE);
217 void ecpg_set_native_sqlda(int, struct sqlda_struct **, const PGresult *, int, enum COMPAT_MODE);
218 unsigned ecpg_hex_dec_len(unsigned srclen);
219 unsigned ecpg_hex_enc_len(unsigned srclen);
220 unsigned ecpg_hex_encode(const char *src, unsigned len, char *dst);
221 
222 #ifdef ENABLE_NLS
223 extern char *ecpg_gettext(const char *msgid) pg_attribute_format_arg(1);
224 #else
225 #define ecpg_gettext(x) (x)
226 #endif
227 
228 /* SQLSTATE values generated or processed by ecpglib (intentionally
229  * not exported -- users should refer to the codes directly) */
230 
231 #define ECPG_SQLSTATE_NO_DATA "02000"
232 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS "07001"
233 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS "07002"
234 #define ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION "07006"
235 #define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX "07009"
236 #define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION "08001"
237 #define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST "08003"
238 #define ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN "08007"
239 #define ECPG_SQLSTATE_CARDINALITY_VIOLATION "21000"
240 #define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER "22002"
241 #define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION "25001"
242 #define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION "25P01"
243 #define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME "26000"
244 #define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME "33000"
245 #define ECPG_SQLSTATE_INVALID_CURSOR_NAME "34000"
246 #define ECPG_SQLSTATE_SYNTAX_ERROR "42601"
247 #define ECPG_SQLSTATE_DATATYPE_MISMATCH "42804"
248 #define ECPG_SQLSTATE_DUPLICATE_CURSOR "42P03"
249 
250 /* implementation-defined internal errors of ecpg */
251 #define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR "YE000"
252 #define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY "YE001"
253 
254 #endif /* _ECPG_ECPGLIB_EXTERN_H */
long ind_arrsize
bool ecpg_register_prepared_stmt(struct statement *)
Definition: prepare.c:59
bool ecpg_execute(struct statement *stmt)
Definition: execute.c:1595
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:509
char arr[FLEXIBLE_ARRAY_MEMBER]
bool ecpg_build_params(struct statement *)
Definition: execute.c:1216
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:73
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:2210
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition: descriptor.c:837
PGresult * results
void ecpg_set_compat_sqlda(int, struct sqlda_compat **, const PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:255
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:1664
#define ecpg_gettext(x)
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:54
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:2242
Definition: sqlca.h:19
char * c
struct connection * next
char * ecpg_prepared(const char *, struct connection *)
Definition: prepare.c:357
void ecpg_free_params(struct statement *stmt, bool print)
Definition: execute.c:1109
struct statement * stmt
struct sqlda_struct * ecpg_build_native_sqlda(int, PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:412
void * value
PGresult * result
bool ecpg_internal_regression_mode
Definition: misc.c:29
#define locale_t
Definition: win32_port.h:363
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:205
#define pg_attribute_format_arg(a)
Definition: c.h:131
enum COMPAT_MODE compat
Definition: ecpg.c:25
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:553
void ecpg_clear_auto_mem(void)
Definition: memory.c:158
bool ecpg_autostart_transaction(struct statement *stmt)
Definition: execute.c:1574
const char * ecpg_type_name(enum ECPGttype)
Definition: typename.c:17
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:98
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:1938
struct prepared_statement * next
struct prepared_statement * ecpg_find_prepared_statement(const char *, struct connection *, struct prepared_statement **)
Definition: prepare.c:239
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:523
struct variable * inlist
bool ecpg_store_result(const PGresult *results, int act_field, const struct statement *stmt, struct variable *var)
Definition: execute.c:306
bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE)
Definition: error.c:283
PGconn * connection
long ind_varcharsize
bool force_indicator
void ecpg_set_native_sqlda(int, struct sqlda_struct **, const PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:444
int sqlda_dynamic_type(Oid, enum COMPAT_MODE)
Definition: typename.c:107
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:85
bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *conn)
Definition: prepare.c:337
bool ecpg_init(const struct connection *, const char *, const int)
Definition: misc.c:104
void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
Definition: error.c:219
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