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