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 
18 {
20 };
21 
23 
24 #define INFORMIX_MODE(X) ((X) == ECPG_COMPAT_INFORMIX || (X) == ECPG_COMPAT_INFORMIX_SE)
25 #define ORACLE_MODE(X) ((X) == ECPG_COMPAT_ORACLE)
26 
28 {
30 };
31 
32 #define ECPG_IS_ARRAY(X) ((X) == ECPG_ARRAY_ARRAY || (X) == ECPG_ARRAY_VECTOR)
33 
34 /* A generic varchar type. */
36 {
37  int len;
39 };
40 
41 /* A generic bytea type. */
43 {
44  int len;
46 };
47 
48 /*
49  * type information cache
50  */
51 
53 {
55  int oid;
56  enum ARRAY_TYPE isarray;
57 };
58 
59 #ifdef HAVE_USELOCALE
60 extern locale_t ecpg_clocale; /* LC_NUMERIC=C */
61 #endif
62 
63 /* structure to store one statement */
64 struct statement
65 {
66  int lineno;
67  char *command;
68  char *name;
70  enum COMPAT_MODE compat;
74  struct variable *inlist;
75  struct variable *outlist;
76 #ifdef HAVE_USELOCALE
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 {
137  enum ECPGttype type;
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 void ecpg_pthreads_init(void);
170 struct connection *ecpg_get_connection(const char *connection_name);
171 char *ecpg_alloc(long size, int lineno);
172 char *ecpg_auto_alloc(long size, int lineno);
173 char *ecpg_realloc(void *ptr, long size, int lineno);
174 void ecpg_free(void *ptr);
175 bool ecpg_init(const struct connection *con,
176  const char *connection_name,
177  const int lineno);
178 char *ecpg_strdup(const char *string, int lineno);
179 const char *ecpg_type_name(enum ECPGttype typ);
182 void ecpg_clear_auto_mem(void);
183 
184 struct descriptor *ecpg_find_desc(int line, const char *name);
185 
187  struct connection *con,
188  struct prepared_statement **prev_);
189 
190 bool ecpg_store_result(const PGresult *results, int act_field,
191  const struct statement *stmt, struct variable *var);
192 bool ecpg_store_input(const int lineno, const bool force_indicator,
193  const struct variable *var,
194  char **tobeinserted_p, bool quote);
195 void ecpg_free_params(struct statement *stmt, bool print);
196 bool ecpg_do_prologue(int lineno, const int compat,
197  const int force_indicator, const char *connection_name,
198  const bool questionmarks, enum ECPG_statement_type statement_type,
199  const char *query, va_list args,
200  struct statement **stmt_out);
201 bool ecpg_build_params(struct statement *stmt);
203 bool ecpg_execute(struct statement *stmt);
204 bool ecpg_process_output(struct statement *stmt, bool clear_result);
205 void ecpg_do_epilogue(struct statement *stmt);
206 bool ecpg_do(const int lineno, const int compat,
207  const int force_indicator, const char *connection_name,
208  const bool questionmarks, const int st, const char *query,
209  va_list args);
210 
211 bool ecpg_check_PQresult(PGresult *results, int lineno,
213 void ecpg_raise(int line, int code, const char *sqlstate, const char *str);
214 void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat);
215 char *ecpg_prepared(const char *name, struct connection *con);
216 bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con);
217 void ecpg_log(const char *format,...) pg_attribute_printf(1, 2);
218 bool ecpg_auto_prepare(int lineno, const char *connection_name,
219  const int compat, char **name, const char *query);
221 void ecpg_init_sqlca(struct sqlca_t *sqlca);
222 
223 struct sqlda_compat *ecpg_build_compat_sqlda(int line, PGresult *res, int row,
224  enum COMPAT_MODE compat);
225 void ecpg_set_compat_sqlda(int lineno, struct sqlda_compat **_sqlda,
226  const PGresult *res, int row,
227  enum COMPAT_MODE compat);
228 struct sqlda_struct *ecpg_build_native_sqlda(int line, PGresult *res, int row,
229  enum COMPAT_MODE compat);
230 void ecpg_set_native_sqlda(int lineno, struct sqlda_struct **_sqlda,
231  const PGresult *res, int row, enum COMPAT_MODE compat);
232 unsigned ecpg_hex_dec_len(unsigned srclen);
233 unsigned ecpg_hex_enc_len(unsigned srclen);
234 unsigned ecpg_hex_encode(const char *src, unsigned len, char *dst);
235 
236 #ifdef ENABLE_NLS
237 extern char *ecpg_gettext(const char *msgid) pg_attribute_format_arg(1);
238 #else
239 #define ecpg_gettext(x) (x)
240 #endif
241 
242 /* SQLSTATE values generated or processed by ecpglib (intentionally
243  * not exported -- users should refer to the codes directly) */
244 
245 #define ECPG_SQLSTATE_NO_DATA "02000"
246 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS "07001"
247 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS "07002"
248 #define ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION "07006"
249 #define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX "07009"
250 #define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION "08001"
251 #define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST "08003"
252 #define ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN "08007"
253 #define ECPG_SQLSTATE_CARDINALITY_VIOLATION "21000"
254 #define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER "22002"
255 #define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION "25001"
256 #define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION "25P01"
257 #define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME "26000"
258 #define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME "33000"
259 #define ECPG_SQLSTATE_INVALID_CURSOR_NAME "34000"
260 #define ECPG_SQLSTATE_SYNTAX_ERROR "42601"
261 #define ECPG_SQLSTATE_DATATYPE_MISMATCH "42804"
262 #define ECPG_SQLSTATE_DUPLICATE_CURSOR "42P03"
263 
264 /* implementation-defined internal errors of ecpg */
265 #define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR "YE000"
266 #define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY "YE001"
267 
268 #endif /* _ECPG_ECPGLIB_EXTERN_H */
void print(const void *obj)
Definition: print.c:36
#define pg_attribute_format_arg(a)
Definition: c.h:193
#define pg_attribute_printf(f, a)
Definition: c.h:194
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:401
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:535
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:442