8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 16:43:03 +01:00

Merge pull request #8399 from FirebirdSQL/work/gh-8356

Improvement #8356 : Make Trace use HEX representation for parameter values ​​of types [VAR]CHAR CHARACTER SET OCTETS and [VAR]BINARY.
This commit is contained in:
Vlad Khorsun 2025-01-20 22:21:55 +02:00 committed by GitHub
commit 3d7c066414
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 77 additions and 64 deletions

View File

@ -56,6 +56,67 @@
using namespace Firebird; using namespace Firebird;
namespace
{
// Convert text descriptor into UTF8 string.
// Binary data converted into HEX representation.
bool descToUTF8(const dsc* param, string& result)
{
UCHAR* address;
USHORT length;
switch (param->dsc_dtype)
{
case dtype_text:
address = param->dsc_address;
length = param->dsc_length;
break;
case dtype_varying:
address = param->dsc_address + sizeof(USHORT);
length = *(USHORT*) param->dsc_address;
fb_assert(length <= param->dsc_length - 2);
break;
default:
return false;
}
if (param->getCharSet() == CS_BINARY)
{
// Convert OCTETS and [VAR]BINARY to HEX string
char* hex = result.getBuffer(length * 2);
for (const UCHAR* p = address; p < address + length; p++)
{
UCHAR c = (*p & 0xF0) >> 4;
*hex++ = c + (c < 10 ? '0' : 'A' - 10);
c = (*p & 0x0F);
*hex++ = c + (c < 10 ? '0' : 'A' - 10);
}
return result.c_str();
}
string src(address, length);
try
{
if (!Jrd::DataTypeUtil::convertToUTF8(src, result, param->dsc_sub_type, status_exception::raise))
result = src;
}
catch (const Firebird::Exception&)
{
result = src;
}
return true;
}
} // namespace
namespace Jrd { namespace Jrd {
const char* StatementHolder::ensurePlan(bool explained) const char* StatementHolder::ensurePlan(bool explained)
@ -287,38 +348,11 @@ const dsc* TraceSQLStatementImpl::DSQLParamsImpl::getParam(FB_SIZE_T idx)
const char* TraceSQLStatementImpl::DSQLParamsImpl::getTextUTF8(CheckStatusWrapper* status, FB_SIZE_T idx) const char* TraceSQLStatementImpl::DSQLParamsImpl::getTextUTF8(CheckStatusWrapper* status, FB_SIZE_T idx)
{ {
const dsc* param = getParam(idx); const dsc* param = getParam(idx);
UCHAR* address;
USHORT length;
switch (param->dsc_dtype) if (descToUTF8(param, m_tempUTF8))
{ return m_tempUTF8.c_str();
case dtype_text:
address = param->dsc_address;
length = param->dsc_length;
break;
case dtype_varying: return nullptr;
address = param->dsc_address + sizeof(USHORT);
length = *(USHORT*) param->dsc_address;
break;
default:
return NULL;
}
string src(address, length);
try
{
if (!DataTypeUtil::convertToUTF8(src, temp_utf8_text, param->dsc_sub_type, status_exception::raise))
temp_utf8_text = src;
}
catch (const Firebird::Exception&)
{
temp_utf8_text = src;
}
return temp_utf8_text.c_str();
} }
@ -351,38 +385,11 @@ const dsc* TraceParamsImpl::getParam(FB_SIZE_T idx)
const char* TraceParamsImpl::getTextUTF8(CheckStatusWrapper* status, FB_SIZE_T idx) const char* TraceParamsImpl::getTextUTF8(CheckStatusWrapper* status, FB_SIZE_T idx)
{ {
const dsc* param = getParam(idx); const dsc* param = getParam(idx);
UCHAR* address;
USHORT length;
switch (param->dsc_dtype) if (descToUTF8(param, m_tempUTF8))
{ return m_tempUTF8.c_str();
case dtype_text:
address = param->dsc_address;
length = param->dsc_length;
break;
case dtype_varying: return nullptr;
address = param->dsc_address + sizeof(USHORT);
length = *(USHORT*) param->dsc_address;
break;
default:
return NULL;
}
string src(address, length);
try
{
if (!DataTypeUtil::convertToUTF8(src, temp_utf8_text, param->dsc_sub_type, status_exception::raise))
temp_utf8_text = src;
}
catch (const Firebird::Exception&)
{
temp_utf8_text = src;
}
return temp_utf8_text.c_str();
} }

View File

@ -267,7 +267,7 @@ private:
DsqlRequest* const m_stmt; DsqlRequest* const m_stmt;
const Firebird::Array<dsql_par*>* m_params = nullptr; const Firebird::Array<dsql_par*>* m_params = nullptr;
Firebird::HalfStaticArray<dsc, 16> m_descs; Firebird::HalfStaticArray<dsc, 16> m_descs;
Firebird::string temp_utf8_text; Firebird::string m_tempUTF8;
}; };
DsqlRequest* const m_stmt; DsqlRequest* const m_stmt;
@ -340,7 +340,7 @@ public:
private: private:
TraceDescriptors* m_descs; TraceDescriptors* m_descs;
Firebird::string temp_utf8_text; Firebird::string m_tempUTF8;
}; };

View File

@ -829,12 +829,18 @@ void TracePluginImpl::appendParams(ITraceParams* params)
switch (parameters->dsc_dtype) switch (parameters->dsc_dtype)
{ {
case dtype_text: case dtype_text:
if (parameters->getTextType() == fb_text_subtype_binary)
paramtype.printf("binary(%d)", parameters->dsc_length);
else
paramtype.printf("char(%d)", parameters->dsc_length); paramtype.printf("char(%d)", parameters->dsc_length);
break; break;
case dtype_cstring: case dtype_cstring:
paramtype.printf("cstring(%d)", parameters->dsc_length - 1); paramtype.printf("cstring(%d)", parameters->dsc_length - 1);
break; break;
case dtype_varying: case dtype_varying:
if (parameters->getTextType() == fb_text_subtype_binary)
paramtype.printf("varbinary(%d)", parameters->dsc_length - 2);
else
paramtype.printf("varchar(%d)", parameters->dsc_length - 2); paramtype.printf("varchar(%d)", parameters->dsc_length - 2);
break; break;
case dtype_blob: case dtype_blob: