00001
00002
00003 #ifndef _ECPG_LIB_EXTERN_H
00004 #define _ECPG_LIB_EXTERN_H
00005
00006 #include "postgres_fe.h"
00007 #include "libpq-fe.h"
00008 #include "sqlca.h"
00009 #include "sqlda-native.h"
00010 #include "sqlda-compat.h"
00011 #include "ecpg_config.h"
00012 #ifndef CHAR_BIT
00013 #include <limits.h>
00014 #endif
00015
00016 enum COMPAT_MODE
00017 {
00018 ECPG_COMPAT_PGSQL = 0, ECPG_COMPAT_INFORMIX, ECPG_COMPAT_INFORMIX_SE
00019 };
00020
00021 extern bool ecpg_internal_regression_mode;
00022
00023 #define INFORMIX_MODE(X) ((X) == ECPG_COMPAT_INFORMIX || (X) == ECPG_COMPAT_INFORMIX_SE)
00024
00025 enum ARRAY_TYPE
00026 {
00027 ECPG_ARRAY_ERROR, ECPG_ARRAY_NOT_SET, ECPG_ARRAY_ARRAY, ECPG_ARRAY_VECTOR, ECPG_ARRAY_NONE
00028 };
00029
00030 #define ECPG_IS_ARRAY(X) ((X) == ECPG_ARRAY_ARRAY || (X) == ECPG_ARRAY_VECTOR)
00031
00032
00033 struct ECPGgeneric_varchar
00034 {
00035 int len;
00036 char arr[1];
00037 };
00038
00039
00040
00041
00042
00043 struct ECPGtype_information_cache
00044 {
00045 struct ECPGtype_information_cache *next;
00046 int oid;
00047 bool isarray;
00048 };
00049
00050
00051 struct statement
00052 {
00053 int lineno;
00054 char *command;
00055 char *name;
00056 struct connection *connection;
00057 enum COMPAT_MODE compat;
00058 bool force_indicator;
00059 enum ECPG_statement_type statement_type;
00060 bool questionmarks;
00061 struct variable *inlist;
00062 struct variable *outlist;
00063 };
00064
00065
00066 struct prepared_statement
00067 {
00068 char *name;
00069 bool prepared;
00070 struct statement *stmt;
00071 struct prepared_statement *next;
00072 };
00073
00074
00075 struct connection
00076 {
00077 char *name;
00078 PGconn *connection;
00079 bool autocommit;
00080 struct ECPGtype_information_cache *cache_head;
00081 struct prepared_statement *prep_stmts;
00082 struct connection *next;
00083 };
00084
00085
00086 struct descriptor
00087 {
00088 char *name;
00089 PGresult *result;
00090 struct descriptor *next;
00091 int count;
00092 struct descriptor_item *items;
00093 };
00094
00095 struct descriptor_item
00096 {
00097 int num;
00098 char *data;
00099 int indicator;
00100 int length;
00101 int precision;
00102 int scale;
00103 int type;
00104 struct descriptor_item *next;
00105 };
00106
00107 struct variable
00108 {
00109 enum ECPGttype type;
00110 void *value;
00111 void *pointer;
00112 long varcharsize;
00113 long arrsize;
00114 long offset;
00115 enum ECPGttype ind_type;
00116 void *ind_value;
00117 void *ind_pointer;
00118 long ind_varcharsize;
00119 long ind_arrsize;
00120 long ind_offset;
00121 struct variable *next;
00122 };
00123
00124 struct var_list
00125 {
00126 int number;
00127 void *pointer;
00128 struct var_list *next;
00129 };
00130
00131 extern struct var_list *ivlist;
00132
00133
00134
00135
00136 void ecpg_add_mem(void *ptr, int lineno);
00137
00138 bool ecpg_get_data(const PGresult *, int, int, int, enum ECPGttype type,
00139 enum ECPGttype, char *, char *, long, long, long,
00140 enum ARRAY_TYPE, enum COMPAT_MODE, bool);
00141
00142 #ifdef ENABLE_THREAD_SAFETY
00143 void ecpg_pthreads_init(void);
00144 #endif
00145 struct connection *ecpg_get_connection(const char *);
00146 char *ecpg_alloc(long, int);
00147 char *ecpg_realloc(void *, long, int);
00148 void ecpg_free(void *);
00149 bool ecpg_init(const struct connection *, const char *, const int);
00150 char *ecpg_strdup(const char *, int);
00151 const char *ecpg_type_name(enum ECPGttype);
00152 int ecpg_dynamic_type(Oid);
00153 int sqlda_dynamic_type(Oid, enum COMPAT_MODE);
00154 void ecpg_free_auto_mem(void);
00155 void ecpg_clear_auto_mem(void);
00156
00157 struct descriptor *ecpggetdescp(int, char *);
00158
00159 struct descriptor *ecpg_find_desc(int line, const char *name);
00160
00161 struct prepared_statement *ecpg_find_prepared_statement(const char *,
00162 struct connection *, struct prepared_statement **);
00163
00164 bool ecpg_store_result(const PGresult *results, int act_field,
00165 const struct statement * stmt, struct variable * var);
00166 bool ecpg_store_input(const int, const bool, const struct variable *, char **, bool);
00167
00168 bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE);
00169 void ecpg_raise(int line, int code, const char *sqlstate, const char *str);
00170 void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat);
00171 char *ecpg_prepared(const char *, struct connection *);
00172 bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection * conn);
00173 void ecpg_log(const char *format,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
00174 bool ecpg_auto_prepare(int, const char *, const int, char **, const char *);
00175 void ecpg_init_sqlca(struct sqlca_t * sqlca);
00176
00177 struct sqlda_compat *ecpg_build_compat_sqlda(int, PGresult *, int, enum COMPAT_MODE);
00178 void ecpg_set_compat_sqlda(int, struct sqlda_compat **, const PGresult *, int, enum COMPAT_MODE);
00179 struct sqlda_struct *ecpg_build_native_sqlda(int, PGresult *, int, enum COMPAT_MODE);
00180 void ecpg_set_native_sqlda(int, struct sqlda_struct **, const PGresult *, int, enum COMPAT_MODE);
00181
00182
00183
00184
00185 #define ECPG_SQLSTATE_NO_DATA "02000"
00186 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS "07001"
00187 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS "07002"
00188 #define ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION "07006"
00189 #define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX "07009"
00190 #define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION "08001"
00191 #define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST "08003"
00192 #define ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN "08007"
00193 #define ECPG_SQLSTATE_CARDINALITY_VIOLATION "21000"
00194 #define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER "22002"
00195 #define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION "25001"
00196 #define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION "25P01"
00197 #define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME "26000"
00198 #define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME "33000"
00199 #define ECPG_SQLSTATE_INVALID_CURSOR_NAME "34000"
00200 #define ECPG_SQLSTATE_SYNTAX_ERROR "42601"
00201 #define ECPG_SQLSTATE_DATATYPE_MISMATCH "42804"
00202 #define ECPG_SQLSTATE_DUPLICATE_CURSOR "42P03"
00203
00204
00205 #define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR "YE000"
00206 #define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY "YE001"
00207
00208 #endif