CONNX Embedded SQL C-string Logic
When passing strings to and from CONNX Embedded SQL, the host variables have to be declared as arrays of data type char. One extra character space has to be declared to accommodate the \0 string terminator.
The CONNX Embedded SQL precompiler option "suppress trailing blanks (-b)" specifies whether the values returned from CONNX Embedded SQL will contain any trailing blanks before the terminator or not.
Passing data to CONNX Embedded SQL
When such a string variable is supplied to CONNX Embedded SQL, only characters up to \0 are significant and \0 is effectively removed from the string. The length of the string for SQL purposes is therefore up to - but not including - \0.
Should the variable not contain \0 then only the first n-1 characters are significant to CONNX Embedded SQL, where n is the declared length of the host variable character array. If such a variable is used to insert or update a field, then any discrepancies between the value length and the field length are corrected by either truncating the string or appending sufficient blanks at the end of the string.
Receiving data from CONNX Embedded SQL
When CONNX Embedded SQL assigns a string value to such a variable, e.g. in a FETCH statement, then \0 is appended to the value. This is the reason for reserving the last position of a character array for \0. Should the variable not provide enough space only the first n-1 characters are returned with \0 being added into the nth (last) position.
Should the field be smaller than the variable, blanks are appended between the end of the value and the \0 terminator in the final position. If, however, the precompiler option "suppress trailing blanks (-b)" is set, all string values returned from CONNX Embedded SQL come with trailing blanks removed. In this case, the \0 terminator is after the last non-blank character. Example:
EXEC SQL BEGIN DECLARE SECTION;
char h_surname [20];
EXEC SQL END DECLARE SECTION;