newsuser@efd.lth.se (News server connection) (11/28/90)
Is it possible to have null-terminated character strings in a character column? The ESQL/C manual mention that it is possible. But my strings gets filled with spaces up to the length of the column. Is there a way to do this? -- Joergen Haegg jh@efd.lth.se postmaster@efd.lth.se System manager @ efd 046-107492 Lund Institute of Technology Sweden
barton@cbnewsk.att.com (jim.m.barton) (11/29/90)
In article <1990Nov28.110715.22247@lth.se>, newsuser@efd.lth.se (News server connection) writes: > > Is it possible to have null-terminated character strings > in a character column? The ESQL/C manual mention that it is possible. > But my strings gets filled with spaces up to the length of the column. > > Is there a way to do this? Yes. INFORMIX ESQL/C supports a psuedo datatype, "string", to be used for host variables for this sitution. Host variables declared as "string" are generated as a normal "char" variables in the C code but signal to the DBMS to suppress trailing blanks AND terminate with an end-of-string when making assignments to those host variables. Example, Suppose we have a table: create table name_table ( name char(100) ); insert into name_table(name) values("SMITH "); The following code should retrieve name_table.name using a "string" host variable: $ string name_value[101]; /* Note added byte for end-of-string */ $ select name into :name_value from name_table; printf("name is '%s'\n", name_value); The result should be: name is 'SMITH'
davek@informix.com (David Kosenko) (11/30/90)
In article <1990Nov28.110715.22247@lth.se> jh@efd.lth.se (Joergen Haegg) writes: > >Is it possible to have null-terminated character strings >in a character column? The ESQL/C manual mention that it is possible. >But my strings gets filled with spaces up to the length of the column. > >Is there a way to do this? Yes. You want to declare your host variables as type string, e.g. $string foo[25]; When you fetch or select into a host variable declared as type string, no blank-padding will occur and the string will be null-terminated. If the string seleted is longer than the host variable size, it will contain n-1 (where n is the size of the string variable) characters and the null character, and, if used, the indicator variable will be set to indicate that truncation occurred. Dave Kosenko Informix Client Services -- Disclaimer: These opinions make no sense and should be ignored! ************************************************************************** The heart and the mind on a parallel course, never the two shall meet. -E. Saliers