2 * Description: This module contains UNICODE routines
10 #include "pgapifunc.h"
11 #include "connection.h"
12 #include "statement.h"
15 RETCODE SQL_API
SQLGetStmtAttrW(SQLHSTMT hstmt
,
16 SQLINTEGER fAttribute
,
18 SQLINTEGER cbValueMax
,
19 SQLINTEGER
* pcbValue
)
22 StatementClass
*stmt
= (StatementClass
*) hstmt
;
25 ENTER_STMT_CS((StatementClass
*) hstmt
);
26 SC_clear_error((StatementClass
*) hstmt
);
27 StartRollbackState(stmt
);
28 ret
= PGAPI_GetStmtAttr(hstmt
, fAttribute
, rgbValue
,
29 cbValueMax
, pcbValue
);
30 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
31 LEAVE_STMT_CS((StatementClass
*) hstmt
);
35 RETCODE SQL_API
SQLSetStmtAttrW(SQLHSTMT hstmt
,
36 SQLINTEGER fAttribute
,
37 PTR rgbValue
, SQLINTEGER cbValueMax
)
40 StatementClass
*stmt
= (StatementClass
*) hstmt
;
45 StartRollbackState(stmt
);
46 ret
= PGAPI_SetStmtAttr(hstmt
, fAttribute
, rgbValue
, cbValueMax
);
47 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
52 RETCODE SQL_API
SQLGetConnectAttrW(HDBC hdbc
,
53 SQLINTEGER fAttribute
,
55 SQLINTEGER cbValueMax
,
56 SQLINTEGER
* pcbValue
)
61 ENTER_CONN_CS((ConnectionClass
*) hdbc
);
62 CC_clear_error((ConnectionClass
*) hdbc
);
63 ret
= PGAPI_GetConnectAttr(hdbc
, fAttribute
, rgbValue
,
64 cbValueMax
, pcbValue
);
65 LEAVE_CONN_CS((ConnectionClass
*) hdbc
);
69 RETCODE SQL_API
SQLSetConnectAttrW(HDBC hdbc
,
70 SQLINTEGER fAttribute
,
71 PTR rgbValue
, SQLINTEGER cbValue
)
74 ConnectionClass
*conn
= (ConnectionClass
*) hdbc
;
79 CC_set_in_unicode_driver(conn
);
80 ret
= PGAPI_SetConnectAttr(hdbc
, fAttribute
, rgbValue
, cbValue
);
87 SQLSetDescFieldW(SQLHDESC DescriptorHandle
, SQLSMALLINT RecNumber
,
88 SQLSMALLINT FieldIdentifier
, PTR Value
,
89 SQLINTEGER BufferLength
)
94 BOOL val_alloced
= FALSE
;
97 if (BufferLength
> 0 || SQL_NTS
== BufferLength
)
99 switch (FieldIdentifier
)
101 case SQL_DESC_BASE_COLUMN_NAME
:
102 case SQL_DESC_BASE_TABLE_NAME
:
103 case SQL_DESC_CATALOG_NAME
:
105 case SQL_DESC_LITERAL_PREFIX
:
106 case SQL_DESC_LITERAL_SUFFIX
:
107 case SQL_DESC_LOCAL_TYPE_NAME
:
109 case SQL_DESC_SCHEMA_NAME
:
110 case SQL_DESC_TABLE_NAME
:
111 case SQL_DESC_TYPE_NAME
:
113 ucs2_to_utf8((const SQLWCHAR
*)Value
,
115 0 ? BufferLength
/ WCLEN
: BufferLength
,
123 uval
= (char *)Value
;
124 vallen
= BufferLength
;
127 PGAPI_SetDescField(DescriptorHandle
, RecNumber
, FieldIdentifier
,
128 uval
, (SQLINTEGER
) vallen
);
135 SQLGetDescFieldW(SQLHDESC hdesc
, SQLSMALLINT iRecord
,
136 SQLSMALLINT iField
, PTR rgbValue
,
137 SQLINTEGER cbValueMax
, SQLINTEGER
* pcbValue
)
140 SQLINTEGER blen
= 0, bMax
, *pcbV
;
146 case SQL_DESC_BASE_COLUMN_NAME
:
147 case SQL_DESC_BASE_TABLE_NAME
:
148 case SQL_DESC_CATALOG_NAME
:
150 case SQL_DESC_LITERAL_PREFIX
:
151 case SQL_DESC_LITERAL_SUFFIX
:
152 case SQL_DESC_LOCAL_TYPE_NAME
:
154 case SQL_DESC_SCHEMA_NAME
:
155 case SQL_DESC_TABLE_NAME
:
156 case SQL_DESC_TYPE_NAME
:
157 bMax
= cbValueMax
* 3 / WCLEN
;
158 rgbV
= (char *)malloc(bMax
+ 1);
160 for (;; bMax
= blen
+ 1, rgbV
= (char *)realloc(rgbV
, bMax
))
163 PGAPI_GetDescField(hdesc
, iRecord
, iField
, rgbV
, bMax
,
165 if (SQL_SUCCESS_WITH_INFO
!= ret
|| blen
< bMax
)
168 if (SQL_SUCCEEDED(ret
))
171 (SQLINTEGER
) utf8_to_ucs2(rgbV
, blen
,
172 (SQLWCHAR
*) rgbValue
,
174 if (SQL_SUCCESS
== ret
&& blen
* WCLEN
>= cbValueMax
)
176 ret
= SQL_SUCCESS_WITH_INFO
;
177 DC_set_error((DescriptorClass
*)hdesc
, STMT_TRUNCATED
,
178 "The buffer was too small for the rgbDesc.");
181 *pcbValue
= blen
* WCLEN
;
187 rgbV
= (char *)rgbValue
;
191 PGAPI_GetDescField(hdesc
, iRecord
, iField
, rgbV
, bMax
,
199 RETCODE SQL_API
SQLGetDiagRecW(SQLSMALLINT fHandleType
,
202 SQLWCHAR
* szSqlState
,
203 SQLINTEGER
* pfNativeError
,
204 SQLWCHAR
* szErrorMsg
,
205 SQLSMALLINT cbErrorMsgMax
,
206 SQLSMALLINT
* pcbErrorMsg
)
209 SQLSMALLINT buflen
, tlen
;
210 char *qstr
= NULL
, *mtxt
= NULL
;
214 qstr
= (char *)malloc(8);
216 if (szErrorMsg
&& cbErrorMsgMax
> 0)
218 buflen
= cbErrorMsgMax
;
219 mtxt
= (char *)malloc(buflen
);
221 ret
= PGAPI_GetDiagRec(fHandleType
, handle
, iRecord
,
222 (SQLCHAR
*)qstr
, pfNativeError
,
223 (SQLCHAR
*)mtxt
, buflen
, &tlen
);
224 if (SQL_SUCCEEDED(ret
))
227 utf8_to_ucs2(qstr
, strlen(qstr
), szSqlState
, 6);
228 if (mtxt
&& tlen
<= cbErrorMsgMax
)
231 (SQLSMALLINT
) utf8_to_ucs2(mtxt
, tlen
, szErrorMsg
,
233 if (tlen
>= cbErrorMsgMax
)
234 ret
= SQL_SUCCESS_WITH_INFO
;
246 SQLRETURN SQL_API
SQLColAttributeW(SQLHSTMT hstmt
,
249 SQLPOINTER pCharAttr
,
250 SQLSMALLINT cbCharAttrMax
,
251 SQLSMALLINT
* pcbCharAttr
,
252 #if defined(WITH_UNIXODBC) || (defined(WIN32) && ! defined(_WIN64))
259 CSTR func
= "SQLColAttributeW";
261 StatementClass
*stmt
= (StatementClass
*) hstmt
;
262 SQLSMALLINT
*rgbL
, blen
= 0, bMax
;
267 SC_clear_error(stmt
);
268 StartRollbackState(stmt
);
271 case SQL_DESC_BASE_COLUMN_NAME
:
272 case SQL_DESC_BASE_TABLE_NAME
:
273 case SQL_DESC_CATALOG_NAME
:
275 case SQL_DESC_LITERAL_PREFIX
:
276 case SQL_DESC_LITERAL_SUFFIX
:
277 case SQL_DESC_LOCAL_TYPE_NAME
:
279 case SQL_DESC_SCHEMA_NAME
:
280 case SQL_DESC_TABLE_NAME
:
281 case SQL_DESC_TYPE_NAME
:
282 case SQL_COLUMN_NAME
:
283 bMax
= cbCharAttrMax
* 3 / WCLEN
;
284 rgbD
= (char *)malloc(bMax
);
286 for (;; bMax
= blen
+ 1, rgbD
= (char *)realloc(rgbD
, bMax
))
288 ret
= PGAPI_ColAttributes(hstmt
, iCol
, iField
, rgbD
,
289 bMax
, rgbL
, (SQLINTEGER
*)pNumAttr
);
290 if (SQL_SUCCESS_WITH_INFO
!= ret
|| blen
< bMax
)
293 if (SQL_SUCCEEDED(ret
))
296 (SQLSMALLINT
) utf8_to_ucs2(rgbD
, blen
,
297 (SQLWCHAR
*) pCharAttr
,
298 cbCharAttrMax
/ WCLEN
);
299 if (SQL_SUCCESS
== ret
&& blen
* WCLEN
>= cbCharAttrMax
)
301 ret
= SQL_SUCCESS_WITH_INFO
;
302 SC_set_error(stmt
, STMT_TRUNCATED
,
303 "The buffer was too small for the pCharAttr.",
307 *pcbCharAttr
= blen
* WCLEN
;
313 rgbD
= (char *)pCharAttr
;
314 bMax
= cbCharAttrMax
;
316 ret
= PGAPI_ColAttributes(hstmt
, iCol
, iField
, rgbD
,
317 bMax
, rgbL
, (SQLINTEGER
*)pNumAttr
);
320 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
326 RETCODE SQL_API
SQLGetDiagFieldW(SQLSMALLINT fHandleType
,
329 SQLSMALLINT fDiagField
,
330 SQLPOINTER rgbDiagInfo
,
331 SQLSMALLINT cbDiagInfoMax
,
332 SQLSMALLINT
* pcbDiagInfo
)
335 SQLSMALLINT
*rgbL
, blen
= 0, bMax
;
339 mylog("Handle=(%u,%p) Rec=%d Id=%d info=(%p,%d)\n",
340 fHandleType
, handle
, iRecord
, fDiagField
, rgbDiagInfo
,
344 case SQL_DIAG_DYNAMIC_FUNCTION
:
345 case SQL_DIAG_CLASS_ORIGIN
:
346 case SQL_DIAG_CONNECTION_NAME
:
347 case SQL_DIAG_MESSAGE_TEXT
:
348 case SQL_DIAG_SERVER_NAME
:
349 case SQL_DIAG_SQLSTATE
:
350 case SQL_DIAG_SUBCLASS_ORIGIN
:
351 bMax
= cbDiagInfoMax
* 3 / WCLEN
+ 1;
352 if (rgbD
= (char *)malloc(bMax
), !rgbD
)
355 for (;; bMax
= blen
+ 1, rgbD
= (char *)realloc(rgbD
, bMax
))
358 PGAPI_GetDiagField(fHandleType
, handle
, iRecord
,
359 fDiagField
, rgbD
, bMax
, rgbL
);
360 if (SQL_SUCCESS_WITH_INFO
!= ret
|| blen
< bMax
)
363 if (SQL_SUCCEEDED(ret
))
366 (SQLSMALLINT
) utf8_to_ucs2(rgbD
, blen
,
367 (SQLWCHAR
*) rgbDiagInfo
,
368 cbDiagInfoMax
/ WCLEN
);
369 if (SQL_SUCCESS
== ret
&& blen
* WCLEN
>= cbDiagInfoMax
)
370 ret
= SQL_SUCCESS_WITH_INFO
;
374 extern int platformId
;
376 if (VER_PLATFORM_WIN32_WINDOWS
== platformId
377 && NULL
== rgbDiagInfo
&& 0 == cbDiagInfoMax
)
380 *pcbDiagInfo
= blen
* WCLEN
;
387 rgbD
= (char *)rgbDiagInfo
;
388 bMax
= cbDiagInfoMax
;
391 PGAPI_GetDiagField(fHandleType
, handle
, iRecord
, fDiagField
,