String truncation

If an output string does not fit into the buffer, Db2 ODBC truncates the string to the size of the buffer and writes the nul-terminator. The string data can be truncated on input or output by using the appropriate SQLSTATE.

If truncation occurs, the function returns SQL_SUCCESS_WITH_INFO and SQLSTATE 01004, which indicates data truncation. The application can then compare the buffer length to the output length to determine which string was truncated.

For example, if SQLFetch() returns SQL_SUCCESS_WITH_INFO, and an SQLSTATE of 01004, at least one of the buffers bound to a column is too small to hold the data. For each buffer that is bound to a column, the application can compare the buffer length with the output length and determine which column was truncated.

ODBC specifies that string data can be truncated on input or output with the appropriate SQLSTATE. As the data source, Db2 does not truncate data on input, but might truncate data on output to maintain data integrity. On input, Db2 rejects string truncation with a negative SQLCODE (-302) and SQLSTATE 22001. On output, Db2 truncates the data and issues SQL_SUCCESS_WITH_INFO and SQLSTATE 01004.