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