Better error reporting when git-get-modules fails.
[versaplex.git] / vxodbc / descriptor.h
blobc6a2711d5f1ac60dc63cd6b1cd32c631b83061c5
1 /* File: descriptor.h
3 * Description: This file contains defines and declarations that are related to
4 * the entire driver.
6 * Comments: See "notice.txt" for copyright and license information.
8 * $Id: descriptor.h,v 1.19 2006/10/13 13:13:31 hinoue Exp $
12 #ifndef __DESCRIPTOR_H__
13 #define __DESCRIPTOR_H__
15 #include "psqlodbc.h"
17 typedef struct
19 char *name;
20 } pgNAME;
21 #define GET_NAME(the_name) ((the_name).name)
22 #define SAFE_NAME(the_name) ((the_name).name ? (the_name).name : NULL_STRING)
23 #define PRINT_NAME(the_name) ((the_name).name ? (the_name).name : PRINT_NULL)
24 #define NAME_IS_NULL(the_name) (NULL == (the_name).name)
25 #define NAME_IS_VALID(the_name) (NULL != (the_name).name)
26 #define INIT_NAME(the_name) ((the_name).name = NULL)
27 #define NULL_THE_NAME(the_name) \
28 do { \
29 if ((the_name).name) free((the_name).name); \
30 (the_name).name = NULL; \
31 } while (0)
32 #define STR_TO_NAME(the_name, str) \
33 do { \
34 if ((the_name).name) \
35 free((the_name).name); \
36 (the_name).name = (str ? strdup((str)) : NULL); \
37 } while (0)
38 #define STRN_TO_NAME(the_name, str, n) \
39 do { \
40 if ((the_name).name) \
41 free((the_name).name); \
42 if (str) \
43 { \
44 (the_name).name = (char *)malloc(n + 1); \
45 memcpy((the_name).name, str, n); \
46 (the_name).name[n] = '\0'; \
47 } \
48 else \
49 (the_name).name = NULL; \
50 } while (0)
51 #define NAME_TO_STR(str, the_name) \
52 do {\
53 if ((the_name).name) strcpy(str, (the_name).name); \
54 else *str = '\0'; \
55 } while (0)
56 #define NAME_TO_NAME(to, from) \
57 do { \
58 if ((to).name) \
59 free((to).name); \
60 if ((from).name) \
61 (to).name = strdup(from.name); \
62 else \
63 (to).name = NULL; \
64 } while (0)
65 #define MOVE_NAME(to, from) \
66 do { \
67 if ((to).name) \
68 free((to).name); \
69 (to).name = (from).name; \
70 (from).name = NULL; \
71 } while (0)
72 #define SET_NAME(the_name, str) ((the_name).name = (str))
74 #define NAMECMP(name1, name2) (strcmp(SAFE_NAME(name1), SAFE_NAME(name2)))
75 #define NAMEICMP(name1, name2) (stricmp(SAFE_NAME(name1), SAFE_NAME(name2)))
77 enum {
78 TI_UPDATABLE = 1L
79 ,TI_HASOIDS_CHECKED = (1L << 1)
80 ,TI_HASOIDS = (1L << 2)
81 ,TI_COLATTRIBUTE = (1L << 3)
83 typedef struct
85 OID table_oid;
86 COL_INFO *col_info; /* cached SQLColumns info for this table */
87 pgNAME schema_name;
88 pgNAME table_name;
89 pgNAME table_alias;
90 pgNAME bestitem;
91 pgNAME bestqual;
92 UInt4 flags;
93 } TABLE_INFO;
94 #define TI_set_updatable(ti) (ti->flags |= TI_UPDATABLE)
95 #define TI_is_updatable(ti) (0 != (ti->flags &= TI_UPDATABLE))
96 #define TI_no_updatable(ti) (ti->flags &= (~TI_UPDATABLE))
97 #define TI_set_hasoids_checked(ti) (ti->flags |= TI_HASOIDS_CHECKED)
98 #define TI_checked_hasoids(ti) (0 != (ti->flags &= TI_HASOIDS))
99 #define TI_set_hasoids(ti) (ti->flags |= TI_HASOIDS)
100 #define TI_has_oids(ti) (0 != (ti->flags &= TI_HASOIDS))
101 #define TI_set_has_no_oids(ti) (ti->flags &= (~TI_HASOIDS))
102 void TI_Constructor(TABLE_INFO *, const ConnectionClass *);
103 void TI_Destructor(TABLE_INFO **, int);
105 enum {
106 FIELD_INITIALIZED = 0
107 ,FIELD_PARSING = 1L
108 ,FIELD_TEMP_SET = (1L << 1)
109 ,FIELD_COL_ATTRIBUTE = (1L << 2)
110 ,FIELD_PARSED_OK = (1L << 3)
111 ,FIELD_PARSED_INCOMPLETE = (1L << 4)
113 typedef struct
115 char flag;
116 char updatable;
117 Int2 attnum;
118 pgNAME schema_name;
119 TABLE_INFO *ti; /* to resolve explicit table names */
120 pgNAME column_name;
121 pgNAME column_alias;
122 char nullable;
123 char auto_increment;
124 char func;
125 int column_size; /* precision in 2.x */
126 int decimal_digits; /* scale in 2.x */
127 int display_size;
128 SQLLEN length;
129 OID columntype;
130 OID basetype;
131 char expr;
132 char quote;
133 char dquote;
134 char numeric;
135 pgNAME before_dot;
136 } FIELD_INFO;
137 Int4 FI_precision(const FIELD_INFO *);
138 Int4 FI_scale(const FIELD_INFO *);
139 void FI_Constructor(FIELD_INFO *, BOOL reuse);
140 void FI_Destructor(FIELD_INFO **, int, BOOL freeFI);
141 #define FI_is_applicable(fi) (NULL != fi && (fi->flag & (FIELD_PARSED_OK | FIELD_COL_ATTRIBUTE)) != 0)
142 #define FI_type(fi) (0 == (fi)->basetype ? (fi)->columntype : (fi)->basetype)
144 typedef struct DescriptorHeader_
146 ConnectionClass *conn_conn;
147 char embedded;
148 char type_defined;
149 UInt4 desc_type;
150 UInt4 error_row; /* 1-based row */
151 UInt4 error_index; /* 1-based index */
152 Int4 __error_number;
153 char *__error_message;
154 PG_ErrorInfo *pgerror;
155 } DescriptorClass;
157 // VX_CLEANUP: There's no longer any external access to the App/Implementation
158 // Row/Param Descriptors now that SQLGetDescField and SQLSetDescField are
159 // disabled. It might be possible to get rid of these altogether.
161 * ARD and APD are(must be) of the same format
163 // App Row Descriptor
164 struct ARDFields_
166 SQLLEN size_of_rowset; /* for ODBC3 fetch operation */
167 SQLUINTEGER bind_size; /* size of each structure if using
168 * Row-wise Binding */
169 SQLUSMALLINT *row_operation_ptr;
170 SQLULEN *row_offset_ptr;
171 BindInfoClass *bookmark;
172 BindInfoClass *bindings;
173 SQLSMALLINT allocated;
174 SQLLEN size_of_rowset_odbc2; /* for SQLExtendedFetch */
178 * APD must be of the same format as ARD
180 // App Param Descriptor
181 struct APDFields_
183 SQLLEN paramset_size; /* really an SQLINTEGER type */
184 SQLUINTEGER param_bind_type; /* size of each structure if using
185 * Row-wise Parameter Binding */
186 SQLUSMALLINT *param_operation_ptr;
187 SQLULEN *param_offset_ptr;
188 ParameterInfoClass *bookmark; /* dummy item to fit APD to ARD */
189 ParameterInfoClass *parameters;
190 SQLSMALLINT allocated;
191 SQLLEN paramset_size_dummy; /* dummy item to fit APD to ARD */
194 // Implementation Row Descriptor
195 struct IRDFields_
197 StatementClass *stmt;
198 SQLULEN *rowsFetched;
199 SQLUSMALLINT *rowStatusArray;
200 UInt4 nfields;
201 SQLSMALLINT allocated;
202 FIELD_INFO **fi;
205 // Implementation Param Descriptor
206 struct IPDFields_
208 SQLUINTEGER *param_processed_ptr;
209 SQLUSMALLINT *param_status_ptr;
210 SQLSMALLINT allocated;
211 ParameterImplClass *parameters;
214 typedef struct
216 DescriptorClass deschd;
217 union {
218 ARDFields ard;
219 APDFields apd;
220 IRDFields ird;
221 IPDFields ipd;
222 } flds;
223 } DescriptorAlloc;
224 typedef struct
226 DescriptorClass deschd;
227 ARDFields ardopts;
228 } ARDClass;
229 typedef struct
231 DescriptorClass deschd;
232 APDFields apdopts;
233 } APDClass;
234 typedef struct
236 DescriptorClass deschd;
237 IRDFields irdopts;
238 } IRDClass;
239 typedef struct
241 DescriptorClass deschd;
242 IPDFields ipdopts;
243 } IPDClass;
245 #define DC_get_conn(a) (a->conn_conn)
247 void InitializeEmbeddedDescriptor(DescriptorClass *, StatementClass *stmt,
248 UInt4 desc_type);
249 void DC_Destructor(DescriptorClass *desc);
250 void InitializeARDFields(ARDFields *self);
251 void InitializeAPDFields(APDFields *self);
252 /* void InitializeIRDFields(IRDFields *self);
253 void InitializeIPDFiedls(IPDFields *self); */
254 BindInfoClass *ARD_AllocBookmark(ARDFields *self);
255 void ARD_unbind_cols(ARDFields *self, BOOL freeall);
256 void APD_free_params(APDFields *self, char option);
257 void IPD_free_params(IPDFields *self, char option);
258 BOOL getCOLIfromTI(const char *, ConnectionClass *, StatementClass *, const OID, TABLE_INFO **);
259 RETCODE DC_set_stmt(DescriptorClass *desc, StatementClass *stmt);
260 void DC_clear_error(DescriptorClass *desc);
261 void DC_set_error(DescriptorClass *desc, int errornumber, const char * errormsg);
262 void DC_set_errormsg(DescriptorClass *desc, const char * errormsg);
263 PG_ErrorInfo *DC_get_error(DescriptorClass *self);
264 int DC_get_errornumber(const DescriptorClass *self);
265 const char *DC_get_errormsg(const DescriptorClass *self);
266 void DC_log_error(const char *func, const char *desc, const DescriptorClass *self);
268 /* Error numbers about descriptor handle */
269 enum {
270 LOWEST_DESC_ERROR = -2
271 /* minus means warning/notice message */
272 ,DESC_ERROR_IN_ROW = -2
273 ,DESC_OPTION_VALUE_CHANGED = -1
274 ,DESC_OK = 0
275 ,DESC_EXEC_ERROR
276 ,DESC_STATUS_ERROR
277 ,DESC_SEQUENCE_ERROR
278 ,DESC_NO_MEMORY_ERROR
279 ,DESC_COLNUM_ERROR
280 ,DESC_NO_STMTSTRING
281 ,DESC_ERROR_TAKEN_FROM_BACKEND
282 ,DESC_INTERNAL_ERROR
283 ,DESC_STILL_EXECUTING
284 ,DESC_NOT_IMPLEMENTED_ERROR
285 ,DESC_BAD_PARAMETER_NUMBER_ERROR
286 ,DESC_OPTION_OUT_OF_RANGE_ERROR
287 ,DESC_INVALID_COLUMN_NUMBER_ERROR
288 ,DESC_RESTRICTED_DATA_TYPE_ERROR
289 ,DESC_INVALID_CURSOR_STATE_ERROR
290 ,DESC_CREATE_TABLE_ERROR
291 ,DESC_NO_CURSOR_NAME
292 ,DESC_INVALID_CURSOR_NAME
293 ,DESC_INVALID_ARGUMENT_NO
294 ,DESC_ROW_OUT_OF_RANGE
295 ,DESC_OPERATION_CANCELLED
296 ,DESC_INVALID_CURSOR_POSITION
297 ,DESC_VALUE_OUT_OF_RANGE
298 ,DESC_OPERATION_INVALID
299 ,DESC_PROGRAM_TYPE_OUT_OF_RANGE
300 ,DESC_BAD_ERROR
301 ,DESC_INVALID_OPTION_IDENTIFIER
302 ,DESC_RETURN_NULL_WITHOUT_INDICATOR
303 ,DESC_INVALID_DESCRIPTOR_IDENTIFIER
304 ,DESC_OPTION_NOT_FOR_THE_DRIVER
305 ,DESC_FETCH_OUT_OF_RANGE
306 ,DESC_COUNT_FIELD_INCORRECT
308 #endif /* __DESCRIPTOR_H__ */