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 "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 #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;
42 };
43 
44 /* A generic bytea type. */
46 {
47  int len;
49 };
50 
51 /*
52  * type information cache
53  */
54 
56 {
58  int oid;
59  enum ARRAY_TYPE isarray;
60 };
61 
62 #ifdef HAVE_USELOCALE
63 extern locale_t ecpg_clocale; /* LC_NUMERIC=C */
64 #endif
65 
66 /* structure to store one statement */
67 struct statement
68 {
69  int lineno;
70  char *command;
71  char *name;
73  enum COMPAT_MODE compat;
77  struct variable *inlist;
78  struct variable *outlist;
79 #ifdef HAVE_USELOCALE
81 #else
82  char *oldlocale;
83 #ifdef HAVE__CONFIGTHREADLOCALE
84  int oldthreadlocale;
85 #endif
86 #endif
87  int nparams;
88  char **paramvalues;
92 };
93 
94 /* structure to store prepared statements for a connection */
96 {
97  char *name;
98  bool prepared;
99  struct statement *stmt;
101 };
102 
103 /* structure to store connections */
105 {
106  char *name;
111  struct connection *next;
112 };
113 
114 /* structure to store descriptors */
116 {
117  char *name;
119  struct descriptor *next;
120  int count;
122 };
123 
125 {
126  int num;
127  char *data;
129  int length;
131  int scale;
132  int type;
133  bool is_binary;
134  int data_len;
136 };
137 
138 struct variable
139 {
140  enum ECPGttype type;
141  void *value;
142  void *pointer;
144  long arrsize;
145  long offset;
146  enum ECPGttype ind_type;
147  void *ind_value;
148  void *ind_pointer;
152  struct variable *next;
153 };
154 
155 struct var_list
156 {
157  int number;
158  void *pointer;
159  struct var_list *next;
160 };
161 
162 extern struct var_list *ivlist;
163 
164 /* Here are some methods used by the lib. */
165 
166 bool ecpg_add_mem(void *ptr, int lineno);
167 
168 bool ecpg_get_data(const PGresult *, int, int, int, enum ECPGttype type,
169  enum ECPGttype, char *, char *, long, long, long,
170  enum ARRAY_TYPE, enum COMPAT_MODE, bool);
171 
172 void ecpg_pthreads_init(void);
173 struct connection *ecpg_get_connection(const char *connection_name);
174 char *ecpg_alloc(long size, int lineno);
175 char *ecpg_auto_alloc(long size, int lineno);
176 char *ecpg_realloc(void *ptr, long size, int lineno);
177 void ecpg_free(void *ptr);
178 bool ecpg_init(const struct connection *con,
179  const char *connection_name,
180  const int lineno);
181 char *ecpg_strdup(const char *string, int lineno);
182 const char *ecpg_type_name(enum ECPGttype typ);
185 void ecpg_clear_auto_mem(void);
186 
187 struct descriptor *ecpg_find_desc(int line, const char *name);
188 
190  struct connection *con,
191  struct prepared_statement **prev_);
192 
193 bool ecpg_store_result(const PGresult *results, int act_field,
194  const struct statement *stmt, struct variable *var);
195 bool ecpg_store_input(const int lineno, const bool force_indicator,
196  const struct variable *var,
197  char **tobeinserted_p, bool quote);
198 void ecpg_free_params(struct statement *stmt, bool print);
199 bool ecpg_do_prologue(int lineno, const int compat,
200  const int force_indicator, const char *connection_name,
201  const bool questionmarks, enum ECPG_statement_type statement_type,
202  const char *query, va_list args,
203  struct statement **stmt_out);
204 bool ecpg_build_params(struct statement *stmt);
206 bool ecpg_execute(struct statement *stmt);
207 bool ecpg_process_output(struct statement *stmt, bool clear_result);
208 void ecpg_do_epilogue(struct statement *stmt);
209 bool ecpg_do(const int lineno, const int compat,
210  const int force_indicator, const char *connection_name,
211  const bool questionmarks, const int st, const char *query,
212  va_list args);
213 
214 bool ecpg_check_PQresult(PGresult *results, int lineno,
216 void ecpg_raise(int line, int code, const char *sqlstate, const char *str);
217 void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat);
218 char *ecpg_prepared(const char *name, struct connection *con);
219 bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con);
220 void ecpg_log(const char *format,...) pg_attribute_printf(1, 2);
221 bool ecpg_auto_prepare(int lineno, const char *connection_name,
222  const int compat, char **name, const char *query);
224 void ecpg_init_sqlca(struct sqlca_t *sqlca);
225 
226 struct sqlda_compat *ecpg_build_compat_sqlda(int line, PGresult *res, int row,
227  enum COMPAT_MODE compat);
228 void ecpg_set_compat_sqlda(int lineno, struct sqlda_compat **_sqlda,
229  const PGresult *res, int row,
230  enum COMPAT_MODE compat);
231 struct sqlda_struct *ecpg_build_native_sqlda(int line, PGresult *res, int row,
232  enum COMPAT_MODE compat);
233 void ecpg_set_native_sqlda(int lineno, struct sqlda_struct **_sqlda,
234  const PGresult *res, int row, enum COMPAT_MODE compat);
235 unsigned ecpg_hex_dec_len(unsigned srclen);
236 unsigned ecpg_hex_enc_len(unsigned srclen);
237 unsigned ecpg_hex_encode(const char *src, unsigned len, char *dst);
238 
239 #ifdef ENABLE_NLS
240 extern char *ecpg_gettext(const char *msgid) pg_attribute_format_arg(1);
241 #else
242 #define ecpg_gettext(x) (x)
243 #endif
244 
245 /* SQLSTATE values generated or processed by ecpglib (intentionally
246  * not exported -- users should refer to the codes directly) */
247 
248 #define ECPG_SQLSTATE_NO_DATA "02000"
249 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS "07001"
250 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS "07002"
251 #define ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION "07006"
252 #define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX "07009"
253 #define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION "08001"
254 #define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST "08003"
255 #define ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN "08007"
256 #define ECPG_SQLSTATE_CARDINALITY_VIOLATION "21000"
257 #define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER "22002"
258 #define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION "25001"
259 #define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION "25P01"
260 #define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME "26000"
261 #define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME "33000"
262 #define ECPG_SQLSTATE_INVALID_CURSOR_NAME "34000"
263 #define ECPG_SQLSTATE_SYNTAX_ERROR "42601"
264 #define ECPG_SQLSTATE_DATATYPE_MISMATCH "42804"
265 #define ECPG_SQLSTATE_DUPLICATE_CURSOR "42P03"
266 
267 /* implementation-defined internal errors of ecpg */
268 #define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR "YE000"
269 #define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY "YE001"
270 
271 #endif /* _ECPG_ECPGLIB_EXTERN_H */
void print(const void *obj)
Definition: print.c:36
#define pg_attribute_format_arg(a)
Definition: c.h:190
#define pg_attribute_printf(f, a)
Definition: c.h:191
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:398
enum COMPAT_MODE compat
Definition: ecpg.c:25
bool force_indicator
Definition: ecpg.c:18
bool questionmarks
Definition: ecpg.c:19
unsigned ecpg_hex_enc_len(unsigned srclen)
Definition: data.c:128
bool ecpg_build_params(struct statement *stmt)
Definition: execute.c:1213
bool ecpg_store_result(const PGresult *results, int act_field, const struct statement *stmt, struct variable *var)
Definition: execute.c:303
bool ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat)
Definition: error.c:281
#define ecpg_gettext(x)
bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con)
Definition: prepare.c:337
unsigned ecpg_hex_dec_len(unsigned srclen)
Definition: data.c:134
struct sqlda_struct * ecpg_build_native_sqlda(int line, PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:412
void ecpg_pthreads_init(void)
Definition: connect.c:30
char * ecpg_auto_alloc(long size, int lineno)
Definition: memory.c:101
COMPAT_MODE
@ ECPG_COMPAT_PGSQL
@ ECPG_COMPAT_ORACLE
@ ECPG_COMPAT_INFORMIX
@ ECPG_COMPAT_INFORMIX_SE
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
bool ecpg_execute(struct statement *stmt)
Definition: execute.c:1602
void ecpg_free_params(struct statement *stmt, bool print)
Definition: execute.c:1106
bool ecpg_add_mem(void *ptr, int lineno)
Definition: memory.c:117
const char * ecpg_type_name(enum ECPGttype typ)
Definition: typename.c:17
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
Definition: prepare.c:239
bool ecpg_register_prepared_stmt(struct statement *stmt)
Definition: prepare.c:59
bool ecpg_store_input(const int lineno, const bool force_indicator, const struct variable *var, char **tobeinserted_p, bool quote)
Definition: execute.c:506
void ecpg_log(const char *format,...) pg_attribute_printf(1
unsigned ecpg_hex_encode(const char *src, unsigned len, char *dst)
Definition: data.c:191
void bool ecpg_auto_prepare(int lineno, const char *connection_name, const int compat, char **name, const char *query)
Definition: prepare.c:553
void ecpg_clear_auto_mem(void)
Definition: memory.c:151
bool ecpg_init(const struct connection *con, const char *connection_name, const int lineno)
Definition: misc.c:73
void ecpg_do_epilogue(struct statement *stmt)
Definition: execute.c:2211
char * ecpg_alloc(long size, int lineno)
Definition: memory.c:19
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:71
void ecpg_set_compat_sqlda(int lineno, struct sqlda_compat **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:255
bool ecpg_do(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query, va_list args)
Definition: execute.c:2243
char * ecpg_strdup(const char *string, int lineno)
Definition: memory.c:47
bool ecpg_do_prologue(int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, enum ECPG_statement_type statement_type, const char *query, va_list args, struct statement **stmt_out)
Definition: execute.c:1944
bool ecpg_process_output(struct statement *stmt, bool clear_result)
Definition: execute.c:1671
int sqlda_dynamic_type(Oid type, enum COMPAT_MODE compat)
Definition: typename.c:107
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:67
bool ecpg_autostart_transaction(struct statement *stmt)
Definition: execute.c:1581
char * ecpg_prepared(const char *name, struct connection *con)
Definition: prepare.c:357
struct var_list * ivlist
Definition: misc.c:516
void ecpg_set_native_sqlda(int lineno, struct sqlda_struct **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:444
int ecpg_dynamic_type(Oid type)
Definition: typename.c:73
char * ecpg_realloc(void *ptr, long size, int lineno)
Definition: memory.c:33
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
struct sqlda_compat * ecpg_build_compat_sqlda(int line, PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:205
bool ecpg_internal_regression_mode
Definition: misc.c:29
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition: descriptor.c:832
void ecpg_free(void *ptr)
Definition: memory.c:13
ARRAY_TYPE
@ ECPG_ARRAY_NOT_SET
@ ECPG_ARRAY_ARRAY
@ ECPG_ARRAY_VECTOR
@ ECPG_ARRAY_NONE
@ ECPG_ARRAY_ERROR
void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
Definition: error.c:219
ECPG_statement_type
Definition: ecpgtype.h:96
ECPGttype
Definition: ecpgtype.h:42
const char * str
#define stmt
Definition: indent_codes.h:59
static char format
const void size_t len
unsigned int Oid
Definition: postgres_ext.h:31
char * c
static pg_noinline void Size size
Definition: slab.c:607
#define sqlca
Definition: sqlca.h:59
PGconn * conn
Definition: streamutil.c:55
char arr[FLEXIBLE_ARRAY_MEMBER]
char arr[FLEXIBLE_ARRAY_MEMBER]
struct ECPGtype_information_cache * next
PGconn * connection
struct ECPGtype_information_cache * cache_head
struct connection * next
struct prepared_statement * prep_stmts
struct descriptor_item * next
struct descriptor * next
struct descriptor_item * items
PGresult * result
struct statement * stmt
struct prepared_statement * next
Definition: sqlca.h:20
struct variable * inlist
bool questionmarks
char * command
char ** paramvalues
char * oldlocale
struct variable * outlist
struct connection * connection
bool force_indicator
int * paramformats
enum COMPAT_MODE compat
enum ECPG_statement_type statement_type
char * name
PGresult * results
int * paramlengths
struct var_list * next
void * pointer
void * value
long ind_arrsize
long ind_offset
void * ind_value
long ind_varcharsize
long varcharsize
struct variable * next
enum ECPGttype type
enum ECPGttype ind_type
void * ind_pointer
void * pointer
const char * type
const char * name
#define locale_t
Definition: win32_port.h:424