|
56 | 56 |
|
57 | 57 | using namespace Firebird; |
58 | 58 |
|
| 59 | +namespace |
| 60 | +{ |
| 61 | + |
| 62 | +// Convert text descriptor into UTF8 string. |
| 63 | +// Binary data converted into HEX representation. |
| 64 | +bool descToUTF8(const dsc* param, string& result) |
| 65 | +{ |
| 66 | + UCHAR* address; |
| 67 | + USHORT length; |
| 68 | + |
| 69 | + switch (param->dsc_dtype) |
| 70 | + { |
| 71 | + case dtype_text: |
| 72 | + address = param->dsc_address; |
| 73 | + length = param->dsc_length; |
| 74 | + break; |
| 75 | + |
| 76 | + case dtype_varying: |
| 77 | + address = param->dsc_address + sizeof(USHORT); |
| 78 | + length = *(USHORT*) param->dsc_address; |
| 79 | + fb_assert(length <= param->dsc_length - 2); |
| 80 | + break; |
| 81 | + |
| 82 | + default: |
| 83 | + return false; |
| 84 | + } |
| 85 | + |
| 86 | + if (param->getCharSet() == CS_BINARY) |
| 87 | + { |
| 88 | + // Convert OCTETS and [VAR]BINARY to HEX string |
| 89 | + |
| 90 | + char* hex = result.getBuffer(length * 2); |
| 91 | + |
| 92 | + for (const UCHAR* p = address; p < address + length; p++) |
| 93 | + { |
| 94 | + UCHAR c = (*p & 0xF0) >> 4; |
| 95 | + *hex++ = c + (c < 10 ? '0' : 'A' - 10); |
| 96 | + |
| 97 | + c = (*p & 0x0F); |
| 98 | + *hex++ = c + (c < 10 ? '0' : 'A' - 10); |
| 99 | + } |
| 100 | + return result.c_str(); |
| 101 | + } |
| 102 | + |
| 103 | + string src(address, length); |
| 104 | + |
| 105 | + try |
| 106 | + { |
| 107 | + if (!Jrd::DataTypeUtil::convertToUTF8(src, result, param->dsc_sub_type, status_exception::raise)) |
| 108 | + result = src; |
| 109 | + } |
| 110 | + catch (const Firebird::Exception&) |
| 111 | + { |
| 112 | + result = src; |
| 113 | + } |
| 114 | + |
| 115 | + return true; |
| 116 | +} |
| 117 | + |
| 118 | +} // namespace |
| 119 | + |
59 | 120 | namespace Jrd { |
60 | 121 |
|
61 | 122 | const char* StatementHolder::ensurePlan(bool explained) |
@@ -287,38 +348,11 @@ const dsc* TraceSQLStatementImpl::DSQLParamsImpl::getParam(FB_SIZE_T idx) |
287 | 348 | const char* TraceSQLStatementImpl::DSQLParamsImpl::getTextUTF8(CheckStatusWrapper* status, FB_SIZE_T idx) |
288 | 349 | { |
289 | 350 | const dsc* param = getParam(idx); |
290 | | - UCHAR* address; |
291 | | - USHORT length; |
292 | 351 |
|
293 | | - switch (param->dsc_dtype) |
294 | | - { |
295 | | - case dtype_text: |
296 | | - address = param->dsc_address; |
297 | | - length = param->dsc_length; |
298 | | - break; |
299 | | - |
300 | | - case dtype_varying: |
301 | | - address = param->dsc_address + sizeof(USHORT); |
302 | | - length = *(USHORT*) param->dsc_address; |
303 | | - break; |
304 | | - |
305 | | - default: |
306 | | - return NULL; |
307 | | - } |
| 352 | + if (descToUTF8(param, m_tempUTF8)) |
| 353 | + return m_tempUTF8.c_str(); |
308 | 354 |
|
309 | | - string src(address, length); |
310 | | - |
311 | | - try |
312 | | - { |
313 | | - if (!DataTypeUtil::convertToUTF8(src, temp_utf8_text, param->dsc_sub_type, status_exception::raise)) |
314 | | - temp_utf8_text = src; |
315 | | - } |
316 | | - catch (const Firebird::Exception&) |
317 | | - { |
318 | | - temp_utf8_text = src; |
319 | | - } |
320 | | - |
321 | | - return temp_utf8_text.c_str(); |
| 355 | + return nullptr; |
322 | 356 | } |
323 | 357 |
|
324 | 358 |
|
@@ -351,38 +385,11 @@ const dsc* TraceParamsImpl::getParam(FB_SIZE_T idx) |
351 | 385 | const char* TraceParamsImpl::getTextUTF8(CheckStatusWrapper* status, FB_SIZE_T idx) |
352 | 386 | { |
353 | 387 | const dsc* param = getParam(idx); |
354 | | - UCHAR* address; |
355 | | - USHORT length; |
356 | 388 |
|
357 | | - switch (param->dsc_dtype) |
358 | | - { |
359 | | - case dtype_text: |
360 | | - address = param->dsc_address; |
361 | | - length = param->dsc_length; |
362 | | - break; |
363 | | - |
364 | | - case dtype_varying: |
365 | | - address = param->dsc_address + sizeof(USHORT); |
366 | | - length = *(USHORT*) param->dsc_address; |
367 | | - break; |
368 | | - |
369 | | - default: |
370 | | - return NULL; |
371 | | - } |
372 | | - |
373 | | - string src(address, length); |
374 | | - |
375 | | - try |
376 | | - { |
377 | | - if (!DataTypeUtil::convertToUTF8(src, temp_utf8_text, param->dsc_sub_type, status_exception::raise)) |
378 | | - temp_utf8_text = src; |
379 | | - } |
380 | | - catch (const Firebird::Exception&) |
381 | | - { |
382 | | - temp_utf8_text = src; |
383 | | - } |
| 389 | + if (descToUTF8(param, m_tempUTF8)) |
| 390 | + return m_tempUTF8.c_str(); |
384 | 391 |
|
385 | | - return temp_utf8_text.c_str(); |
| 392 | + return nullptr; |
386 | 393 | } |
387 | 394 |
|
388 | 395 |
|
|
0 commit comments