Merge commit 'origin/master'
[versaplex.git] / vxodbc / odbcapiw.cc
blob00c4a4b5029d97599d27424c7d21f140c2d2afbd
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 (%x, %p, %d, %p, %d, %p)\n",
730 hdbc, szSqlStrIn, cbSqlStrIn,
731 szSqlStr, cbSqlStrMax, pcbSqlStr);
733 ENTER_CONN_CS(conn);
734 CC_clear_error(conn);
735 CC_set_in_unicode_driver(conn);
736 szIn = ucs2_to_utf8(szSqlStrIn, cbSqlStrIn, &slen, FALSE);
737 buflen = 3 * cbSqlStrMax;
738 if (buflen > 0)
739 szOut = (char *)malloc(buflen);
740 for (;; buflen = olen + 1, szOut = (char *)realloc(szOut, buflen))
742 ret = PGAPI_NativeSql(hdbc, (const UCHAR *)szIn, (SQLINTEGER)slen,
743 (UCHAR *)szOut, buflen, &olen);
744 if (SQL_SUCCESS_WITH_INFO != ret || olen < buflen)
745 break;
747 if (szIn)
748 free(szIn);
749 if (SQL_SUCCEEDED(ret))
751 SQLLEN szcount = olen;
753 if (olen < buflen)
754 szcount = utf8_to_ucs2(szOut, olen, szSqlStr, cbSqlStrMax);
755 if (SQL_SUCCESS == ret && szcount > cbSqlStrMax)
757 ConnectionClass *conn = (ConnectionClass *) hdbc;
759 ret = SQL_SUCCESS_WITH_INFO;
760 mylog("Sql string too large: %d(%d) > %d\n",
761 szcount, olen, cbSqlStrMax);
762 CC_set_error(conn, CONN_TRUNCATED, "Sql string too large",
763 func);
765 if (pcbSqlStr)
766 *pcbSqlStr = (SQLINTEGER) szcount;
768 LEAVE_CONN_CS(conn);
769 free(szOut);
770 return ret;
773 RETCODE SQL_API SQLPrimaryKeysW(HSTMT hstmt,
774 SQLWCHAR * szCatalogName,
775 SQLSMALLINT cbCatalogName,
776 SQLWCHAR * szSchemaName,
777 SQLSMALLINT cbSchemaName,
778 SQLWCHAR * szTableName,
779 SQLSMALLINT cbTableName)
781 CSTR func = "SQLPrimaryKeysW";
782 RETCODE ret;
783 char *ctName, *scName, *tbName;
784 SQLLEN nmlen1, nmlen2, nmlen3;
785 StatementClass *stmt = (StatementClass *) hstmt;
786 ConnectionClass *conn;
787 BOOL lower_id;
788 mylog("Start\n");
790 conn = SC_get_conn(stmt);
791 lower_id = SC_is_lower_case(stmt, conn);
792 ctName =
793 ucs2_to_utf8(szCatalogName, cbCatalogName, &nmlen1, lower_id);
794 scName =
795 ucs2_to_utf8(szSchemaName, cbSchemaName, &nmlen2, lower_id);
796 tbName = ucs2_to_utf8(szTableName, cbTableName, &nmlen3, lower_id);
797 ENTER_STMT_CS(stmt);
798 SC_clear_error(stmt);
799 StartRollbackState(stmt);
800 if (SC_opencheck(stmt, func))
801 ret = SQL_ERROR;
802 else
803 ret = PGAPI_PrimaryKeys(hstmt,
804 (const UCHAR *)ctName, (SQLSMALLINT)nmlen1,
805 (const UCHAR *)scName, (SQLSMALLINT)nmlen2,
806 (const UCHAR *)tbName, (SQLSMALLINT)nmlen3);
807 ret = DiscardStatementSvp(stmt, ret, FALSE);
808 LEAVE_STMT_CS(stmt);
809 if (ctName)
810 free(ctName);
811 if (scName)
812 free(scName);
813 if (tbName)
814 free(tbName);
815 return ret;
818 RETCODE SQL_API SQLProcedureColumnsW(HSTMT hstmt,
819 SQLWCHAR * szCatalogName,
820 SQLSMALLINT cbCatalogName,
821 SQLWCHAR * szSchemaName,
822 SQLSMALLINT cbSchemaName,
823 SQLWCHAR * szProcName,
824 SQLSMALLINT cbProcName,
825 SQLWCHAR * szColumnName,
826 SQLSMALLINT cbColumnName)
828 CSTR func = "SQLProcedureColumnsW";
829 RETCODE ret;
830 char *ctName, *scName, *prName, *clName;
831 SQLLEN nmlen1, nmlen2, nmlen3, nmlen4;
832 StatementClass *stmt = (StatementClass *) hstmt;
833 ConnectionClass *conn;
834 BOOL lower_id;
835 UWORD flag = 0;
836 mylog("Start\n");
838 conn = SC_get_conn(stmt);
839 lower_id = SC_is_lower_case(stmt, conn);
840 ctName =
841 ucs2_to_utf8(szCatalogName, cbCatalogName, &nmlen1, lower_id);
842 scName =
843 ucs2_to_utf8(szSchemaName, cbSchemaName, &nmlen2, lower_id);
844 prName = ucs2_to_utf8(szProcName, cbProcName, &nmlen3, lower_id);
845 clName =
846 ucs2_to_utf8(szColumnName, cbColumnName, &nmlen4, lower_id);
847 ENTER_STMT_CS(stmt);
848 SC_clear_error(stmt);
849 StartRollbackState(stmt);
850 if (stmt->options.metadata_id)
851 flag |= PODBC_NOT_SEARCH_PATTERN;
852 if (SC_opencheck(stmt, func))
853 ret = SQL_ERROR;
854 else
855 ret =
856 PGAPI_ProcedureColumns(hstmt,
857 (const UCHAR *)ctName, (SQLSMALLINT)nmlen1,
858 (const UCHAR *)scName, (SQLSMALLINT)nmlen2,
859 (const UCHAR *)prName, (SQLSMALLINT)nmlen3,
860 (const UCHAR *)clName, (SQLSMALLINT)nmlen4,
861 flag);
862 ret = DiscardStatementSvp(stmt, ret, FALSE);
863 LEAVE_STMT_CS(stmt);
864 if (ctName)
865 free(ctName);
866 if (scName)
867 free(scName);
868 if (prName)
869 free(prName);
870 if (clName)
871 free(clName);
872 return ret;
875 RETCODE SQL_API SQLProceduresW(HSTMT hstmt,
876 SQLWCHAR * szCatalogName,
877 SQLSMALLINT cbCatalogName,
878 SQLWCHAR * szSchemaName,
879 SQLSMALLINT cbSchemaName,
880 SQLWCHAR * szProcName,
881 SQLSMALLINT cbProcName)
883 CSTR func = "SQLProceduresW";
884 RETCODE ret;
885 char *ctName, *scName, *prName;
886 SQLLEN nmlen1, nmlen2, nmlen3;
887 StatementClass *stmt = (StatementClass *) hstmt;
888 ConnectionClass *conn;
889 BOOL lower_id;
890 UWORD flag = 0;
891 mylog("Start\n");
893 conn = SC_get_conn(stmt);
894 lower_id = SC_is_lower_case(stmt, conn);
895 ctName =
896 ucs2_to_utf8(szCatalogName, cbCatalogName, &nmlen1, lower_id);
897 scName =
898 ucs2_to_utf8(szSchemaName, cbSchemaName, &nmlen2, lower_id);
899 prName = ucs2_to_utf8(szProcName, cbProcName, &nmlen3, lower_id);
900 ENTER_STMT_CS(stmt);
901 SC_clear_error(stmt);
902 StartRollbackState(stmt);
903 if (stmt->options.metadata_id)
904 flag |= PODBC_NOT_SEARCH_PATTERN;
905 if (SC_opencheck(stmt, func))
906 ret = SQL_ERROR;
907 else
908 ret = PGAPI_Procedures(hstmt,
909 (const UCHAR *)ctName, (SQLSMALLINT)nmlen1,
910 (const UCHAR *)scName, (SQLSMALLINT)nmlen2,
911 (const UCHAR *)prName, (SQLSMALLINT)nmlen3,
912 flag);
913 ret = DiscardStatementSvp(stmt, ret, FALSE);
914 LEAVE_STMT_CS(stmt);
915 if (ctName)
916 free(ctName);
917 if (scName)
918 free(scName);
919 if (prName)
920 free(prName);
921 return ret;
924 RETCODE SQL_API SQLTablePrivilegesW(HSTMT hstmt,
925 SQLWCHAR * szCatalogName,
926 SQLSMALLINT cbCatalogName,
927 SQLWCHAR * szSchemaName,
928 SQLSMALLINT cbSchemaName,
929 SQLWCHAR * szTableName,
930 SQLSMALLINT cbTableName)
932 CSTR func = "SQLTablePrivilegesW";
933 RETCODE ret;
934 char *ctName, *scName, *tbName;
935 SQLLEN nmlen1, nmlen2, nmlen3;
936 StatementClass *stmt = (StatementClass *) hstmt;
937 ConnectionClass *conn;
938 BOOL lower_id;
939 UWORD flag = 0;
940 mylog("Start\n");
942 conn = SC_get_conn(stmt);
943 lower_id = SC_is_lower_case(stmt, conn);
944 ctName =
945 ucs2_to_utf8(szCatalogName, cbCatalogName, &nmlen1, lower_id);
946 scName =
947 ucs2_to_utf8(szSchemaName, cbSchemaName, &nmlen2, lower_id);
948 tbName = ucs2_to_utf8(szTableName, cbTableName, &nmlen3, lower_id);
949 ENTER_STMT_CS((StatementClass *) hstmt);
950 SC_clear_error(stmt);
951 StartRollbackState(stmt);
952 if (stmt->options.metadata_id)
953 flag |= PODBC_NOT_SEARCH_PATTERN;
954 if (SC_opencheck(stmt, func))
955 ret = SQL_ERROR;
956 else
957 ret = PGAPI_TablePrivileges(hstmt,
958 (const UCHAR *)ctName, (SQLSMALLINT)nmlen1,
959 (const UCHAR *)scName, (SQLSMALLINT)nmlen2,
960 (const UCHAR *)tbName, (SQLSMALLINT)nmlen3,
961 flag);
962 ret = DiscardStatementSvp(stmt, ret, FALSE);
963 LEAVE_STMT_CS((StatementClass *) hstmt);
964 if (ctName)
965 free(ctName);
966 if (scName)
967 free(scName);
968 if (tbName)
969 free(tbName);
970 return ret;
973 RETCODE SQL_API SQLGetTypeInfoW(SQLHSTMT StatementHandle,
974 SQLSMALLINT DataType)
976 mylog("Start\n");
977 CSTR func = "SQLGetTypeInfoW";
978 RETCODE ret;
979 StatementClass *stmt = (StatementClass *) StatementHandle;
981 ENTER_STMT_CS(stmt);
982 SC_clear_error(stmt);
983 StartRollbackState(stmt);
984 if (SC_opencheck(stmt, func))
985 ret = SQL_ERROR;
986 else
987 ret = PGAPI_GetTypeInfo(StatementHandle, DataType);
988 ret = DiscardStatementSvp(stmt, ret, FALSE);
989 LEAVE_STMT_CS(stmt);
990 return ret;