Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement #8356 : Make Trace use HEX representation for parameter values ​​of types [VAR]CHAR CHARACTER SET OCTETS and [VAR]BINARY. #8399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 67 additions & 60 deletions src/jrd/trace/TraceObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,67 @@

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 (UCHAR* p = address; p < address + length; p++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (UCHAR* p = address; p < address + length; p++)
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 {

const char* StatementHolder::ensurePlan(bool explained)
Expand Down Expand Up @@ -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 dsc* param = getParam(idx);
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;
break;

default:
return NULL;
}
if (descToUTF8(param, m_tempUTF8))
return m_tempUTF8.c_str();

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();
return nullptr;
}


Expand Down Expand Up @@ -351,38 +385,11 @@ const dsc* TraceParamsImpl::getParam(FB_SIZE_T idx)
const char* TraceParamsImpl::getTextUTF8(CheckStatusWrapper* status, FB_SIZE_T idx)
{
const dsc* param = getParam(idx);
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;
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;
}
if (descToUTF8(param, m_tempUTF8))
return m_tempUTF8.c_str();

return temp_utf8_text.c_str();
return nullptr;
}


Expand Down
4 changes: 2 additions & 2 deletions src/jrd/trace/TraceObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class TraceSQLStatementImpl :
DsqlRequest* const m_stmt;
const Firebird::Array<dsql_par*>* m_params = nullptr;
Firebird::HalfStaticArray<dsc, 16> m_descs;
Firebird::string temp_utf8_text;
Firebird::string m_tempUTF8;
};

DsqlRequest* const m_stmt;
Expand Down Expand Up @@ -340,7 +340,7 @@ class TraceParamsImpl :

private:
TraceDescriptors* m_descs;
Firebird::string temp_utf8_text;
Firebird::string m_tempUTF8;
};


Expand Down
10 changes: 8 additions & 2 deletions src/utilities/ntrace/TracePluginImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,13 +829,19 @@ void TracePluginImpl::appendParams(ITraceParams* params)
switch (parameters->dsc_dtype)
{
case dtype_text:
paramtype.printf("char(%d)", parameters->dsc_length);
if (parameters->getTextType() == fb_text_subtype_binary)
paramtype.printf("binary(%d)", parameters->dsc_length);
else
paramtype.printf("char(%d)", parameters->dsc_length);
break;
case dtype_cstring:
paramtype.printf("cstring(%d)", parameters->dsc_length - 1);
break;
case dtype_varying:
paramtype.printf("varchar(%d)", parameters->dsc_length - 2);
if (parameters->getTextType() == fb_text_subtype_binary)
paramtype.printf("varbinary(%d)", parameters->dsc_length - 2);
else
paramtype.printf("varchar(%d)", parameters->dsc_length - 2);
break;
case dtype_blob:
paramtype = "blob";
Expand Down
Loading