Binary data written to MySQL table via ODBC is truncated

I have a MySQL database with a table containing a column BINARY(16).

When I write binary data via ODBC from my C ++ application, the data is processed as a string with a terminating zero, i.e. it is truncated in the first Null byte in the data.

In my C ++ application, I bind an array unsigned char [16]using SQLBindParameteras follows:

SQLBindParameter(statementHandler, paramCount, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_BINARY, MAX_NOTIFICATION_OUT_IP_BIN_LEN, 0, _notificationOutDstIP, MAX_NOTIFICATION_OUT_IP_BIN_LEN, 0);

MAX_NOTIFICATION_OUT_IP_BIN_LEN equal to 16.

How can I make sure that 16 bytes are written to the database, even if the binary data contains null values?

+3
source share
1 answer

From the MSDN documentation forSQLBindParameter :

StrLen_or_IndPtr , , NULL .

:

SQLBindParameter(statementHandler,
                 paramCount,
                 SQL_PARAM_INPUT,
                 SQL_C_BINARY, SQL_BINARY,
                 MAX_NOTIFICATION_OUT_IP_BIN_LEN,
                 0,
                 _notificationOutDstIP,
                 MAX_NOTIFICATION_OUT_IP_BIN_LEN,
                 &MAX_NOTIFICATION_OUT_IP_BIN_LEN
);
+2

All Articles