PostgreSQL Source Code  git master
extern.h
Go to the documentation of this file.
1 /* src/interfaces/ecpg/ecpglib/extern.h */
2 
3 #ifndef _ECPG_LIB_EXTERN_H
4 #define _ECPG_LIB_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 
12 #ifndef CHAR_BIT
13 #include <limits.h>
14 #endif
15 
17 {
19 };
20 
22 
23 #define INFORMIX_MODE(X) ((X) == ECPG_COMPAT_INFORMIX || (X) == ECPG_COMPAT_INFORMIX_SE)
24 #define ORACLE_MODE(X) ((X) == ECPG_COMPAT_ORACLE)
25 
27 {
29 };
30 
31 #define ECPG_IS_ARRAY(X) ((X) == ECPG_ARRAY_ARRAY || (X) == ECPG_ARRAY_VECTOR)
32 
33 /* A generic varchar type. */
35 {
36  int len;
37  char arr[FLEXIBLE_ARRAY_MEMBER];
38 };
39 
40 /*
41  * type information cache
42  */
43 
45 {
47  int oid;
49 };
50 
51 /* structure to store one statement */
52 struct statement
53 {
54  int lineno;
55  char *command;
56  char *name;
60  enum ECPG_statement_type statement_type;
62  struct variable *inlist;
63  struct variable *outlist;
64  char *oldlocale;
65  int nparams;
66  char **paramvalues;
68 };
69 
70 /* structure to store prepared statements for a connection */
72 {
73  char *name;
74  bool prepared;
75  struct statement *stmt;
77 };
78 
79 /* structure to store connections */
80 struct connection
81 {
82  char *name;
84  bool autocommit;
87  struct connection *next;
88 };
89 
90 /* structure to store descriptors */
91 struct descriptor
92 {
93  char *name;
95  struct descriptor *next;
96  int count;
98 };
99 
101 {
102  int num;
103  char *data;
105  int length;
107  int scale;
108  int type;
110 };
111 
112 struct variable
113 {
115  void *value;
116  void *pointer;
118  long arrsize;
119  long offset;
120  enum ECPGttype ind_type;
121  void *ind_value;
122  void *ind_pointer;
126  struct variable *next;
127 };
128 
129 struct var_list
130 {
131  int number;
132  void *pointer;
133  struct var_list *next;
134 };
135 
136 extern struct var_list *ivlist;
137 
138 /* Here are some methods used by the lib. */
139 
140 bool ecpg_add_mem(void *ptr, int lineno);
141 
142 bool ecpg_get_data(const PGresult *, int, int, int, enum ECPGttype type,
143  enum ECPGttype, char *, char *, long, long, long,
144  enum ARRAY_TYPE, enum COMPAT_MODE, bool);
145 
146 #ifdef ENABLE_THREAD_SAFETY
147 void ecpg_pthreads_init(void);
148 #endif
149 struct connection *ecpg_get_connection(const char *);
150 char *ecpg_alloc(long, int);
151 char *ecpg_auto_alloc(long, int);
152 char *ecpg_realloc(void *, long, int);
153 void ecpg_free(void *);
154 bool ecpg_init(const struct connection *, const char *, const int);
155 char *ecpg_strdup(const char *, int);
156 const char *ecpg_type_name(enum ECPGttype);
159 void ecpg_free_auto_mem(void);
160 void ecpg_clear_auto_mem(void);
161 
162 struct descriptor *ecpggetdescp(int, char *);
163 
164 struct descriptor *ecpg_find_desc(int line, const char *name);
165 
167  struct connection *, struct prepared_statement **);
168 
169 bool ecpg_store_result(const PGresult *results, int act_field,
170  const struct statement *stmt, struct variable *var);
171 bool ecpg_store_input(const int, const bool, const struct variable *, char **, bool);
172 void ecpg_free_params(struct statement *stmt, bool print);
173 bool ecpg_do_prologue(int, const int, const int, const char *, const bool,
174  enum ECPG_statement_type, const char *, va_list,
175  struct statement **);
176 bool ecpg_build_params(struct statement *);
178 bool ecpg_execute(struct statement *stmt);
179 bool ecpg_process_output(struct statement *, bool);
180 void ecpg_do_epilogue(struct statement *);
181 bool ecpg_do(const int, const int, const int, const char *, const bool,
182  const int, const char *, va_list);
183 
184 bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE);
185 void ecpg_raise(int line, int code, const char *sqlstate, const char *str);
186 void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat);
187 char *ecpg_prepared(const char *, struct connection *);
188 bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *conn);
189 void ecpg_log(const char *format,...) pg_attribute_printf(1, 2);
190 bool ecpg_auto_prepare(int, const char *, const int, char **, const char *);
191 void ecpg_init_sqlca(struct sqlca_t *sqlca);
192 
193 struct sqlda_compat *ecpg_build_compat_sqlda(int, PGresult *, int, enum COMPAT_MODE);
194 void ecpg_set_compat_sqlda(int, struct sqlda_compat **, const PGresult *, int, enum COMPAT_MODE);
195 struct sqlda_struct *ecpg_build_native_sqlda(int, PGresult *, int, enum COMPAT_MODE);
196 void ecpg_set_native_sqlda(int, struct sqlda_struct **, const PGresult *, int, enum COMPAT_MODE);
197 
198 /* SQLSTATE values generated or processed by ecpglib (intentionally
199  * not exported -- users should refer to the codes directly) */
200 
201 #define ECPG_SQLSTATE_NO_DATA "02000"
202 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS "07001"
203 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS "07002"
204 #define ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION "07006"
205 #define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX "07009"
206 #define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION "08001"
207 #define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST "08003"
208 #define ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN "08007"
209 #define ECPG_SQLSTATE_CARDINALITY_VIOLATION "21000"
210 #define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER "22002"
211 #define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION "25001"
212 #define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION "25P01"
213 #define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME "26000"
214 #define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME "33000"
215 #define ECPG_SQLSTATE_INVALID_CURSOR_NAME "34000"
216 #define ECPG_SQLSTATE_SYNTAX_ERROR "42601"
217 #define ECPG_SQLSTATE_DATATYPE_MISMATCH "42804"
218 #define ECPG_SQLSTATE_DUPLICATE_CURSOR "42P03"
219 
220 /* implementation-defined internal errors of ecpg */
221 #define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR "YE000"
222 #define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY "YE001"
223 
224 #endif /* _ECPG_LIB_EXTERN_H */
long ind_arrsize
Definition: extern.h:124
bool ecpg_init(const struct connection *, const char *, const int)
Definition: misc.c:105
struct var_list * next
Definition: extern.h:133
int ecpg_dynamic_type(Oid)
Definition: typename.c:72
char arr[FLEXIBLE_ARRAY_MEMBER]
Definition: extern.h:37
ARRAY_TYPE
Definition: extern.h:26
bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *conn)
Definition: prepare.c:276
void print(const void *obj)
Definition: print.c:35
void ecpg_free(void *)
Definition: memory.c:13
bool ecpg_store_input(const int, const bool, const struct variable *, char **, bool)
Definition: execute.c:494
#define sqlca
Definition: sqlca.h:59
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition: descriptor.c:800
bool ecpg_build_params(struct statement *)
Definition: execute.c:1107
char * data
Definition: extern.h:103
char * name
Definition: extern.h:82
void * pointer
Definition: extern.h:116
void * pointer
Definition: extern.h:132
void ecpg_free_auto_mem(void)
PGresult * results
Definition: extern.h:67
char * ecpg_strdup(const char *, int)
Definition: memory.c:47
char * ecpg_auto_alloc(long, int)
Definition: memory.c:108
bool autocommit
Definition: extern.h:84
bool ecpg_process_output(struct statement *, bool)
Definition: execute.c:1481
struct variable * next
Definition: extern.h:126
unsigned int Oid
Definition: postgres_ext.h:31
char * oldlocale
Definition: extern.h:64
#define pg_attribute_printf(f, a)
Definition: c.h:132
struct connection * ecpg_get_connection(const char *)
Definition: connect.c:74
ECPG_statement_type
Definition: ecpgtype.h:94
struct ECPGtype_information_cache * next
Definition: extern.h:46
void ecpg_log(const char *format,...) pg_attribute_printf(1
void ecpg_do_epilogue(struct statement *)
Definition: execute.c:1986
struct descriptor * next
Definition: extern.h:95
PGconn * conn
Definition: streamutil.c:55
struct connection * connection
Definition: extern.h:57
void ecpg_set_compat_sqlda(int, struct sqlda_compat **, const PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:253
struct ECPGtype_information_cache * cache_head
Definition: extern.h:85
void ecpg_free_params(struct statement *stmt, bool print)
Definition: execute.c:1052
const char * ecpg_type_name(enum ECPGttype)
Definition: typename.c:18
Definition: sqlca.h:19
char * c
struct connection * next
Definition: extern.h:87
bool ecpg_do(const int, const int, const int, const char *, const bool, const int, const char *, va_list)
Definition: execute.c:2003
struct statement * stmt
Definition: extern.h:75
int lineno
Definition: extern.h:54
void * value
Definition: extern.h:115
char * ecpg_alloc(long, int)
Definition: memory.c:19
PGresult * result
Definition: extern.h:94
void bool ecpg_auto_prepare(int, const char *, const int, char **, const char *)
Definition: prepare.c:468
void ecpg_clear_auto_mem(void)
Definition: memory.c:158
int number
Definition: extern.h:131
bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE)
Definition: error.c:283
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:1754
struct prepared_statement * ecpg_find_prepared_statement(const char *, struct connection *, struct prepared_statement **)
Definition: prepare.c:182
bool ecpg_internal_regression_mode
Definition: misc.c:30
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:127
struct prepared_statement * next
Definition: extern.h:76
char * ecpg_prepared(const char *, struct connection *)
Definition: prepare.c:295
struct sqlda_compat * ecpg_build_compat_sqlda(int, PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:203
void * ind_pointer
Definition: extern.h:122
int count
Definition: extern.h:96
struct descriptor * ecpggetdescp(int, char *)
long offset
Definition: extern.h:119
struct sqlda_struct * ecpg_build_native_sqlda(int, PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:410
char * command
Definition: extern.h:55
struct variable * inlist
Definition: extern.h:62
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:99
enum COMPAT_MODE compat
Definition: ecpg.c:25
PGconn * connection
Definition: extern.h:83
struct var_list * ivlist
Definition: misc.c:521
bool ecpg_autostart_transaction(struct statement *stmt)
Definition: execute.c:1412
long ind_varcharsize
Definition: extern.h:123
bool force_indicator
Definition: extern.h:59
bool ecpg_store_result(const PGresult *results, int act_field, const struct statement *stmt, struct variable *var)
Definition: execute.c:309
char * name
Definition: extern.h:56
struct descriptor_item * items
Definition: extern.h:97
const char * name
Definition: encode.c:521
long ind_offset
Definition: extern.h:125
char ** paramvalues
Definition: extern.h:66
struct descriptor_item * next
Definition: extern.h:109
bool questionmarks
Definition: extern.h:61
long arrsize
Definition: extern.h:118
int nparams
Definition: extern.h:65
void * ind_value
Definition: extern.h:121
bool ecpg_execute(struct statement *stmt)
Definition: execute.c:1433
void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
Definition: error.c:219
COMPAT_MODE
Definition: extern.h:16
char * name
Definition: extern.h:93
static char format
Definition: pg_basebackup.c:83
int sqlda_dynamic_type(Oid, enum COMPAT_MODE)
Definition: typename.c:106
void ecpg_set_native_sqlda(int, struct sqlda_struct **, const PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:442
enum ARRAY_TYPE isarray
Definition: extern.h:48
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
bool ecpg_add_mem(void *ptr, int lineno)
Definition: memory.c:124
long varcharsize
Definition: extern.h:117
struct variable * outlist
Definition: extern.h:63
char * ecpg_realloc(void *, long, int)
Definition: memory.c:33
struct prepared_statement * prep_stmts
Definition: extern.h:86
ECPGttype
Definition: ecpgtype.h:41