hostvars and NULL-values
Posted in 1999
Topics: Data Types & Schema Design
I want to insert empty strings (hostvar-type VARCHAR, columntype VARCHAR) in to a column. Unfortunately, this specific row will contain a NULL value. When I do a SELECT for this row again, I will retrieve an error, which I can suppress. But what I want to know is, can I be sure to retrieve an empty string again or is the result undefined ? Or is there a way to insert empty strings without creating a NULL value. The trouble is that I can't fill these strings with a space before the insert statement (It would be too much work) and I don't want informix to pad the strings with spaces as it would be the case with CHAR types. I need empty strings as a result. Thanks in advance, Pascal
ProzessDV wrote: > > I want to insert empty strings (hostvar-type VARCHAR, columntype VARCHAR) in to > a column. Unfortunately, this specific row will contain a NULL value. When I do > a SELECT for this row again, I will retrieve an error, which I can suppress. > But what I want to know is, can I be sure to retrieve an empty string again or > is the result undefined ? > Or is there a way to insert empty strings without creating a NULL value. The > trouble is that I can't fill these strings with a space before the insert > statement (It would be too much work) and I don't want informix to pad the > strings with spaces as it would be the case with CHAR types. I need empty > strings as a result. Unfortunately, Informix stores a NULL as the first character of any char or varchar column to indicate that the column contains a NULL for that row. The best way to handle this is to declare an indicator variable for the host variable into which you are fetching the varchar then check the indicator and handle it appropriately. Ex: EXEC SQL BEGIN DECLARE SECTION; varchar value[10]; short i_value; ... EXEC SQL END DECLARE SECTION; ... ... FETCH acursor INTO :value : i_value; if (i_value < 0) value[0] = (char)0; ... ... Art S. Kagel