PostgreSQL Source Code: src/interfaces/ecpg/ecpglib/ecpglib_extern.h Source File

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
17 enum COMPAT_MODE
18{
19 ECPG_COMPAT_PGSQL = 0, ECPG_COMPAT_INFORMIX, ECPG_COMPAT_INFORMIX_SE, ECPG_COMPAT_ORACLE
20 };
21
22extern bool ecpg_internal_regression_mode;
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
27 enum ARRAY_TYPE
28{
29 ECPG_ARRAY_ERROR, ECPG_ARRAY_NOT_SET, ECPG_ARRAY_ARRAY, ECPG_ARRAY_VECTOR, ECPG_ARRAY_NONE
30 };
31
32 #define ECPG_IS_ARRAY(X) ((X) == ECPG_ARRAY_ARRAY || (X) == ECPG_ARRAY_VECTOR)
33
34/* A generic varchar type. */
35 struct ECPGgeneric_varchar
36{
37 int len;
38 char arr[FLEXIBLE_ARRAY_MEMBER];
39};
40
41/* A generic bytea type. */
42 struct ECPGgeneric_bytea
43{
44 int len;
45 char arr[FLEXIBLE_ARRAY_MEMBER];
46};
47
48/*
49 * type information cache
50 */
51
52 struct ECPGtype_information_cache
53{
54 struct ECPGtype_information_cache *next;
55 int oid;
56 enum ARRAY_TYPE isarray;
57};
58
59#ifdef HAVE_USELOCALE
60extern 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;
69 struct connection *connection;
70 enum COMPAT_MODE compat;
71 bool force_indicator;
72 enum ECPG_statement_type statement_type;
73 bool questionmarks;
74 struct variable *inlist;
75 struct variable *outlist;
76#ifdef HAVE_USELOCALE
77 locale_t oldlocale;
78#else
79 char *oldlocale;
80#ifdef WIN32
81 int oldthreadlocale;
82#endif
83#endif
84 int nparams;
85 char **paramvalues;
86 int *paramlengths;
87 int *paramformats;
88 PGresult *results;
89};
90
91/* structure to store prepared statements for a connection */
92 struct prepared_statement
93{
94 char *name;
95 bool prepared;
96 struct statement *stmt;
97 struct prepared_statement *next;
98};
99
100/* structure to store connections */
101 struct connection
102{
103 char *name;
104 PGconn *connection;
105 bool autocommit;
106 struct ECPGtype_information_cache *cache_head;
107 struct prepared_statement *prep_stmts;
108 struct connection *next;
109};
110
111/* structure to store descriptors */
112 struct descriptor
113{
114 char *name;
115 PGresult *result;
116 struct descriptor *next;
117 int count;
118 struct descriptor_item *items;
119};
120
121 struct descriptor_item
122{
123 int num;
124 char *data;
125 int indicator;
126 int length;
127 int precision;
128 int scale;
129 int type;
130 bool is_binary;
131 int data_len;
132 struct descriptor_item *next;
133};
134
135 struct variable
136{
137 enum ECPGttype type;
138 void *value;
139 void *pointer;
140 long varcharsize;
141 long arrsize;
142 long offset;
143 enum ECPGttype ind_type;
144 void *ind_value;
145 void *ind_pointer;
146 long ind_varcharsize;
147 long ind_arrsize;
148 long ind_offset;
149 struct variable *next;
150};
151
152 struct var_list
153{
154 int number;
155 void *pointer;
156 struct var_list *next;
157};
158
159extern struct var_list *ivlist;
160
161/* Here are some methods used by the lib. */
162
163bool ecpg_add_mem(void *ptr, int lineno);
164
165bool 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
169void ecpg_pthreads_init(void);
170struct connection *ecpg_get_connection(const char *connection_name);
171char *ecpg_alloc(long size, int lineno);
172char *ecpg_auto_alloc(long size, int lineno);
173char *ecpg_realloc(void *ptr, long size, int lineno);
174void ecpg_free(void *ptr);
175bool ecpg_init(const struct connection *con,
176 const char *connection_name,
177 const int lineno);
178char *ecpg_strdup(const char *string, int lineno, bool *alloc_failed);
179const char *ecpg_type_name(enum ECPGttype typ);
180int ecpg_dynamic_type(Oid type);
181int sqlda_dynamic_type(Oid type, enum COMPAT_MODE compat);
182void ecpg_clear_auto_mem(void);
183
184struct descriptor *ecpg_find_desc(int line, const char *name);
185
186struct prepared_statement *ecpg_find_prepared_statement(const char *name,
187 struct connection *con,
188 struct prepared_statement **prev_);
189
190bool ecpg_store_result(const PGresult *results, int act_field,
191 const struct statement *stmt, struct variable *var);
192bool ecpg_store_input(const int lineno, const bool force_indicator,
193 const struct variable *var,
194 char **tobeinserted_p, bool quote);
195void ecpg_free_params(struct statement *stmt, bool print);
196bool 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);
201bool ecpg_build_params(struct statement *stmt);
202bool ecpg_autostart_transaction(struct statement *stmt);
203bool ecpg_execute(struct statement *stmt);
204bool ecpg_process_output(struct statement *stmt, bool clear_result);
205void ecpg_do_epilogue(struct statement *stmt);
206bool 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
211bool ecpg_check_PQresult(PGresult *results, int lineno,
212 PGconn *connection, enum COMPAT_MODE compat);
213void ecpg_raise(int line, int code, const char *sqlstate, const char *str);
214void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat);
215char *ecpg_prepared(const char *name, struct connection *con);
216bool 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);
218bool ecpg_auto_prepare(int lineno, const char *connection_name,
219 const int compat, char **name, const char *query);
220bool ecpg_register_prepared_stmt(struct statement *stmt);
221void ecpg_init_sqlca(struct sqlca_t *sqlca);
222
223struct sqlda_compat *ecpg_build_compat_sqlda(int line, PGresult *res, int row,
224 enum COMPAT_MODE compat);
225void ecpg_set_compat_sqlda(int lineno, struct sqlda_compat **_sqlda,
226 const PGresult *res, int row,
227 enum COMPAT_MODE compat);
228struct sqlda_struct *ecpg_build_native_sqlda(int line, PGresult *res, int row,
229 enum COMPAT_MODE compat);
230void ecpg_set_native_sqlda(int lineno, struct sqlda_struct **_sqlda,
231 const PGresult *res, int row, enum COMPAT_MODE compat);
232unsigned ecpg_hex_dec_len(unsigned srclen);
233unsigned ecpg_hex_enc_len(unsigned srclen);
234unsigned ecpg_hex_encode(const char *src, unsigned len, char *dst);
235
236#ifdef ENABLE_NLS
237extern 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:231
#define pg_attribute_printf(f, a)
Definition: c.h:232
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:470
enum COMPAT_MODE compat
Definition: ecpg.c:26
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:363
unsigned ecpg_hex_dec_len(unsigned srclen)
Definition: data.c:134
void ecpg_pthreads_init(void)
Definition: connect.c:30
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition: descriptor.c:840
COMPAT_MODE
Definition: ecpglib_extern.h:18
@ ECPG_COMPAT_PGSQL
Definition: ecpglib_extern.h:19
@ ECPG_COMPAT_ORACLE
Definition: ecpglib_extern.h:19
@ ECPG_COMPAT_INFORMIX
Definition: ecpglib_extern.h:19
@ ECPG_COMPAT_INFORMIX_SE
Definition: ecpglib_extern.h:19
char * ecpg_strdup(const char *string, int lineno, bool *alloc_failed)
Definition: memory.c:54
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
char * ecpg_alloc(long size, int lineno)
Definition: memory.c:19
void ecpg_free_params(struct statement *stmt, bool print)
Definition: execute.c:1106
struct sqlda_struct * ecpg_build_native_sqlda(int line, PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:412
bool ecpg_add_mem(void *ptr, int lineno)
Definition: memory.c:126
char * ecpg_auto_alloc(long size, int lineno)
Definition: memory.c:110
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:581
void ecpg_clear_auto_mem(void)
Definition: memory.c:160
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:2232
struct sqlda_compat * ecpg_build_compat_sqlda(int line, PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:205
char * ecpg_prepared(const char *name, struct connection *con)
Definition: prepare.c:383
void ecpg_set_compat_sqlda(int lineno, struct sqlda_compat **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:255
char * ecpg_realloc(void *ptr, long size, int lineno)
Definition: memory.c:33
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:2259
const char * ecpg_type_name(enum ECPGttype typ)
Definition: typename.c:17
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
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
Definition: prepare.c:265
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:76
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:67
bool ecpg_autostart_transaction(struct statement *stmt)
Definition: execute.c:1581
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
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
bool ecpg_internal_regression_mode
Definition: misc.c:29
void ecpg_free(void *ptr)
Definition: memory.c:13
ARRAY_TYPE
Definition: ecpglib_extern.h:28
@ ECPG_ARRAY_NOT_SET
Definition: ecpglib_extern.h:29
@ ECPG_ARRAY_ARRAY
Definition: ecpglib_extern.h:29
@ ECPG_ARRAY_VECTOR
Definition: ecpglib_extern.h:29
@ ECPG_ARRAY_NONE
Definition: ecpglib_extern.h:29
@ ECPG_ARRAY_ERROR
Definition: ecpglib_extern.h:29
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
Definition: pg_basebackup.c:134
const void size_t len
unsigned int Oid
Definition: postgres_ext.h:32
c
char * c
Definition: preproc-cursor.c:31
#define sqlca
Definition: sqlca.h:59
PGconn * conn
Definition: streamutil.c:52
char arr[FLEXIBLE_ARRAY_MEMBER]
Definition: ecpglib_extern.h:45
char arr[FLEXIBLE_ARRAY_MEMBER]
Definition: ecpglib_extern.h:38
struct ECPGtype_information_cache * next
Definition: ecpglib_extern.h:54
enum ARRAY_TYPE isarray
Definition: ecpglib_extern.h:56
char * name
PGconn * connection
bool autocommit
struct ECPGtype_information_cache * cache_head
struct connection * next
struct prepared_statement * prep_stmts
struct descriptor_item * next
struct descriptor * next
char * name
struct descriptor_item * items
PGresult * result
struct statement * stmt
Definition: ecpglib_extern.h:96
struct prepared_statement * next
Definition: ecpglib_extern.h:97
Definition: sqlca.h:20
struct variable * inlist
Definition: ecpglib_extern.h:74
int lineno
Definition: ecpglib_extern.h:66
int nparams
Definition: ecpglib_extern.h:84
bool questionmarks
Definition: ecpglib_extern.h:73
char * command
Definition: ecpglib_extern.h:67
char ** paramvalues
Definition: ecpglib_extern.h:85
char * oldlocale
Definition: ecpglib_extern.h:79
struct variable * outlist
Definition: ecpglib_extern.h:75
struct connection * connection
Definition: ecpglib_extern.h:69
bool force_indicator
Definition: ecpglib_extern.h:71
int * paramformats
Definition: ecpglib_extern.h:87
enum COMPAT_MODE compat
Definition: ecpglib_extern.h:70
enum ECPG_statement_type statement_type
Definition: ecpglib_extern.h:72
char * name
Definition: ecpglib_extern.h:68
PGresult * results
Definition: ecpglib_extern.h:88
int * paramlengths
Definition: ecpglib_extern.h:86
struct var_list * next
int number
void * pointer
void * value
long ind_arrsize
long ind_offset
void * ind_value
long ind_varcharsize
long varcharsize
long arrsize
struct variable * next
enum ECPGttype type
long offset
enum ECPGttype ind_type
void * ind_pointer
void * pointer
const char * type
const char * name
#define locale_t
Definition: win32_port.h:432

AltStyle によって変換されたページ (->オリジナル) /