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 #ifdef ENABLE_THREAD_SAFETY
173 void ecpg_pthreads_init(void);
174 #endif
175 struct connection *ecpg_get_connection(const char *connection_name);
176 char *ecpg_alloc(long size, int lineno);
177 char *ecpg_auto_alloc(long size, int lineno);
178 char *ecpg_realloc(void *ptr, long size, int lineno);
179 void ecpg_free(void *ptr);
180 bool ecpg_init(const struct connection *con,
181  const char *connection_name,
182  const int lineno);
183 char *ecpg_strdup(const char *string, int lineno);
184 const char *ecpg_type_name(enum ECPGttype typ);
187 void ecpg_clear_auto_mem(void);
188 
189 struct descriptor *ecpg_find_desc(int line, const char *name);
190 
192  struct connection *con,
193  struct prepared_statement **prev_);
194 
195 bool ecpg_store_result(const PGresult *results, int act_field,
196  const struct statement *stmt, struct variable *var);
197 bool ecpg_store_input(const int lineno, const bool force_indicator,
198  const struct variable *var,
199  char **tobeinserted_p, bool quote);
200 void ecpg_free_params(struct statement *stmt, bool print);
201 bool ecpg_do_prologue(int lineno, const int compat,
202  const int force_indicator, const char *connection_name,
203  const bool questionmarks, enum ECPG_statement_type statement_type,
204  const char *query, va_list args,
205  struct statement **stmt_out);
206 bool ecpg_build_params(struct statement *stmt);
208 bool ecpg_execute(struct statement *stmt);
209 bool ecpg_process_output(struct statement *stmt, bool clear_result);
210 void ecpg_do_epilogue(struct statement *stmt);
211 bool ecpg_do(const int lineno, const int compat,
212  const int force_indicator, const char *connection_name,
213  const bool questionmarks, const int st, const char *query,
214  va_list args);
215 
216 bool ecpg_check_PQresult(PGresult *results, int lineno,
218 void ecpg_raise(int line, int code, const char *sqlstate, const char *str);
219 void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat);
220 char *ecpg_prepared(const char *name, struct connection *con);
221 bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con);
222 void ecpg_log(const char *format,...) pg_attribute_printf(1, 2);
223 bool ecpg_auto_prepare(int lineno, const char *connection_name,
224  const int compat, char **name, const char *query);
226 void ecpg_init_sqlca(struct sqlca_t *sqlca);
227 
228 struct sqlda_compat *ecpg_build_compat_sqlda(int line, PGresult *res, int row,
229  enum COMPAT_MODE compat);
230 void ecpg_set_compat_sqlda(int lineno, struct sqlda_compat **_sqlda,
231  const PGresult *res, int row,
232  enum COMPAT_MODE compat);
233 struct sqlda_struct *ecpg_build_native_sqlda(int line, PGresult *res, int row,
234  enum COMPAT_MODE compat);
235 void ecpg_set_native_sqlda(int lineno, struct sqlda_struct **_sqlda,
236  const PGresult *res, int row, enum COMPAT_MODE compat);
237 unsigned ecpg_hex_dec_len(unsigned srclen);
238 unsigned ecpg_hex_enc_len(unsigned srclen);
239 unsigned ecpg_hex_encode(const char *src, unsigned len, char *dst);
240 
241 #ifdef ENABLE_NLS
242 extern char *ecpg_gettext(const char *msgid) pg_attribute_format_arg(1);
243 #else
244 #define ecpg_gettext(x) (x)
245 #endif
246 
247 /* SQLSTATE values generated or processed by ecpglib (intentionally
248  * not exported -- users should refer to the codes directly) */
249 
250 #define ECPG_SQLSTATE_NO_DATA "02000"
251 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS "07001"
252 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS "07002"
253 #define ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION "07006"
254 #define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX "07009"
255 #define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION "08001"
256 #define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST "08003"
257 #define ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN "08007"
258 #define ECPG_SQLSTATE_CARDINALITY_VIOLATION "21000"
259 #define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER "22002"
260 #define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION "25001"
261 #define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION "25P01"
262 #define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME "26000"
263 #define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME "33000"
264 #define ECPG_SQLSTATE_INVALID_CURSOR_NAME "34000"
265 #define ECPG_SQLSTATE_SYNTAX_ERROR "42601"
266 #define ECPG_SQLSTATE_DATATYPE_MISMATCH "42804"
267 #define ECPG_SQLSTATE_DUPLICATE_CURSOR "42P03"
268 
269 /* implementation-defined internal errors of ecpg */
270 #define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR "YE000"
271 #define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY "YE001"
272 
273 #endif /* _ECPG_ECPGLIB_EXTERN_H */
void print(const void *obj)
Definition: print.c:36
#define pg_attribute_format_arg(a)
Definition: c.h:174
#define pg_attribute_printf(f, a)
Definition: c.h:175
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:362
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
char * ecpg_auto_alloc(long size, int lineno)
Definition: memory.c:108
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:124
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:158
bool ecpg_init(const struct connection *con, const char *connection_name, const int lineno)
Definition: misc.c:104
void ecpg_do_epilogue(struct statement *stmt)
Definition: execute.c:2213
char * ecpg_alloc(long size, int lineno)
Definition: memory.c:19
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:79
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:2245
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:98
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:529
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:842
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 * name
Definition: encode.c:561
static char format
const void size_t len
unsigned int Oid
Definition: postgres_ext.h:31
char * c
#define sqlca
Definition: sqlca.h:59
PGconn * conn
Definition: streamutil.c:54
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
#define locale_t
Definition: win32_port.h:419