1 /* File: descriptor.h 2 * 3 * Description: This file contains defines and declarations that are related to 4 * the entire driver. 5 * 6 * Comments: See "readme.txt" for copyright and license information. 7 */ 8 9 #ifndef __DESCRIPTOR_H__ 10 #define __DESCRIPTOR_H__ 11 12 #include "psqlodbc.h" 13 14 typedef struct InheritanceClass 15 { 16 UInt4 allocated; 17 UInt4 count; 18 OID cur_tableoid; 19 pgNAME cur_fullTable; 20 struct { 21 OID tableoid; 22 pgNAME fullTable; 23 } inf[1]; 24 } InheritanceClass; 25 26 enum { 27 TI_UPDATABLE = 1L 28 ,TI_HASOIDS_CHECKED = (1L << 1) 29 ,TI_HASOIDS = (1L << 2) 30 ,TI_COLATTRIBUTE = (1L << 3) 31 ,TI_HASSUBCLASS = (1L << 4) 32 }; 33 typedef struct 34 { 35 OID table_oid; 36 COL_INFO *col_info; /* cached SQLColumns info for this table */ 37 pgNAME schema_name; 38 pgNAME table_name; 39 pgNAME table_alias; 40 pgNAME bestitem; 41 pgNAME bestqual; 42 UInt4 flags; 43 InheritanceClass *ih; 44 } TABLE_INFO; 45 #define TI_set_updatable(ti) (ti->flags |= TI_UPDATABLE) 46 #define TI_is_updatable(ti) (0 != (ti->flags & TI_UPDATABLE)) 47 #define TI_no_updatable(ti) (ti->flags &= (~TI_UPDATABLE)) 48 #define TI_set_hasoids_checked(ti) (ti->flags |= TI_HASOIDS_CHECKED) 49 #define TI_checked_hasoids(ti) (0 != (ti->flags & TI_HASOIDS)) 50 #define TI_set_hasoids(ti) (ti->flags |= TI_HASOIDS) 51 #define TI_has_oids(ti) (0 != (ti->flags & TI_HASOIDS)) 52 #define TI_set_has_no_oids(ti) (ti->flags &= (~TI_HASOIDS)) 53 #define TI_set_hassubclass(ti) (ti->flags |= TI_HASSUBCLASS) 54 #define TI_has_subclass(ti) (0 != (ti->flags & TI_HASSUBCLASS)) 55 #define TI_set_has_no_subclass(ti) (ti->flags &= (~TI_HASSUBCLASS)) 56 void TI_Constructor(TABLE_INFO *, const ConnectionClass *); 57 void TI_Destructor(TABLE_INFO **, int); 58 void TI_Create_IH(TABLE_INFO *ti); 59 void TI_Destroy_IH(TABLE_INFO *ti); 60 const pgNAME TI_From_IH(TABLE_INFO *ti, OID tableoid); 61 const pgNAME TI_Ins_IH(TABLE_INFO *ti, OID tableoid, const char *fullName); 62 63 enum { 64 FIELD_INITIALIZED = 0 65 ,FIELD_PARSING = 1L 66 ,FIELD_TEMP_SET = (1L << 1) 67 ,FIELD_COL_ATTRIBUTE = (1L << 2) 68 ,FIELD_PARSED_OK = (1L << 3) 69 ,FIELD_PARSED_INCOMPLETE = (1L << 4) 70 }; 71 typedef struct 72 { 73 char flag; 74 char updatable; 75 Int2 attnum; 76 pgNAME schema_name; 77 TABLE_INFO *ti; /* to resolve explicit table names */ 78 pgNAME column_name; 79 pgNAME column_alias; 80 char nullable; 81 char auto_increment; 82 char func; 83 char columnkey; 84 int column_size; /* precision in 2.x */ 85 int decimal_digits; /* scale in 2.x */ 86 int display_size; 87 SQLLEN length; 88 OID columntype; 89 OID basetype; /* may be the basetype when the column type is a domain */ 90 int typmod; 91 char expr; 92 char quote; 93 char dquote; 94 char numeric; 95 pgNAME before_dot; 96 } FIELD_INFO; 97 Int4 FI_precision(const FIELD_INFO *); 98 Int4 FI_scale(const FIELD_INFO *); 99 void FI_Constructor(FIELD_INFO *, BOOL reuse); 100 void FI_Destructor(FIELD_INFO **, int, BOOL freeFI); 101 #define FI_is_applicable(fi) (NULL != fi && (fi->flag & (FIELD_PARSED_OK | FIELD_COL_ATTRIBUTE)) != 0) 102 #define FI_type(fi) (0 == (fi)->basetype ? (fi)->columntype : (fi)->basetype) 103 104 typedef struct DescriptorHeader_ 105 { 106 ConnectionClass *conn_conn; 107 char embedded; 108 char type_defined; 109 UInt4 desc_type; 110 UInt4 error_row; /* 1-based row */ 111 UInt4 error_index; /* 1-based index */ 112 Int4 __error_number; 113 char *__error_message; 114 PG_ErrorInfo *pgerror; 115 } DescriptorHeader; 116 117 /* 118 * ARD and APD are(must be) of the same format 119 */ 120 struct ARDFields_ 121 { 122 SQLLEN size_of_rowset; /* for ODBC3 fetch operation */ 123 SQLUINTEGER bind_size; /* size of each structure if using 124 * Row-wise Binding */ 125 SQLUSMALLINT *row_operation_ptr; 126 SQLULEN *row_offset_ptr; 127 BindInfoClass *bookmark; 128 BindInfoClass *bindings; 129 SQLSMALLINT allocated; 130 SQLLEN size_of_rowset_odbc2; /* for SQLExtendedFetch */ 131 }; 132 133 /* 134 * APD must be of the same format as ARD 135 */ 136 struct APDFields_ 137 { 138 SQLLEN paramset_size; /* really an SQLINTEGER type */ 139 SQLUINTEGER param_bind_type; /* size of each structure if using 140 * Row-wise Parameter Binding */ 141 SQLUSMALLINT *param_operation_ptr; 142 SQLULEN *param_offset_ptr; 143 ParameterInfoClass *bookmark; /* dummy item to fit APD to ARD */ 144 ParameterInfoClass *parameters; 145 SQLSMALLINT allocated; 146 SQLLEN paramset_size_dummy; /* dummy item to fit APD to ARD */ 147 }; 148 149 struct IRDFields_ 150 { 151 StatementClass *stmt; 152 SQLULEN *rowsFetched; 153 SQLUSMALLINT *rowStatusArray; 154 UInt4 nfields; 155 SQLSMALLINT allocated; 156 FIELD_INFO **fi; 157 }; 158 159 struct IPDFields_ 160 { 161 SQLULEN *param_processed_ptr; 162 SQLUSMALLINT *param_status_ptr; 163 SQLSMALLINT allocated; 164 ParameterImplClass *parameters; 165 }; 166 167 /*** 168 typedef struct 169 { 170 DescriptorHeader deschd; 171 ARDFields ardopts; 172 } ARDClass; 173 typedef struct 174 { 175 DescriptorHeader deschd; 176 APDFields apdopts; 177 } APDClass; 178 typedef struct 179 { 180 DescriptorHeader deschd; 181 IRDFields irdopts; 182 } IRDClass; 183 typedef struct 184 { 185 DescriptorHeader deschd; 186 IPDFields ipdopts; 187 } IPDClass; 188 ***/ 189 typedef struct 190 { 191 DescriptorHeader deschd; 192 union { 193 ARDFields ardf; 194 APDFields apdf; 195 IRDFields irdf; 196 IPDFields ipdf; 197 }; 198 } DescriptorClass; 199 200 #define DC_get_conn(a) ((a)->deschd.conn_conn) 201 #define DC_get_desc_type(a) ((a)->deschd.desc_type) 202 #define DC_get_embedded(a) ((a)->deschd.embedded) 203 204 void InitializeEmbeddedDescriptor(DescriptorClass *, StatementClass *stmt, 205 UInt4 desc_type); 206 void DC_Destructor(DescriptorClass *desc); 207 void InitializeARDFields(ARDFields *self); 208 void InitializeAPDFields(APDFields *self); 209 /* void InitializeIRDFields(IRDFields *self); 210 void InitializeIPDFiedls(IPDFields *self); */ 211 BindInfoClass *ARD_AllocBookmark(ARDFields *self); 212 void ARD_unbind_cols(ARDFields *self, BOOL freeall); 213 void APD_free_params(APDFields *self, char option); 214 void IPD_free_params(IPDFields *self, char option); 215 BOOL getCOLIfromTI(const char *, ConnectionClass *, StatementClass *, const OID, TABLE_INFO **); 216 RETCODE DC_set_stmt(DescriptorClass *desc, StatementClass *stmt); 217 void DC_clear_error(DescriptorClass *desc); 218 void DC_set_error(DescriptorClass *desc, int errornumber, const char * errormsg); 219 void DC_set_errormsg(DescriptorClass *desc, const char * errormsg); 220 PG_ErrorInfo *DC_get_error(DescriptorClass *self); 221 int DC_get_errornumber(const DescriptorClass *self); 222 const char *DC_get_errormsg(const DescriptorClass *self); 223 void DC_log_error(const char *func, const char *desc, const DescriptorClass *self); 224 225 /* Error numbers about descriptor handle */ 226 enum { 227 LOWEST_DESC_ERROR = -2 228 /* minus means warning/notice message */ 229 ,DESC_ERROR_IN_ROW = -2 230 ,DESC_OPTION_VALUE_CHANGED = -1 231 ,DESC_OK = 0 232 ,DESC_EXEC_ERROR 233 ,DESC_STATUS_ERROR 234 ,DESC_SEQUENCE_ERROR 235 ,DESC_NO_MEMORY_ERROR 236 ,DESC_COLNUM_ERROR 237 ,DESC_NO_STMTSTRING 238 ,DESC_ERROR_TAKEN_FROM_BACKEND 239 ,DESC_INTERNAL_ERROR 240 ,DESC_STILL_EXECUTING 241 ,DESC_NOT_IMPLEMENTED_ERROR 242 ,DESC_BAD_PARAMETER_NUMBER_ERROR 243 ,DESC_OPTION_OUT_OF_RANGE_ERROR 244 ,DESC_INVALID_COLUMN_NUMBER_ERROR 245 ,DESC_RESTRICTED_DATA_TYPE_ERROR 246 ,DESC_INVALID_CURSOR_STATE_ERROR 247 ,DESC_CREATE_TABLE_ERROR 248 ,DESC_NO_CURSOR_NAME 249 ,DESC_INVALID_CURSOR_NAME 250 ,DESC_INVALID_ARGUMENT_NO 251 ,DESC_ROW_OUT_OF_RANGE 252 ,DESC_OPERATION_CANCELLED 253 ,DESC_INVALID_CURSOR_POSITION 254 ,DESC_VALUE_OUT_OF_RANGE 255 ,DESC_OPERATION_INVALID 256 ,DESC_PROGRAM_TYPE_OUT_OF_RANGE 257 ,DESC_BAD_ERROR 258 ,DESC_INVALID_OPTION_IDENTIFIER 259 ,DESC_RETURN_NULL_WITHOUT_INDICATOR 260 ,DESC_INVALID_DESCRIPTOR_IDENTIFIER 261 ,DESC_OPTION_NOT_FOR_THE_DRIVER 262 ,DESC_FETCH_OUT_OF_RANGE 263 ,DESC_COUNT_FIELD_INCORRECT 264 }; 265 #endif /* __DESCRIPTOR_H__ */ 266