Skip to content
This repository was archived by the owner on Dec 13, 2022. It is now read-only.
Open
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
31 changes: 22 additions & 9 deletions src/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,23 +237,36 @@ char *Value::as_c_str(unsigned long &size) const
size= 0;
return 0;
}

boost::uint32_t length_from_meta= m_metadata;

if (m_type == MYSQL_TYPE_STRING)
{
if (m_metadata >= 256)
{
uint byte0= m_metadata & 0xFF;
uint byte1= m_metadata >> 8;

/* a long CHAR() field: see #37426 */
if ((byte0 & 0x30) != 0x30)
length_from_meta= byte1 | (((byte0 & 0x30) ^ 0x30) << 4);
else
length_from_meta = m_metadata >> 8;
}
else
length_from_meta= m_metadata;
}

/*
Length encoded; First byte is length of string.
*/
int metadata_length= m_size > 251 ? 2: 1;
int metadata_length= length_from_meta > 255 ? 2 : 1;
/*
Size is length of the character string; not of the entire storage
*/
size= m_size - metadata_length;

char *str = const_cast<char *>(m_storage + metadata_length);

if (m_type == mysql::system::MYSQL_TYPE_VARCHAR && m_metadata > 255) {
str++;
size--;
}

return str;
return const_cast<char *>(m_storage + metadata_length);
}

unsigned char *Value::as_blob(unsigned long &size) const
Expand Down