SQL to C: Binary
SQL_BINARY
The following table shows the ODBC C data types to which binary SQL data may
be converted. For an explanation of the columns and terms in the table, see
SQL_VARBINARY
SQL_LONGVARBINARY
C type identifier |
Test |
*TargetValuePtr | *StrLen_or
_IndPtr | SQL-
STATE |
SQL_C_CHAR | (Byte length of data) * 2 < BufferLength
(Byte length of data) * 2 >= BufferLength | Data
Truncated data | Length of data in bytes
Length of data in bytes | n/a
01004 |
SQL_C_BINARY | Byte length of data <= BufferLength
Byte length of data > BufferLength | Data
Truncated data | Length of data in bytes
Length of data in bytes | n/a
01004 |
The driver always converts individual bytes to pairs of hexadecimal digits and terminates the character string with a null byte. Because of this, if BufferLength is even and is less than the length of the converted data, the last byte of the *TargetValuePtr buffer is not used. (The converted data requires an even number of bytes, the next-to-last byte is a null byte, and the last byte cannot be used.)
Note Application developers are discouraged from binding binary SQL data to a character C data type. This conversion is usually inefficient and slow.