I’m using mysql_fetch_field_direct to get information about the type of a given column in a dynamically fetched result set like so:
MYSQL_FIELD *field = mysql_fetch_field_direct(resultSet, col);
then I access field->type to check the field’s type. However, I am currently stuck because I would like to take different actions depending on whether the field’s type is BLOB or TEXT. However, it seems that the enum_field_types enum only contains MYSQL_TYPE_BLOB, but not MYSQL_TYPE_TEXT and instead marks text as BLOBs as well. This kinda makes sense given that a TEXT object is essentially a BLOB but with a special interpretation when processing the data.
However, this leaves me wondering: How can I check whether the field’s actual type is BLOB or TEXT?
>Solution :
Check the field->charsetnr.
If this value is 63, it’s a binary BLOB.
If it’s any other value, it’s TEXT.
Here’s what the documentation (in the section describing charsetnr) has to say about this:
To distinguish between binary and nonbinary data for string data types, check whether the charsetnr value is 63. If so, the character set is binary, which indicates binary rather than nonbinary data. This enables you to distinguish BINARY from CHAR, VARBINARY from VARCHAR, and the BLOB types from the TEXT types.