Merge commit 'origin/master'
[versaplex.git] / vxodbc / odbcapiw.cc
blobad9484de99ff034213c6707c4c392b74435346d6
1 /*
2 * Description: This module contains UNICODE routines
3 */
5 #include "psqlodbc.h"
6 #include <stdio.h>
7 #include <string.h>
9 #include "pgapifunc.h"
10 #include "connection.h"
11 #include "statement.h"
13 RETCODE SQL_API SQLColumnsW(HSTMT StatementHandle,
14 SQLWCHAR * CatalogName,
15 SQLSMALLINT NameLength1,
16 SQLWCHAR * SchemaName,
17 SQLSMALLINT NameLength2,
18 SQLWCHAR * TableName,
19 SQLSMALLINT NameLength3,
20 SQLWCHAR * ColumnName,
21 SQLSMALLINT NameLength4)
23 CSTR func = "SQLColumnsW";
24 RETCODE ret;
25 char *ctName, *scName, *tbName, *clName;
26 SQLLEN nmlen1, nmlen2, nmlen3, nmlen4;
27 StatementClass *stmt = (StatementClass *) StatementHandle;
28 ConnectionClass *conn;
29 BOOL lower_id;
30 UWORD flag = PODBC_SEARCH_PUBLIC_SCHEMA;
31 mylog("Start\n");
33 conn = SC_get_conn(stmt);
34 lower_id = SC_is_lower_case(stmt, conn);
35 ctName = ucs2_to_utf8(CatalogName, NameLength1, &nmlen1, lower_id);
36 scName = ucs2_to_utf8(SchemaName, NameLength2, &nmlen2, lower_id);
37 tbName = ucs2_to_utf8(TableName, NameLength3, &nmlen3, lower_id);
38 clName = ucs2_to_utf8(ColumnName, NameLength4, &nmlen4, lower_id);
39 mylog("Params: '%s' '%s' '%s' '%s'\n", ctName, scName, tbName, clName);
40 ENTER_STMT_CS(stmt);
41 SC_clear_error(stmt);
42 StartRollbackState(stmt);
43 if (stmt->options.metadata_id)
44 flag |= PODBC_NOT_SEARCH_PATTERN;
45 if (SC_opencheck(stmt, func))
46 ret = SQL_ERROR;
47 else
48 ret =
49 PGAPI_Columns(StatementHandle,
50 (const UCHAR *)ctName, (SQLSMALLINT) nmlen1,
51 (const UCHAR *)scName, (SQLSMALLINT) nmlen2,
52 (const UCHAR *)tbName, (SQLSMALLINT) nmlen3,
53 (const UCHAR *)clName, (SQLSMALLINT) nmlen4,
54 flag, 0, 0);
55 ret = DiscardStatementSvp(stmt, ret, FALSE);
56 LEAVE_STMT_CS(stmt);
57 if (ctName)
58 free(ctName);
59 if (scName)
60 free(scName);
61 if (tbName)
62 free(tbName);
63 if (clName)
64 free(clName);
65 return ret;
69 RETCODE SQL_API SQLConnectW(HDBC ConnectionHandle,
70 SQLWCHAR * ServerName,
71 SQLSMALLINT NameLength1,
72 SQLWCHAR * UserName,
73 SQLSMALLINT NameLength2,
74 SQLWCHAR * Authentication,
75 SQLSMALLINT NameLength3)
77 char *svName, *usName, *auth;
78 SQLLEN nmlen1, nmlen2, nmlen3;
79 RETCODE ret;
80 ConnectionClass *conn = (ConnectionClass *) ConnectionHandle;
81 mylog("Start\n");
83 ENTER_CONN_CS(conn);
84 CC_clear_error(conn);
85 CC_set_in_unicode_driver(conn);
86 svName = ucs2_to_utf8(ServerName, NameLength1, &nmlen1, FALSE);
87 usName = ucs2_to_utf8(UserName, NameLength2, &nmlen2, FALSE);
88 auth = ucs2_to_utf8(Authentication, NameLength3, &nmlen3, FALSE);
89 ret = PGAPI_Connect(ConnectionHandle,
90 (const UCHAR *)svName, (SQLSMALLINT) nmlen1,
91 (const UCHAR *)usName, (SQLSMALLINT) nmlen2,
92 (const UCHAR *)auth, (SQLSMALLINT) nmlen3);
93 LEAVE_CONN_CS(conn);
94 if (svName)
95 free(svName);
96 if (usName)
97 free(usName);
98 if (auth)
99 free(auth);
100 return ret;
103 RETCODE SQL_API SQLDriverConnectW(HDBC hdbc,
104 HWND hwnd,
105 SQLWCHAR * szConnStrIn,
106 SQLSMALLINT cbConnStrIn,
107 SQLWCHAR * szConnStrOut,
108 SQLSMALLINT cbConnStrOutMax,
109 SQLSMALLINT FAR * pcbConnStrOut,
110 SQLUSMALLINT fDriverCompletion)
112 CSTR func = "SQLDriverConnectW";
113 char *szIn, *szOut = NULL;
114 SQLSMALLINT maxlen, obuflen = 0;
115 SQLLEN inlen;
116 SQLSMALLINT olen, *pCSO;
117 RETCODE ret;
118 ConnectionClass *conn = (ConnectionClass *) hdbc;
119 mylog("Start\n");
121 ENTER_CONN_CS(conn);
122 CC_clear_error(conn);
123 CC_set_in_unicode_driver(conn);
124 szIn = ucs2_to_utf8(szConnStrIn, cbConnStrIn, &inlen, FALSE);
125 maxlen = cbConnStrOutMax;
126 pCSO = NULL;
127 olen = 0;
128 if (maxlen > 0)
130 obuflen = maxlen + 1;
131 szOut = (char *)malloc(obuflen);
132 pCSO = &olen;
133 } else if (pcbConnStrOut)
134 pCSO = &olen;
135 ret = PGAPI_DriverConnect(hdbc, hwnd,
136 (const UCHAR *)szIn, (SQLSMALLINT) inlen,
137 (UCHAR *)szOut, maxlen,
138 pCSO, fDriverCompletion);
139 if (ret != SQL_ERROR && NULL != pCSO)
141 SQLLEN outlen = olen;
143 if (olen < obuflen)
144 outlen =
145 utf8_to_ucs2(szOut, olen, szConnStrOut,
146 cbConnStrOutMax);
147 else
148 utf8_to_ucs2(szOut, maxlen, szConnStrOut, cbConnStrOutMax);
149 if (outlen >= cbConnStrOutMax)
151 inolog("cbConnstrOutMax=%d pcb=%p\n", cbConnStrOutMax,
152 pcbConnStrOut);
153 if (SQL_SUCCESS == ret)
155 CC_set_error(conn, CONN_TRUNCATED,
156 "the ConnStrOut is too small", func);
157 ret = SQL_SUCCESS_WITH_INFO;
160 if (pcbConnStrOut)
161 *pcbConnStrOut = (SQLSMALLINT) outlen;
163 LEAVE_CONN_CS(conn);
164 if (szOut)
165 free(szOut);
166 if (szIn)
167 free(szIn);
168 return ret;
170 RETCODE SQL_API SQLBrowseConnectW(HDBC hdbc,
171 SQLWCHAR * szConnStrIn,
172 SQLSMALLINT cbConnStrIn,
173 SQLWCHAR * szConnStrOut,
174 SQLSMALLINT cbConnStrOutMax,
175 SQLSMALLINT * pcbConnStrOut)
177 char *szIn, *szOut;
178 SQLLEN inlen;
179 SQLUSMALLINT obuflen;
180 SQLSMALLINT olen;
181 RETCODE ret;
182 ConnectionClass *conn = (ConnectionClass *) hdbc;
183 mylog("Start\n");
185 ENTER_CONN_CS(conn);
186 CC_clear_error(conn);
187 CC_set_in_unicode_driver(conn);
188 szIn = ucs2_to_utf8(szConnStrIn, cbConnStrIn, &inlen, FALSE);
189 obuflen = cbConnStrOutMax + 1;
190 szOut = (char *)malloc(obuflen);
191 ret = PGAPI_BrowseConnect(hdbc,
192 (const UCHAR *)szIn, (SQLSMALLINT)inlen,
193 (UCHAR *)szOut, cbConnStrOutMax, &olen);
194 LEAVE_CONN_CS(conn);
195 if (ret != SQL_ERROR)
197 SQLLEN outlen =
198 utf8_to_ucs2(szOut, olen, szConnStrOut, cbConnStrOutMax);
199 if (pcbConnStrOut)
200 *pcbConnStrOut = (SQLSMALLINT) outlen;
202 free(szOut);
203 if (szIn)
204 free(szIn);
205 return ret;
208 RETCODE SQL_API SQLDataSourcesW(HENV EnvironmentHandle,
209 SQLUSMALLINT Direction,
210 SQLWCHAR * ServerName,
211 SQLSMALLINT BufferLength1,
212 SQLSMALLINT * NameLength1,
213 SQLWCHAR * Description,
214 SQLSMALLINT BufferLength2,
215 SQLSMALLINT * NameLength2)
217 mylog("Start\n");
219 return PGAPI_DataSources(EnvironmentHandle, Direction, ServerName,
220 BufferLength1, NameLength1, Description, BufferLength2,
221 NameLength2);
223 return SQL_ERROR;
226 RETCODE SQL_API SQLDescribeColW(HSTMT StatementHandle,
227 SQLUSMALLINT ColumnNumber,
228 SQLWCHAR * ColumnName,
229 SQLSMALLINT BufferLength,
230 SQLSMALLINT * NameLength,
231 SQLSMALLINT * DataType,
232 SQLULEN * ColumnSize,
233 SQLSMALLINT * DecimalDigits,
234 SQLSMALLINT * Nullable)
236 CSTR func = "SQLDescribeColW";
237 RETCODE ret;
238 StatementClass *stmt = (StatementClass *) StatementHandle;
239 SQLSMALLINT buflen, nmlen;
240 char *clName = NULL;
241 mylog("Start\n");
243 buflen = 0;
244 if (BufferLength > 0)
245 buflen = BufferLength * 3;
246 else if (NameLength)
247 buflen = 32;
248 if (buflen > 0)
249 clName = (char *)malloc(buflen);
250 ENTER_STMT_CS(stmt);
251 SC_clear_error(stmt);
252 StartRollbackState(stmt);
253 for (;; buflen = nmlen + 1, clName = (char *)realloc(clName, buflen))
255 ret = PGAPI_DescribeCol(StatementHandle, ColumnNumber,
256 (UCHAR *)clName, buflen, &nmlen, DataType,
257 ColumnSize, DecimalDigits, Nullable);
258 if (SQL_SUCCESS_WITH_INFO != ret || nmlen < buflen)
259 break;
261 if (SQL_SUCCEEDED(ret))
263 SQLLEN nmcount = nmlen;
265 if (nmlen < buflen)
266 nmcount =
267 utf8_to_ucs2(clName, nmlen, ColumnName, BufferLength);
268 if (SQL_SUCCESS == ret && BufferLength > 0
269 && nmcount > BufferLength)
271 ret = SQL_SUCCESS_WITH_INFO;
272 SC_set_error(stmt, STMT_TRUNCATED, "Column name too large",
273 func);
275 if (NameLength)
276 *NameLength = (SQLSMALLINT) nmcount;
278 ret = DiscardStatementSvp(stmt, ret, FALSE);
279 LEAVE_STMT_CS(stmt);
280 if (clName)
281 free(clName);
282 return ret;
285 RETCODE SQL_API SQLExecDirectW(HSTMT StatementHandle,
286 SQLWCHAR * StatementText,
287 SQLINTEGER TextLength)
289 CSTR func = "SQLExecDirectW";
290 RETCODE ret;
291 char *stxt;
292 SQLLEN slen;
293 StatementClass *stmt = (StatementClass *) StatementHandle;
294 UWORD flag = 0;
295 mylog("Start\n");
297 stxt = ucs2_to_utf8(StatementText, TextLength, &slen, FALSE);
298 ENTER_STMT_CS(stmt);
299 SC_clear_error(stmt);
300 if (PG_VERSION_GE(SC_get_conn(stmt), 7.4))
301 flag |= PODBC_WITH_HOLD;
302 StartRollbackState(stmt);
303 if (SC_opencheck(stmt, func))
304 ret = SQL_ERROR;
305 else
306 ret =
307 PGAPI_ExecDirect_Vx(StatementHandle,
308 (const UCHAR *)stxt, (SQLINTEGER)slen,
309 flag);
310 ret = DiscardStatementSvp(stmt, ret, FALSE);
311 LEAVE_STMT_CS(stmt);
312 if (stxt)
313 free(stxt);
314 return ret;
317 RETCODE SQL_API SQLGetCursorNameW(HSTMT StatementHandle,
318 SQLWCHAR * CursorName,
319 SQLSMALLINT BufferLength,
320 SQLSMALLINT * NameLength)
322 CSTR func = "SQLGetCursorNameW";
323 RETCODE ret;
324 StatementClass *stmt = (StatementClass *) StatementHandle;
325 char *crName;
326 SQLSMALLINT clen, buflen;
327 mylog("Start\n");
329 if (BufferLength > 0)
330 buflen = BufferLength * 3;
331 else
332 buflen = 32;
333 crName = (char *)malloc(buflen);
334 ENTER_STMT_CS(stmt);
335 SC_clear_error(stmt);
336 StartRollbackState(stmt);
337 for (;; buflen = clen + 1, crName = (char *)realloc(crName, buflen))
339 ret =
340 PGAPI_GetCursorName(StatementHandle,
341 (UCHAR *)crName, buflen, &clen);
342 if (SQL_SUCCESS_WITH_INFO != ret || clen < buflen)
343 break;
345 if (SQL_SUCCEEDED(ret))
347 SQLLEN nmcount = clen;
349 if (clen < buflen)
350 nmcount =
351 utf8_to_ucs2(crName, clen, CursorName, BufferLength);
352 if (SQL_SUCCESS == ret && nmcount > BufferLength)
354 ret = SQL_SUCCESS_WITH_INFO;
355 SC_set_error(stmt, STMT_TRUNCATED, "Cursor name too large",
356 func);
358 if (NameLength)
359 *NameLength = (SQLSMALLINT) nmcount;
361 ret = DiscardStatementSvp(stmt, ret, FALSE);
362 LEAVE_STMT_CS(stmt);
363 free(crName);
364 return ret;
367 RETCODE SQL_API SQLGetInfoW(HDBC ConnectionHandle,
368 SQLUSMALLINT InfoType, PTR InfoValue,
369 SQLSMALLINT BufferLength,
370 SQLSMALLINT * StringLength)
372 ConnectionClass *conn = (ConnectionClass *) ConnectionHandle;
373 RETCODE ret;
374 mylog("Start\n");
376 ENTER_CONN_CS(conn);
377 CC_set_in_unicode_driver(conn);
378 CC_clear_error(conn);
379 if ((ret = PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue,
380 BufferLength, StringLength)) == SQL_ERROR)
382 if (conn->driver_version >= 0x0300)
384 CC_clear_error(conn);
385 ret = PGAPI_GetInfo30(ConnectionHandle, InfoType, InfoValue,
386 BufferLength, StringLength);
389 if (SQL_ERROR == ret)
390 CC_log_error("SQLGetInfoW(30)", "", conn);
391 LEAVE_CONN_CS(conn);
392 return ret;
395 RETCODE SQL_API SQLPrepareW(HSTMT StatementHandle,
396 SQLWCHAR * StatementText,
397 SQLINTEGER TextLength)
399 StatementClass *stmt = (StatementClass *) StatementHandle;
400 RETCODE ret;
401 char *stxt;
402 SQLLEN slen;
403 mylog("Start\n");
405 stxt = ucs2_to_utf8(StatementText, TextLength, &slen, FALSE);
406 ENTER_STMT_CS(stmt);
407 SC_clear_error(stmt);
408 StartRollbackState(stmt);
409 ret = PGAPI_Prepare(StatementHandle,
410 (const UCHAR *)stxt, (SQLINTEGER)slen);
411 ret = DiscardStatementSvp(stmt, ret, FALSE);
412 LEAVE_STMT_CS(stmt);
413 if (stxt)
414 free(stxt);
415 return ret;
418 RETCODE SQL_API SQLSetCursorNameW(HSTMT StatementHandle,
419 SQLWCHAR * CursorName,
420 SQLSMALLINT NameLength)
422 RETCODE ret;
423 StatementClass *stmt = (StatementClass *) StatementHandle;
424 char *crName;
425 SQLLEN nlen;
426 mylog("Start\n");
428 crName = ucs2_to_utf8(CursorName, NameLength, &nlen, FALSE);
429 ENTER_STMT_CS(stmt);
430 SC_clear_error(stmt);
431 StartRollbackState(stmt);
432 ret =
433 PGAPI_SetCursorName(StatementHandle,
434 (const UCHAR *)crName, (SQLSMALLINT)nlen);
435 ret = DiscardStatementSvp(stmt, ret, FALSE);
436 LEAVE_STMT_CS(stmt);
437 if (crName)
438 free(crName);
439 return ret;
442 RETCODE SQL_API SQLSpecialColumnsW(HSTMT StatementHandle,
443 SQLUSMALLINT IdentifierType,
444 SQLWCHAR * CatalogName,
445 SQLSMALLINT NameLength1,
446 SQLWCHAR * SchemaName,
447 SQLSMALLINT NameLength2,
448 SQLWCHAR * TableName,
449 SQLSMALLINT NameLength3,
450 SQLUSMALLINT Scope,
451 SQLUSMALLINT Nullable)
453 CSTR func = "SQLSpecialColumnsW";
454 RETCODE ret;
455 char *ctName, *scName, *tbName;
456 SQLLEN nmlen1, nmlen2, nmlen3;
457 StatementClass *stmt = (StatementClass *) StatementHandle;
458 ConnectionClass *conn;
459 BOOL lower_id;
460 mylog("Start\n");
462 conn = SC_get_conn(stmt);
463 lower_id = SC_is_lower_case(stmt, conn);
464 ctName = ucs2_to_utf8(CatalogName, NameLength1, &nmlen1, lower_id);
465 scName = ucs2_to_utf8(SchemaName, NameLength2, &nmlen2, lower_id);
466 tbName = ucs2_to_utf8(TableName, NameLength3, &nmlen3, lower_id);
467 ENTER_STMT_CS(stmt);
468 SC_clear_error(stmt);
469 StartRollbackState(stmt);
470 if (SC_opencheck(stmt, func))
471 ret = SQL_ERROR;
472 else
473 ret =
474 PGAPI_SpecialColumns(StatementHandle, IdentifierType,
475 (const UCHAR *)ctName, (SQLSMALLINT)nmlen1,
476 (const UCHAR *)scName, (SQLSMALLINT)nmlen2,
477 (const UCHAR *)tbName, (SQLSMALLINT)nmlen3,
478 Scope, Nullable);
479 ret = DiscardStatementSvp(stmt, ret, FALSE);
480 LEAVE_STMT_CS(stmt);
481 if (ctName)
482 free(ctName);
483 if (scName)
484 free(scName);
485 if (tbName)
486 free(tbName);
487 return ret;
490 RETCODE SQL_API SQLStatisticsW(HSTMT StatementHandle,
491 SQLWCHAR * CatalogName,
492 SQLSMALLINT NameLength1,
493 SQLWCHAR * SchemaName,
494 SQLSMALLINT NameLength2,
495 SQLWCHAR * TableName,
496 SQLSMALLINT NameLength3,
497 SQLUSMALLINT Unique,
498 SQLUSMALLINT Reserved)
500 CSTR func = "SQLStatisticsW";
501 RETCODE ret;
502 char *ctName, *scName, *tbName;
503 SQLLEN nmlen1, nmlen2, nmlen3;
504 StatementClass *stmt = (StatementClass *) StatementHandle;
505 ConnectionClass *conn;
506 BOOL lower_id;
507 mylog("Start\n");
509 conn = SC_get_conn(stmt);
510 lower_id = SC_is_lower_case(stmt, conn);
511 ctName = ucs2_to_utf8(CatalogName, NameLength1, &nmlen1, lower_id);
512 scName = ucs2_to_utf8(SchemaName, NameLength2, &nmlen2, lower_id);
513 tbName = ucs2_to_utf8(TableName, NameLength3, &nmlen3, lower_id);
515 ENTER_STMT_CS(stmt);
516 SC_clear_error(stmt);
517 StartRollbackState(stmt);
518 if (SC_opencheck(stmt, func))
519 ret = SQL_ERROR;
520 else
521 ret =
522 PGAPI_Statistics(StatementHandle,
523 (const UCHAR *)ctName, (SQLSMALLINT)nmlen1,
524 (const UCHAR *)scName, (SQLSMALLINT)nmlen2,
525 (const UCHAR *)tbName, (SQLSMALLINT)nmlen3,
526 Unique, Reserved);
527 ret = DiscardStatementSvp(stmt, ret, FALSE);
528 LEAVE_STMT_CS(stmt);
529 if (ctName)
530 free(ctName);
531 if (scName)
532 free(scName);
533 if (tbName)
534 free(tbName);
535 return ret;
538 RETCODE SQL_API SQLTablesW(HSTMT StatementHandle,
539 SQLWCHAR * CatalogName,
540 SQLSMALLINT NameLength1,
541 SQLWCHAR * SchemaName,
542 SQLSMALLINT NameLength2,
543 SQLWCHAR * TableName,
544 SQLSMALLINT NameLength3,
545 SQLWCHAR * TableType,
546 SQLSMALLINT NameLength4)
548 CSTR func = "SQLTablesW";
549 RETCODE ret;
550 char *ctName, *scName, *tbName, *tbType;
551 SQLLEN nmlen1, nmlen2, nmlen3, nmlen4;
552 StatementClass *stmt = (StatementClass *) StatementHandle;
553 ConnectionClass *conn;
554 BOOL lower_id;
555 UWORD flag = 0;
556 mylog("Start\n");
558 conn = SC_get_conn(stmt);
559 lower_id = SC_is_lower_case(stmt, conn);
560 ctName = ucs2_to_utf8(CatalogName, NameLength1, &nmlen1, lower_id);
561 scName = ucs2_to_utf8(SchemaName, NameLength2, &nmlen2, lower_id);
562 tbName = ucs2_to_utf8(TableName, NameLength3, &nmlen3, lower_id);
563 tbType = ucs2_to_utf8(TableType, NameLength4, &nmlen4, FALSE);
564 ENTER_STMT_CS(stmt);
565 SC_clear_error(stmt);
566 StartRollbackState(stmt);
567 if (stmt->options.metadata_id)
568 flag |= PODBC_NOT_SEARCH_PATTERN;
569 if (SC_opencheck(stmt, func))
570 ret = SQL_ERROR;
571 else
572 ret =
573 PGAPI_Tables(StatementHandle,
574 (const UCHAR *)ctName, (SQLSMALLINT)nmlen1,
575 (const UCHAR *)scName, (SQLSMALLINT)nmlen2,
576 (const UCHAR *)tbName, (SQLSMALLINT)nmlen3,
577 (const UCHAR *)tbType, (SQLSMALLINT) nmlen4, flag);
578 ret = DiscardStatementSvp(stmt, ret, FALSE);
579 LEAVE_STMT_CS(stmt);
580 if (ctName)
581 free(ctName);
582 if (scName)
583 free(scName);
584 if (tbName)
585 free(tbName);
586 if (tbType)
587 free(tbType);
588 return ret;
591 RETCODE SQL_API SQLColumnPrivilegesW(HSTMT hstmt,
592 SQLWCHAR * szCatalogName,
593 SQLSMALLINT cbCatalogName,
594 SQLWCHAR * szSchemaName,
595 SQLSMALLINT cbSchemaName,
596 SQLWCHAR * szTableName,
597 SQLSMALLINT cbTableName,
598 SQLWCHAR * szColumnName,
599 SQLSMALLINT cbColumnName)
601 CSTR func = "SQLColumnPrivilegesW";
602 RETCODE ret;
603 char *ctName, *scName, *tbName, *clName;
604 SQLLEN nmlen1, nmlen2, nmlen3, nmlen4;
605 StatementClass *stmt = (StatementClass *) hstmt;
606 ConnectionClass *conn;
607 BOOL lower_id;
608 UWORD flag = 0;
609 mylog("Start\n");
611 conn = SC_get_conn(stmt);
612 lower_id = SC_is_lower_case(stmt, conn);
613 ctName =
614 ucs2_to_utf8(szCatalogName, cbCatalogName, &nmlen1, lower_id);
615 scName =
616 ucs2_to_utf8(szSchemaName, cbSchemaName, &nmlen2, lower_id);
617 tbName = ucs2_to_utf8(szTableName, cbTableName, &nmlen3, lower_id);
618 clName =
619 ucs2_to_utf8(szColumnName, cbColumnName, &nmlen4, lower_id);
620 ENTER_STMT_CS(stmt);
621 SC_clear_error(stmt);
622 StartRollbackState(stmt);
623 if (stmt->options.metadata_id)
624 flag |= PODBC_NOT_SEARCH_PATTERN;
625 if (SC_opencheck(stmt, func))
626 ret = SQL_ERROR;
627 else
628 ret =
629 PGAPI_ColumnPrivileges(hstmt,
630 (const UCHAR *)ctName, (SQLSMALLINT)nmlen1,
631 (const UCHAR *)scName, (SQLSMALLINT)nmlen2,
632 (const UCHAR *)tbName, (SQLSMALLINT)nmlen3,
633 (const UCHAR *)clName, (SQLSMALLINT)nmlen4, flag);
634 ret = DiscardStatementSvp(stmt, ret, FALSE);
635 LEAVE_STMT_CS(stmt);
636 if (ctName)
637 free(ctName);
638 if (scName)
639 free(scName);
640 if (tbName)
641 free(tbName);
642 if (clName)
643 free(clName);
644 return ret;
647 RETCODE SQL_API SQLForeignKeysW(HSTMT hstmt,
648 SQLWCHAR * szPkCatalogName,
649 SQLSMALLINT cbPkCatalogName,
650 SQLWCHAR * szPkSchemaName,
651 SQLSMALLINT cbPkSchemaName,
652 SQLWCHAR * szPkTableName,
653 SQLSMALLINT cbPkTableName,
654 SQLWCHAR * szFkCatalogName,
655 SQLSMALLINT cbFkCatalogName,
656 SQLWCHAR * szFkSchemaName,
657 SQLSMALLINT cbFkSchemaName,
658 SQLWCHAR * szFkTableName,
659 SQLSMALLINT cbFkTableName)
661 CSTR func = "SQLForeignKeysW";
662 RETCODE ret;
663 char *ctName, *scName, *tbName, *fkctName, *fkscName, *fktbName;
664 SQLLEN nmlen1, nmlen2, nmlen3, nmlen4, nmlen5, nmlen6;
665 StatementClass *stmt = (StatementClass *) hstmt;
666 ConnectionClass *conn;
667 BOOL lower_id;
668 mylog("Start\n");
670 conn = SC_get_conn(stmt);
671 lower_id = SC_is_lower_case(stmt, conn);
672 ctName =
673 ucs2_to_utf8(szPkCatalogName, cbPkCatalogName, &nmlen1,
674 lower_id);
675 scName =
676 ucs2_to_utf8(szPkSchemaName, cbPkSchemaName, &nmlen2, lower_id);
677 tbName =
678 ucs2_to_utf8(szPkTableName, cbPkTableName, &nmlen3, lower_id);
679 fkctName =
680 ucs2_to_utf8(szFkCatalogName, cbFkCatalogName, &nmlen4,
681 lower_id);
682 fkscName =
683 ucs2_to_utf8(szFkSchemaName, cbFkSchemaName, &nmlen5, lower_id);
684 fktbName =
685 ucs2_to_utf8(szFkTableName, cbFkTableName, &nmlen6, lower_id);
686 ENTER_STMT_CS(stmt);
687 SC_clear_error(stmt);
688 StartRollbackState(stmt);
689 if (SC_opencheck(stmt, func))
690 ret = SQL_ERROR;
691 else
692 ret = PGAPI_ForeignKeys(hstmt,
693 (const UCHAR *)ctName, (SQLSMALLINT)nmlen1,
694 (const UCHAR *)scName, (SQLSMALLINT)nmlen2,
695 (const UCHAR *)tbName, (SQLSMALLINT)nmlen3,
696 (const UCHAR *)fkctName, (SQLSMALLINT)nmlen4,
697 (const UCHAR *)fkscName, (SQLSMALLINT)nmlen5,
698 (const UCHAR *)fktbName, (SQLSMALLINT)nmlen6);
699 ret = DiscardStatementSvp(stmt, ret, FALSE);
700 LEAVE_STMT_CS(stmt);
701 if (ctName)
702 free(ctName);
703 if (scName)
704 free(scName);
705 if (tbName)
706 free(tbName);
707 if (fkctName)
708 free(fkctName);
709 if (fkscName)
710 free(fkscName);
711 if (fktbName)
712 free(fktbName);
713 return ret;
716 RETCODE SQL_API SQLNativeSqlW(HDBC hdbc,
717 SQLWCHAR * szSqlStrIn,
718 SQLINTEGER cbSqlStrIn,
719 SQLWCHAR * szSqlStr,
720 SQLINTEGER cbSqlStrMax,
721 SQLINTEGER * pcbSqlStr)
723 CSTR func = "SQLNativeSqlW";
724 RETCODE ret;
725 char *szIn, *szOut = NULL;
726 SQLLEN slen;
727 SQLINTEGER buflen, olen;
728 ConnectionClass *conn = (ConnectionClass *) hdbc;
729 mylog("Start\n");
731 ENTER_CONN_CS(conn);
732 CC_clear_error(conn);
733 CC_set_in_unicode_driver(conn);
734 szIn = ucs2_to_utf8(szSqlStrIn, cbSqlStrIn, &slen, FALSE);
735 buflen = 3 * cbSqlStrMax;
736 if (buflen > 0)
737 szOut = (char *)malloc(buflen);
738 for (;; buflen = olen + 1, szOut = (char *)realloc(szOut, buflen))
740 ret = PGAPI_NativeSql(hdbc, (const UCHAR *)szIn, (SQLINTEGER)slen,
741 (UCHAR *)szOut, buflen, &olen);
742 if (SQL_SUCCESS_WITH_INFO != ret || olen < buflen)
743 break;
745 if (szIn)
746 free(szIn);
747 if (SQL_SUCCEEDED(ret))
749 SQLLEN szcount = olen;
751 if (olen < buflen)
752 szcount = utf8_to_ucs2(szOut, olen, szSqlStr, cbSqlStrMax);
753 if (SQL_SUCCESS == ret && szcount > cbSqlStrMax)
755 ConnectionClass *conn = (ConnectionClass *) hdbc;
757 ret = SQL_SUCCESS_WITH_INFO;
758 CC_set_error(conn, CONN_TRUNCATED, "Sql string too large",
759 func);
761 if (pcbSqlStr)
762 *pcbSqlStr = (SQLINTEGER) szcount;
764 LEAVE_CONN_CS(conn);
765 free(szOut);
766 return ret;
769 RETCODE SQL_API SQLPrimaryKeysW(HSTMT hstmt,
770 SQLWCHAR * szCatalogName,
771 SQLSMALLINT cbCatalogName,
772 SQLWCHAR * szSchemaName,
773 SQLSMALLINT cbSchemaName,
774 SQLWCHAR * szTableName,
775 SQLSMALLINT cbTableName)
777 CSTR func = "SQLPrimaryKeysW";
778 RETCODE ret;
779 char *ctName, *scName, *tbName;
780 SQLLEN nmlen1, nmlen2, nmlen3;
781 StatementClass *stmt = (StatementClass *) hstmt;
782 ConnectionClass *conn;
783 BOOL lower_id;
784 mylog("Start\n");
786 conn = SC_get_conn(stmt);
787 lower_id = SC_is_lower_case(stmt, conn);
788 ctName =
789 ucs2_to_utf8(szCatalogName, cbCatalogName, &nmlen1, lower_id);
790 scName =
791 ucs2_to_utf8(szSchemaName, cbSchemaName, &nmlen2, lower_id);
792 tbName = ucs2_to_utf8(szTableName, cbTableName, &nmlen3, lower_id);
793 ENTER_STMT_CS(stmt);
794 SC_clear_error(stmt);
795 StartRollbackState(stmt);
796 if (SC_opencheck(stmt, func))
797 ret = SQL_ERROR;
798 else
799 ret = PGAPI_PrimaryKeys(hstmt,
800 (const UCHAR *)ctName, (SQLSMALLINT)nmlen1,
801 (const UCHAR *)scName, (SQLSMALLINT)nmlen2,
802 (const UCHAR *)tbName, (SQLSMALLINT)nmlen3);
803 ret = DiscardStatementSvp(stmt, ret, FALSE);
804 LEAVE_STMT_CS(stmt);
805 if (ctName)
806 free(ctName);
807 if (scName)
808 free(scName);
809 if (tbName)
810 free(tbName);
811 return ret;
814 RETCODE SQL_API SQLProcedureColumnsW(HSTMT hstmt,
815 SQLWCHAR * szCatalogName,
816 SQLSMALLINT cbCatalogName,
817 SQLWCHAR * szSchemaName,
818 SQLSMALLINT cbSchemaName,
819 SQLWCHAR * szProcName,
820 SQLSMALLINT cbProcName,
821 SQLWCHAR * szColumnName,
822 SQLSMALLINT cbColumnName)
824 CSTR func = "SQLProcedureColumnsW";
825 RETCODE ret;
826 char *ctName, *scName, *prName, *clName;
827 SQLLEN nmlen1, nmlen2, nmlen3, nmlen4;
828 StatementClass *stmt = (StatementClass *) hstmt;
829 ConnectionClass *conn;
830 BOOL lower_id;
831 UWORD flag = 0;
832 mylog("Start\n");
834 conn = SC_get_conn(stmt);
835 lower_id = SC_is_lower_case(stmt, conn);
836 ctName =
837 ucs2_to_utf8(szCatalogName, cbCatalogName, &nmlen1, lower_id);
838 scName =
839 ucs2_to_utf8(szSchemaName, cbSchemaName, &nmlen2, lower_id);
840 prName = ucs2_to_utf8(szProcName, cbProcName, &nmlen3, lower_id);
841 clName =
842 ucs2_to_utf8(szColumnName, cbColumnName, &nmlen4, lower_id);
843 ENTER_STMT_CS(stmt);
844 SC_clear_error(stmt);
845 StartRollbackState(stmt);
846 if (stmt->options.metadata_id)
847 flag |= PODBC_NOT_SEARCH_PATTERN;
848 if (SC_opencheck(stmt, func))
849 ret = SQL_ERROR;
850 else
851 ret =
852 PGAPI_ProcedureColumns(hstmt,
853 (const UCHAR *)ctName, (SQLSMALLINT)nmlen1,
854 (const UCHAR *)scName, (SQLSMALLINT)nmlen2,
855 (const UCHAR *)prName, (SQLSMALLINT)nmlen3,
856 (const UCHAR *)clName, (SQLSMALLINT)nmlen4,
857 flag);
858 ret = DiscardStatementSvp(stmt, ret, FALSE);
859 LEAVE_STMT_CS(stmt);
860 if (ctName)
861 free(ctName);
862 if (scName)
863 free(scName);
864 if (prName)
865 free(prName);
866 if (clName)
867 free(clName);
868 return ret;
871 RETCODE SQL_API SQLProceduresW(HSTMT hstmt,
872 SQLWCHAR * szCatalogName,
873 SQLSMALLINT cbCatalogName,
874 SQLWCHAR * szSchemaName,
875 SQLSMALLINT cbSchemaName,
876 SQLWCHAR * szProcName,
877 SQLSMALLINT cbProcName)
879 CSTR func = "SQLProceduresW";
880 RETCODE ret;
881 char *ctName, *scName, *prName;
882 SQLLEN nmlen1, nmlen2, nmlen3;
883 StatementClass *stmt = (StatementClass *) hstmt;
884 ConnectionClass *conn;
885 BOOL lower_id;
886 UWORD flag = 0;
887 mylog("Start\n");
889 conn = SC_get_conn(stmt);
890 lower_id = SC_is_lower_case(stmt, conn);
891 ctName =
892 ucs2_to_utf8(szCatalogName, cbCatalogName, &nmlen1, lower_id);
893 scName =
894 ucs2_to_utf8(szSchemaName, cbSchemaName, &nmlen2, lower_id);
895 prName = ucs2_to_utf8(szProcName, cbProcName, &nmlen3, lower_id);
896 ENTER_STMT_CS(stmt);
897 SC_clear_error(stmt);
898 StartRollbackState(stmt);
899 if (stmt->options.metadata_id)
900 flag |= PODBC_NOT_SEARCH_PATTERN;
901 if (SC_opencheck(stmt, func))
902 ret = SQL_ERROR;
903 else
904 ret = PGAPI_Procedures(hstmt,
905 (const UCHAR *)ctName, (SQLSMALLINT)nmlen1,
906 (const UCHAR *)scName, (SQLSMALLINT)nmlen2,
907 (const UCHAR *)prName, (SQLSMALLINT)nmlen3,
908 flag);
909 ret = DiscardStatementSvp(stmt, ret, FALSE);
910 LEAVE_STMT_CS(stmt);
911 if (ctName)
912 free(ctName);
913 if (scName)
914 free(scName);
915 if (prName)
916 free(prName);
917 return ret;
920 RETCODE SQL_API SQLTablePrivilegesW(HSTMT hstmt,
921 SQLWCHAR * szCatalogName,
922 SQLSMALLINT cbCatalogName,
923 SQLWCHAR * szSchemaName,
924 SQLSMALLINT cbSchemaName,
925 SQLWCHAR * szTableName,
926 SQLSMALLINT cbTableName)
928 CSTR func = "SQLTablePrivilegesW";
929 RETCODE ret;
930 char *ctName, *scName, *tbName;
931 SQLLEN nmlen1, nmlen2, nmlen3;
932 StatementClass *stmt = (StatementClass *) hstmt;
933 ConnectionClass *conn;
934 BOOL lower_id;
935 UWORD flag = 0;
936 mylog("Start\n");
938 conn = SC_get_conn(stmt);
939 lower_id = SC_is_lower_case(stmt, conn);
940 ctName =
941 ucs2_to_utf8(szCatalogName, cbCatalogName, &nmlen1, lower_id);
942 scName =
943 ucs2_to_utf8(szSchemaName, cbSchemaName, &nmlen2, lower_id);
944 tbName = ucs2_to_utf8(szTableName, cbTableName, &nmlen3, lower_id);
945 ENTER_STMT_CS((StatementClass *) hstmt);
946 SC_clear_error(stmt);
947 StartRollbackState(stmt);
948 if (stmt->options.metadata_id)
949 flag |= PODBC_NOT_SEARCH_PATTERN;
950 if (SC_opencheck(stmt, func))
951 ret = SQL_ERROR;
952 else
953 ret = PGAPI_TablePrivileges(hstmt,
954 (const UCHAR *)ctName, (SQLSMALLINT)nmlen1,
955 (const UCHAR *)scName, (SQLSMALLINT)nmlen2,
956 (const UCHAR *)tbName, (SQLSMALLINT)nmlen3,
957 flag);
958 ret = DiscardStatementSvp(stmt, ret, FALSE);
959 LEAVE_STMT_CS((StatementClass *) hstmt);
960 if (ctName)
961 free(ctName);
962 if (scName)
963 free(scName);
964 if (tbName)
965 free(tbName);
966 return ret;
969 RETCODE SQL_API SQLGetTypeInfoW(SQLHSTMT StatementHandle,
970 SQLSMALLINT DataType)
972 mylog("Start\n");
973 CSTR func = "SQLGetTypeInfoW";
974 RETCODE ret;
975 StatementClass *stmt = (StatementClass *) StatementHandle;
977 ENTER_STMT_CS(stmt);
978 SC_clear_error(stmt);
979 StartRollbackState(stmt);
980 if (SC_opencheck(stmt, func))
981 ret = SQL_ERROR;
982 else
983 ret = PGAPI_GetTypeInfo(StatementHandle, DataType);
984 ret = DiscardStatementSvp(stmt, ret, FALSE);
985 LEAVE_STMT_CS(stmt);
986 return ret;