FIXME: toplevel Makefile: 'make ntest' doesn't run versaplexd for now.
[versaplex.git] / vxodbc / info30.cc
bloba1c09c31c37047ea8a7d91a87b4eda768752531e
1 /*
2 * Description: This module contains routines related to ODBC 3.0
3 * SQLGetInfo().
4 */
6 #include "psqlodbc.h"
7 #include "misc.h"
9 #include "connection.h"
10 #include "pgapifunc.h"
12 RETCODE SQL_API
13 PGAPI_GetInfo30(HDBC hdbc, SQLUSMALLINT fInfoType, PTR rgbInfoValue,
14 SQLSMALLINT cbInfoValueMax,
15 SQLSMALLINT FAR * pcbInfoValue)
17 CSTR func = "PGAPI_GetInfo30";
18 ConnectionClass *conn = (ConnectionClass *) hdbc;
19 ConnInfo *ci = &(conn->connInfo);
20 const char *p = NULL;
21 ssize_t len = 0;
22 SQLLEN value = 0;
23 RETCODE result;
25 switch (fInfoType)
27 case SQL_DYNAMIC_CURSOR_ATTRIBUTES1:
28 len = 4;
29 value = 0;
30 break;
31 case SQL_DYNAMIC_CURSOR_ATTRIBUTES2:
32 len = 4;
33 value = 0;
34 break;
36 case SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES1:
37 len = 4;
38 value = SQL_CA1_NEXT; /* others aren't allowed in ODBC spec */
39 break;
40 case SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2:
41 len = 4;
42 value = SQL_CA2_READ_ONLY_CONCURRENCY;
43 value |= SQL_CA2_CRC_EXACT;
44 break;
45 case SQL_KEYSET_CURSOR_ATTRIBUTES1:
46 len = 4;
47 value = SQL_CA1_NEXT | SQL_CA1_ABSOLUTE
48 | SQL_CA1_RELATIVE | SQL_CA1_BOOKMARK
49 | SQL_CA1_LOCK_NO_CHANGE | SQL_CA1_POS_POSITION
50 | SQL_CA1_POS_REFRESH;
51 if (0 != (ci->updatable_cursors & ALLOW_KEYSET_DRIVEN_CURSORS))
52 value |= (SQL_CA1_POS_UPDATE | SQL_CA1_POS_DELETE
53 | SQL_CA1_BULK_ADD
54 | SQL_CA1_BULK_UPDATE_BY_BOOKMARK
55 | SQL_CA1_BULK_DELETE_BY_BOOKMARK
56 | SQL_CA1_BULK_FETCH_BY_BOOKMARK);
57 break;
58 case SQL_KEYSET_CURSOR_ATTRIBUTES2:
59 len = 4;
60 value = SQL_CA2_READ_ONLY_CONCURRENCY;
61 if (0 != (ci->updatable_cursors & ALLOW_KEYSET_DRIVEN_CURSORS))
62 value |= (SQL_CA2_OPT_ROWVER_CONCURRENCY
63 /*| SQL_CA2_CRC_APPROXIMATE */
65 if (0 != (ci->updatable_cursors & SENSE_SELF_OPERATIONS))
66 value |= (SQL_CA2_SENSITIVITY_DELETIONS
67 | SQL_CA2_SENSITIVITY_UPDATES
68 | SQL_CA2_SENSITIVITY_ADDITIONS);
69 value |= SQL_CA2_CRC_EXACT;
70 break;
72 case SQL_STATIC_CURSOR_ATTRIBUTES1:
73 len = 4;
74 value = SQL_CA1_NEXT | SQL_CA1_ABSOLUTE
75 | SQL_CA1_RELATIVE | SQL_CA1_BOOKMARK
76 | SQL_CA1_LOCK_NO_CHANGE | SQL_CA1_POS_POSITION
77 | SQL_CA1_POS_REFRESH;
78 if (0 != (ci->updatable_cursors & ALLOW_STATIC_CURSORS))
79 value |= (SQL_CA1_POS_UPDATE | SQL_CA1_POS_DELETE);
80 if (0 != (ci->updatable_cursors & ALLOW_BULK_OPERATIONS))
81 value |= (SQL_CA1_BULK_ADD
82 | SQL_CA1_BULK_UPDATE_BY_BOOKMARK
83 | SQL_CA1_BULK_DELETE_BY_BOOKMARK
84 | SQL_CA1_BULK_FETCH_BY_BOOKMARK);
85 break;
86 case SQL_STATIC_CURSOR_ATTRIBUTES2:
87 len = 4;
88 value = SQL_CA2_READ_ONLY_CONCURRENCY;
89 if (0 != (ci->updatable_cursors & ALLOW_STATIC_CURSORS))
90 value |= (SQL_CA2_OPT_ROWVER_CONCURRENCY);
91 if (0 != (ci->updatable_cursors & SENSE_SELF_OPERATIONS))
92 value |= (SQL_CA2_SENSITIVITY_DELETIONS
93 | SQL_CA2_SENSITIVITY_UPDATES
94 | SQL_CA2_SENSITIVITY_ADDITIONS);
95 value |= (SQL_CA2_CRC_EXACT);
96 break;
98 case SQL_ODBC_INTERFACE_CONFORMANCE:
99 len = 4;
100 value = SQL_OIC_CORE;
101 break;
102 case SQL_ACTIVE_ENVIRONMENTS:
103 len = 2;
104 value = 0;
105 break;
106 case SQL_AGGREGATE_FUNCTIONS:
107 len = 4;
108 value = SQL_AF_ALL;
109 break;
110 case SQL_ALTER_DOMAIN:
111 len = 4;
112 value = 0;
113 break;
114 case SQL_ASYNC_MODE:
115 len = 4;
116 value = SQL_AM_NONE;
117 break;
118 case SQL_BATCH_ROW_COUNT:
119 len = 4;
120 value = SQL_BRC_EXPLICIT;
121 break;
122 case SQL_BATCH_SUPPORT:
123 len = 4;
124 value = SQL_BS_SELECT_EXPLICIT | SQL_BS_ROW_COUNT_EXPLICIT;
125 break;
126 case SQL_CATALOG_NAME:
127 len = 0;
128 if (CurrCat(conn))
129 p = "Y";
130 else
131 p = "N";
132 break;
133 case SQL_COLLATION_SEQ:
134 len = 0;
135 p = "";
136 break;
137 case SQL_CREATE_ASSERTION:
138 len = 4;
139 value = 0;
140 break;
141 case SQL_CREATE_CHARACTER_SET:
142 len = 4;
143 value = 0;
144 break;
145 case SQL_CREATE_COLLATION:
146 len = 4;
147 value = 0;
148 break;
149 case SQL_CREATE_DOMAIN:
150 len = 4;
151 value = 0;
152 break;
153 case SQL_CREATE_SCHEMA:
154 len = 4;
155 if (conn->schema_support)
156 value = SQL_CS_CREATE_SCHEMA | SQL_CS_AUTHORIZATION;
157 else
158 value = 0;
159 break;
160 case SQL_CREATE_TABLE:
161 len = 4;
162 value = SQL_CT_CREATE_TABLE | SQL_CT_COLUMN_CONSTRAINT
163 | SQL_CT_COLUMN_DEFAULT;
164 if (PG_VERSION_GE(conn, 6.5))
165 value |= SQL_CT_GLOBAL_TEMPORARY;
166 if (PG_VERSION_GE(conn, 7.0))
167 value |= SQL_CT_TABLE_CONSTRAINT
168 | SQL_CT_CONSTRAINT_NAME_DEFINITION
169 | SQL_CT_CONSTRAINT_INITIALLY_DEFERRED
170 | SQL_CT_CONSTRAINT_INITIALLY_IMMEDIATE
171 | SQL_CT_CONSTRAINT_DEFERRABLE;
172 break;
173 case SQL_CREATE_TRANSLATION:
174 len = 4;
175 value = 0;
176 break;
177 case SQL_CREATE_VIEW:
178 len = 4;
179 value = SQL_CV_CREATE_VIEW;
180 break;
181 case SQL_DDL_INDEX:
182 len = 4;
183 value = SQL_DI_CREATE_INDEX | SQL_DI_DROP_INDEX;
184 break;
185 case SQL_DESCRIBE_PARAMETER:
186 len = 0;
187 p = "N";
188 break;
189 case SQL_DROP_ASSERTION:
190 len = 4;
191 value = 0;
192 break;
193 case SQL_DROP_CHARACTER_SET:
194 len = 4;
195 value = 0;
196 break;
197 case SQL_DROP_COLLATION:
198 len = 4;
199 value = 0;
200 break;
201 case SQL_DROP_DOMAIN:
202 len = 4;
203 value = 0;
204 break;
205 case SQL_DROP_SCHEMA:
206 len = 4;
207 if (conn->schema_support)
208 value =
209 SQL_DS_DROP_SCHEMA | SQL_DS_RESTRICT | SQL_DS_CASCADE;
210 else
211 value = 0;
212 break;
213 case SQL_DROP_TABLE:
214 len = 4;
215 value = SQL_DT_DROP_TABLE;
216 if (PG_VERSION_GT(conn, 7.2)) /* hopefully */
217 value |= (SQL_DT_RESTRICT | SQL_DT_CASCADE);
218 break;
219 case SQL_DROP_TRANSLATION:
220 len = 4;
221 value = 0;
222 break;
223 case SQL_DROP_VIEW:
224 len = 4;
225 value = SQL_DV_DROP_VIEW;
226 if (PG_VERSION_GT(conn, 7.2)) /* hopefully */
227 value |= (SQL_DV_RESTRICT | SQL_DV_CASCADE);
228 break;
229 case SQL_INDEX_KEYWORDS:
230 len = 4;
231 value = SQL_IK_NONE;
232 case SQL_INFO_SCHEMA_VIEWS:
233 len = 4;
234 value = 0;
235 break;
236 case SQL_INSERT_STATEMENT:
237 len = 4;
238 value =
239 SQL_IS_INSERT_LITERALS | SQL_IS_INSERT_SEARCHED |
240 SQL_IS_SELECT_INTO;
241 break;
242 case SQL_MAX_IDENTIFIER_LEN:
243 len = 2;
244 value = 32;
245 if (PG_VERSION_GT(conn, 7.2))
246 value = 64;
247 break;
248 case SQL_MAX_ROW_SIZE_INCLUDES_LONG:
249 len = 0;
250 p = "Y";
251 break;
252 case SQL_PARAM_ARRAY_ROW_COUNTS:
253 len = 4;
254 value = SQL_PARC_BATCH;
255 break;
256 case SQL_PARAM_ARRAY_SELECTS:
257 len = 4;
258 value = SQL_PAS_BATCH;
259 break;
260 case SQL_SQL_CONFORMANCE:
261 len = 4;
262 value = SQL_SC_SQL92_ENTRY;
263 break;
264 case SQL_SQL92_DATETIME_FUNCTIONS:
265 len = 4;
266 value =
267 SQL_SDF_CURRENT_DATE | SQL_SDF_CURRENT_TIME |
268 SQL_SDF_CURRENT_TIMESTAMP;
269 break;
270 case SQL_SQL92_FOREIGN_KEY_DELETE_RULE:
271 len = 4;
272 value =
273 SQL_SFKD_CASCADE | SQL_SFKD_NO_ACTION | SQL_SFKD_SET_DEFAULT
274 | SQL_SFKD_SET_NULL;
275 break;
276 case SQL_SQL92_FOREIGN_KEY_UPDATE_RULE:
277 len = 4;
278 value =
279 SQL_SFKU_CASCADE | SQL_SFKU_NO_ACTION | SQL_SFKU_SET_DEFAULT
280 | SQL_SFKU_SET_NULL;
281 break;
282 case SQL_SQL92_GRANT:
283 len = 4;
284 value =
285 SQL_SG_DELETE_TABLE | SQL_SG_INSERT_TABLE |
286 SQL_SG_REFERENCES_TABLE | SQL_SG_SELECT_TABLE |
287 SQL_SG_UPDATE_TABLE;
288 break;
289 case SQL_SQL92_NUMERIC_VALUE_FUNCTIONS:
290 len = 4;
291 value = SQL_SNVF_BIT_LENGTH | SQL_SNVF_CHAR_LENGTH
292 | SQL_SNVF_CHARACTER_LENGTH | SQL_SNVF_EXTRACT
293 | SQL_SNVF_OCTET_LENGTH | SQL_SNVF_POSITION;
294 break;
295 case SQL_SQL92_PREDICATES:
296 len = 4;
297 value = SQL_SP_BETWEEN | SQL_SP_COMPARISON
298 | SQL_SP_EXISTS | SQL_SP_IN
299 | SQL_SP_ISNOTNULL | SQL_SP_ISNULL
300 | SQL_SP_LIKE | SQL_SP_OVERLAPS
301 | SQL_SP_QUANTIFIED_COMPARISON;
302 break;
303 case SQL_SQL92_RELATIONAL_JOIN_OPERATORS:
304 len = 4;
305 if (PG_VERSION_GE(conn, 7.1))
306 value = SQL_SRJO_CROSS_JOIN | SQL_SRJO_EXCEPT_JOIN
307 | SQL_SRJO_FULL_OUTER_JOIN | SQL_SRJO_INNER_JOIN
308 | SQL_SRJO_INTERSECT_JOIN | SQL_SRJO_LEFT_OUTER_JOIN
309 | SQL_SRJO_NATURAL_JOIN | SQL_SRJO_RIGHT_OUTER_JOIN
310 | SQL_SRJO_UNION_JOIN;
311 break;
312 case SQL_SQL92_REVOKE:
313 len = 4;
314 value =
315 SQL_SR_DELETE_TABLE | SQL_SR_INSERT_TABLE |
316 SQL_SR_REFERENCES_TABLE | SQL_SR_SELECT_TABLE |
317 SQL_SR_UPDATE_TABLE;
318 break;
319 case SQL_SQL92_ROW_VALUE_CONSTRUCTOR:
320 len = 4;
321 value = SQL_SRVC_VALUE_EXPRESSION | SQL_SRVC_NULL;
322 break;
323 case SQL_SQL92_STRING_FUNCTIONS:
324 len = 4;
325 value = SQL_SSF_CONVERT | SQL_SSF_LOWER
326 | SQL_SSF_UPPER | SQL_SSF_SUBSTRING
327 | SQL_SSF_TRANSLATE | SQL_SSF_TRIM_BOTH
328 | SQL_SSF_TRIM_LEADING | SQL_SSF_TRIM_TRAILING;
329 break;
330 case SQL_SQL92_VALUE_EXPRESSIONS:
331 len = 4;
332 value =
333 SQL_SVE_CASE | SQL_SVE_CAST | SQL_SVE_COALESCE |
334 SQL_SVE_NULLIF;
335 break;
336 #ifdef SQL_DTC_TRANSACTION_COST
337 case SQL_DTC_TRANSACTION_COST:
338 #else
339 case 1750:
340 #endif
341 len = 4;
342 break;
343 /* The followings aren't implemented yet */
344 case SQL_DATETIME_LITERALS:
345 len = 4;
346 case SQL_DM_VER:
347 len = 0;
348 case SQL_DRIVER_HDESC:
349 len = 4;
350 case SQL_MAX_ASYNC_CONCURRENT_STATEMENTS:
351 len = 4;
352 case SQL_STANDARD_CLI_CONFORMANCE:
353 len = 4;
354 case SQL_XOPEN_CLI_YEAR:
355 len = 0;
356 default:
357 /* unrecognized key */
358 CC_set_error(conn, CONN_NOT_IMPLEMENTED_ERROR,
359 "Unrecognized key passed to SQLGetInfo30.", func);
360 return SQL_ERROR;
362 result = SQL_SUCCESS;
363 mylog("%s: p='%s', len=%d, value=%d, cbMax=%d\n", func,
364 p ? p : "<NULL>", len, value, cbInfoValueMax);
365 if (p)
367 /* char/binary data */
368 len = strlen(p);
370 if (rgbInfoValue)
372 #ifdef UNICODE_SUPPORT
373 if (CC_is_in_unicode_driver(conn))
375 len =
376 utf8_to_ucs2(p, len, (SQLWCHAR *) rgbInfoValue,
377 cbInfoValueMax / WCLEN);
378 len *= WCLEN;
379 } else
380 #endif /* UNICODE_SUPPORT */
381 strncpy_null((char *) rgbInfoValue, p,
382 (size_t) cbInfoValueMax);
384 if (len >= cbInfoValueMax)
386 result = SQL_SUCCESS_WITH_INFO;
387 CC_set_error(conn, CONN_TRUNCATED,
388 "The buffer was too small for tthe InfoValue.",
389 func);
392 #ifdef UNICODE_SUPPORT
393 else if (CC_is_in_unicode_driver(conn))
394 len *= WCLEN;
395 #endif /* UNICODE_SUPPORT */
396 } else
398 /* numeric data */
399 if (rgbInfoValue)
401 if (len == 2)
402 *((WORD *) rgbInfoValue) = (WORD) value;
403 else if (len == 4)
404 *((DWORD *) rgbInfoValue) = (DWORD) value;
408 if (pcbInfoValue)
409 *pcbInfoValue = (SQLSMALLINT) len;
410 return result;