2 * Description: This module contains UNICODE routines
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
,
19 SQLSMALLINT NameLength3
,
20 SQLWCHAR
* ColumnName
,
21 SQLSMALLINT NameLength4
)
23 CSTR func
= "SQLColumnsW";
25 char *ctName
, *scName
, *tbName
, *clName
;
26 SQLLEN nmlen1
, nmlen2
, nmlen3
, nmlen4
;
27 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
28 ConnectionClass
*conn
;
30 UWORD flag
= PODBC_SEARCH_PUBLIC_SCHEMA
;
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
);
42 StartRollbackState(stmt
);
43 if (stmt
->options
.metadata_id
)
44 flag
|= PODBC_NOT_SEARCH_PATTERN
;
45 if (SC_opencheck(stmt
, func
))
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
,
55 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
69 RETCODE SQL_API
SQLConnectW(HDBC ConnectionHandle
,
70 SQLWCHAR
* ServerName
,
71 SQLSMALLINT NameLength1
,
73 SQLSMALLINT NameLength2
,
74 SQLWCHAR
* Authentication
,
75 SQLSMALLINT NameLength3
)
77 char *svName
, *usName
, *auth
;
78 SQLLEN nmlen1
, nmlen2
, nmlen3
;
80 ConnectionClass
*conn
= (ConnectionClass
*) ConnectionHandle
;
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
);
103 RETCODE SQL_API
SQLDriverConnectW(HDBC hdbc
,
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;
116 SQLSMALLINT olen
, *pCSO
;
118 ConnectionClass
*conn
= (ConnectionClass
*) hdbc
;
122 CC_clear_error(conn
);
123 CC_set_in_unicode_driver(conn
);
124 szIn
= ucs2_to_utf8(szConnStrIn
, cbConnStrIn
, &inlen
, FALSE
);
125 maxlen
= cbConnStrOutMax
;
130 obuflen
= maxlen
+ 1;
131 szOut
= (char *)malloc(obuflen
);
133 } else if (pcbConnStrOut
)
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
;
145 utf8_to_ucs2(szOut
, olen
, szConnStrOut
,
148 utf8_to_ucs2(szOut
, maxlen
, szConnStrOut
, cbConnStrOutMax
);
149 if (outlen
>= cbConnStrOutMax
)
151 inolog("cbConnstrOutMax=%d pcb=%p\n", cbConnStrOutMax
,
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
;
161 *pcbConnStrOut
= (SQLSMALLINT
) outlen
;
170 RETCODE SQL_API
SQLBrowseConnectW(HDBC hdbc
,
171 SQLWCHAR
* szConnStrIn
,
172 SQLSMALLINT cbConnStrIn
,
173 SQLWCHAR
* szConnStrOut
,
174 SQLSMALLINT cbConnStrOutMax
,
175 SQLSMALLINT
* pcbConnStrOut
)
179 SQLUSMALLINT obuflen
;
182 ConnectionClass
*conn
= (ConnectionClass
*) hdbc
;
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
);
195 if (ret
!= SQL_ERROR
)
198 utf8_to_ucs2(szOut
, olen
, szConnStrOut
, cbConnStrOutMax
);
200 *pcbConnStrOut
= (SQLSMALLINT
) outlen
;
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
)
219 return PGAPI_DataSources(EnvironmentHandle, Direction, ServerName,
220 BufferLength1, NameLength1, Description, BufferLength2,
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";
238 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
239 SQLSMALLINT buflen
, nmlen
;
244 if (BufferLength
> 0)
245 buflen
= BufferLength
* 3;
249 clName
= (char *)malloc(buflen
);
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
)
261 if (SQL_SUCCEEDED(ret
))
263 SQLLEN nmcount
= nmlen
;
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",
276 *NameLength
= (SQLSMALLINT
) nmcount
;
278 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
285 RETCODE SQL_API
SQLExecDirectW(HSTMT StatementHandle
,
286 SQLWCHAR
* StatementText
,
287 SQLINTEGER TextLength
)
289 CSTR func
= "SQLExecDirectW";
293 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
297 stxt
= ucs2_to_utf8(StatementText
, TextLength
, &slen
, FALSE
);
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
))
307 PGAPI_ExecDirect_Vx(StatementHandle
,
308 (const UCHAR
*)stxt
, (SQLINTEGER
)slen
,
310 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
317 RETCODE SQL_API
SQLGetCursorNameW(HSTMT StatementHandle
,
318 SQLWCHAR
* CursorName
,
319 SQLSMALLINT BufferLength
,
320 SQLSMALLINT
* NameLength
)
322 CSTR func
= "SQLGetCursorNameW";
324 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
326 SQLSMALLINT clen
, buflen
;
329 if (BufferLength
> 0)
330 buflen
= BufferLength
* 3;
333 crName
= (char *)malloc(buflen
);
335 SC_clear_error(stmt
);
336 StartRollbackState(stmt
);
337 for (;; buflen
= clen
+ 1, crName
= (char *)realloc(crName
, buflen
))
340 PGAPI_GetCursorName(StatementHandle
,
341 (UCHAR
*)crName
, buflen
, &clen
);
342 if (SQL_SUCCESS_WITH_INFO
!= ret
|| clen
< buflen
)
345 if (SQL_SUCCEEDED(ret
))
347 SQLLEN nmcount
= clen
;
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",
359 *NameLength
= (SQLSMALLINT
) nmcount
;
361 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
367 RETCODE SQL_API
SQLGetInfoW(HDBC ConnectionHandle
,
368 SQLUSMALLINT InfoType
, PTR InfoValue
,
369 SQLSMALLINT BufferLength
,
370 SQLSMALLINT
* StringLength
)
372 ConnectionClass
*conn
= (ConnectionClass
*) ConnectionHandle
;
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
);
395 RETCODE SQL_API
SQLPrepareW(HSTMT StatementHandle
,
396 SQLWCHAR
* StatementText
,
397 SQLINTEGER TextLength
)
399 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
405 stxt
= ucs2_to_utf8(StatementText
, TextLength
, &slen
, FALSE
);
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
);
418 RETCODE SQL_API
SQLSetCursorNameW(HSTMT StatementHandle
,
419 SQLWCHAR
* CursorName
,
420 SQLSMALLINT NameLength
)
423 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
428 crName
= ucs2_to_utf8(CursorName
, NameLength
, &nlen
, FALSE
);
430 SC_clear_error(stmt
);
431 StartRollbackState(stmt
);
433 PGAPI_SetCursorName(StatementHandle
,
434 (const UCHAR
*)crName
, (SQLSMALLINT
)nlen
);
435 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
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
,
451 SQLUSMALLINT Nullable
)
453 CSTR func
= "SQLSpecialColumnsW";
455 char *ctName
, *scName
, *tbName
;
456 SQLLEN nmlen1
, nmlen2
, nmlen3
;
457 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
458 ConnectionClass
*conn
;
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
);
468 SC_clear_error(stmt
);
469 StartRollbackState(stmt
);
470 if (SC_opencheck(stmt
, func
))
474 PGAPI_SpecialColumns(StatementHandle
, IdentifierType
,
475 (const UCHAR
*)ctName
, (SQLSMALLINT
)nmlen1
,
476 (const UCHAR
*)scName
, (SQLSMALLINT
)nmlen2
,
477 (const UCHAR
*)tbName
, (SQLSMALLINT
)nmlen3
,
479 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
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
,
498 SQLUSMALLINT Reserved
)
500 CSTR func
= "SQLStatisticsW";
502 char *ctName
, *scName
, *tbName
;
503 SQLLEN nmlen1
, nmlen2
, nmlen3
;
504 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
505 ConnectionClass
*conn
;
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
);
516 SC_clear_error(stmt
);
517 StartRollbackState(stmt
);
518 if (SC_opencheck(stmt
, func
))
522 PGAPI_Statistics(StatementHandle
,
523 (const UCHAR
*)ctName
, (SQLSMALLINT
)nmlen1
,
524 (const UCHAR
*)scName
, (SQLSMALLINT
)nmlen2
,
525 (const UCHAR
*)tbName
, (SQLSMALLINT
)nmlen3
,
527 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
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";
550 char *ctName
, *scName
, *tbName
, *tbType
;
551 SQLLEN nmlen1
, nmlen2
, nmlen3
, nmlen4
;
552 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
553 ConnectionClass
*conn
;
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
);
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
))
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
);
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";
603 char *ctName
, *scName
, *tbName
, *clName
;
604 SQLLEN nmlen1
, nmlen2
, nmlen3
, nmlen4
;
605 StatementClass
*stmt
= (StatementClass
*) hstmt
;
606 ConnectionClass
*conn
;
611 conn
= SC_get_conn(stmt
);
612 lower_id
= SC_is_lower_case(stmt
, conn
);
614 ucs2_to_utf8(szCatalogName
, cbCatalogName
, &nmlen1
, lower_id
);
616 ucs2_to_utf8(szSchemaName
, cbSchemaName
, &nmlen2
, lower_id
);
617 tbName
= ucs2_to_utf8(szTableName
, cbTableName
, &nmlen3
, lower_id
);
619 ucs2_to_utf8(szColumnName
, cbColumnName
, &nmlen4
, lower_id
);
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
))
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
);
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";
663 char *ctName
, *scName
, *tbName
, *fkctName
, *fkscName
, *fktbName
;
664 SQLLEN nmlen1
, nmlen2
, nmlen3
, nmlen4
, nmlen5
, nmlen6
;
665 StatementClass
*stmt
= (StatementClass
*) hstmt
;
666 ConnectionClass
*conn
;
670 conn
= SC_get_conn(stmt
);
671 lower_id
= SC_is_lower_case(stmt
, conn
);
673 ucs2_to_utf8(szPkCatalogName
, cbPkCatalogName
, &nmlen1
,
676 ucs2_to_utf8(szPkSchemaName
, cbPkSchemaName
, &nmlen2
, lower_id
);
678 ucs2_to_utf8(szPkTableName
, cbPkTableName
, &nmlen3
, lower_id
);
680 ucs2_to_utf8(szFkCatalogName
, cbFkCatalogName
, &nmlen4
,
683 ucs2_to_utf8(szFkSchemaName
, cbFkSchemaName
, &nmlen5
, lower_id
);
685 ucs2_to_utf8(szFkTableName
, cbFkTableName
, &nmlen6
, lower_id
);
687 SC_clear_error(stmt
);
688 StartRollbackState(stmt
);
689 if (SC_opencheck(stmt
, func
))
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
);
716 RETCODE SQL_API
SQLNativeSqlW(HDBC hdbc
,
717 SQLWCHAR
* szSqlStrIn
,
718 SQLINTEGER cbSqlStrIn
,
720 SQLINTEGER cbSqlStrMax
,
721 SQLINTEGER
* pcbSqlStr
)
723 CSTR func
= "SQLNativeSqlW";
725 char *szIn
, *szOut
= NULL
;
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
);
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
;
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
)
749 if (SQL_SUCCEEDED(ret
))
751 SQLLEN szcount
= olen
;
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",
766 *pcbSqlStr
= (SQLINTEGER
) szcount
;
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";
783 char *ctName
, *scName
, *tbName
;
784 SQLLEN nmlen1
, nmlen2
, nmlen3
;
785 StatementClass
*stmt
= (StatementClass
*) hstmt
;
786 ConnectionClass
*conn
;
790 conn
= SC_get_conn(stmt
);
791 lower_id
= SC_is_lower_case(stmt
, conn
);
793 ucs2_to_utf8(szCatalogName
, cbCatalogName
, &nmlen1
, lower_id
);
795 ucs2_to_utf8(szSchemaName
, cbSchemaName
, &nmlen2
, lower_id
);
796 tbName
= ucs2_to_utf8(szTableName
, cbTableName
, &nmlen3
, lower_id
);
798 SC_clear_error(stmt
);
799 StartRollbackState(stmt
);
800 if (SC_opencheck(stmt
, func
))
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
);
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";
830 char *ctName
, *scName
, *prName
, *clName
;
831 SQLLEN nmlen1
, nmlen2
, nmlen3
, nmlen4
;
832 StatementClass
*stmt
= (StatementClass
*) hstmt
;
833 ConnectionClass
*conn
;
838 conn
= SC_get_conn(stmt
);
839 lower_id
= SC_is_lower_case(stmt
, conn
);
841 ucs2_to_utf8(szCatalogName
, cbCatalogName
, &nmlen1
, lower_id
);
843 ucs2_to_utf8(szSchemaName
, cbSchemaName
, &nmlen2
, lower_id
);
844 prName
= ucs2_to_utf8(szProcName
, cbProcName
, &nmlen3
, lower_id
);
846 ucs2_to_utf8(szColumnName
, cbColumnName
, &nmlen4
, lower_id
);
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
))
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
,
862 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
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";
885 char *ctName
, *scName
, *prName
;
886 SQLLEN nmlen1
, nmlen2
, nmlen3
;
887 StatementClass
*stmt
= (StatementClass
*) hstmt
;
888 ConnectionClass
*conn
;
893 conn
= SC_get_conn(stmt
);
894 lower_id
= SC_is_lower_case(stmt
, conn
);
896 ucs2_to_utf8(szCatalogName
, cbCatalogName
, &nmlen1
, lower_id
);
898 ucs2_to_utf8(szSchemaName
, cbSchemaName
, &nmlen2
, lower_id
);
899 prName
= ucs2_to_utf8(szProcName
, cbProcName
, &nmlen3
, lower_id
);
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
))
908 ret
= PGAPI_Procedures(hstmt
,
909 (const UCHAR
*)ctName
, (SQLSMALLINT
)nmlen1
,
910 (const UCHAR
*)scName
, (SQLSMALLINT
)nmlen2
,
911 (const UCHAR
*)prName
, (SQLSMALLINT
)nmlen3
,
913 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
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";
934 char *ctName
, *scName
, *tbName
;
935 SQLLEN nmlen1
, nmlen2
, nmlen3
;
936 StatementClass
*stmt
= (StatementClass
*) hstmt
;
937 ConnectionClass
*conn
;
942 conn
= SC_get_conn(stmt
);
943 lower_id
= SC_is_lower_case(stmt
, conn
);
945 ucs2_to_utf8(szCatalogName
, cbCatalogName
, &nmlen1
, lower_id
);
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
))
957 ret
= PGAPI_TablePrivileges(hstmt
,
958 (const UCHAR
*)ctName
, (SQLSMALLINT
)nmlen1
,
959 (const UCHAR
*)scName
, (SQLSMALLINT
)nmlen2
,
960 (const UCHAR
*)tbName
, (SQLSMALLINT
)nmlen3
,
962 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
963 LEAVE_STMT_CS((StatementClass
*) hstmt
);
973 RETCODE SQL_API
SQLGetTypeInfoW(SQLHSTMT StatementHandle
,
974 SQLSMALLINT DataType
)
977 CSTR func
= "SQLGetTypeInfoW";
979 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
982 SC_clear_error(stmt
);
983 StartRollbackState(stmt
);
984 if (SC_opencheck(stmt
, func
))
987 ret
= PGAPI_GetTypeInfo(StatementHandle
, DataType
);
988 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);