Character data

 

Input parameters that refer to variable-length character data (such as column names, dynamic parameters, and string attribute values) have an associated length parameter. If the application terminates strings with the null character, as is typical in C, then it provides either the length in bytes of the string (not including the null-terminator) or SQL_NTS (Null-Terminated String) as an argument. A non-negative length argument specifies the actual length of the associated string. The length argument may be 0 to specify a zero-length string. This is different from a NULL value. The negative value SQL_NTS directs the driver to determine the length of the string by locating the null-termination character. This option is not very useful in Fortran, because Fortran character strings are not NULL terminated. However, for compatibility reasons,  f90SQL offers this option.

 

When character data is returned from the driver to the application, the driver always null-terminates it. If the application buffer is not large enough to return all of the character data, the driver truncates it to the byte length of the buffer, less the number of bytes required by the null-termination character. Then it null-terminates the truncated data, and stores it in the buffer. Thus, applications must always allocate extra space for the null-termination character in buffers used to retrieve character data. For example, a 51-byte buffer is needed to retrieve 50 characters of data. This also applies to Fortran applications.  In most cases, f90SQL will take care of formatting the strings such that the null terminator is removed and strings are space-padded, as expected by Fortran. The few exceptions are clearly identified in the reference section of this manual.