Re: Integer -> char
Posted in 1999
>
> I want to convert an integer value to char.
> Normally I am working with Oracle, there it is very simple to convert.
> ;-)
The same is with Informix.
But I didn't understand your question exactly. Do you want to update a table
and convert integer column to char?
You can do with the DDL statement ALTER TABLE. For example, for demo
database 'stores7' it'll be:
ALTER TABLE cust_calls MODIFY customer_num char(10);
If you want to extract an integer from a table and convert it to char in
another column or table, you can have only one problem: if char field does
not fit, ESQL/C will fill the string with asterisks, set a warning
(sqlca.sqlwarn.sqlwarn1 to W and SQLSTATE to 01004), and set any indicator
variable to a positive integer.
If you want to convert integer to a formatting string, you can use
rfmtlong().
It's the example for converting an integer to ITString class value using
Object Interface for C++ (from Informix SDK):
// ------------------------------------------------------------------
ITDBInfo dbinfo("stores7","ovc","alisa","****");
ITConnection con(dbinfo);
con.Open();
ITQuery q(con);
ITRow *row = q.ExecOneRow("select customer_num from cust_calls;");
ITValue *val = row->Column(0);
if(val->TypeOf().Name().Equal("integer")) cout << "The field is integer.\\n";
ITConversions *conv;
val->QueryInterface(ITConversionsIID, (void **) &conv);
ITString str;
conv->ConvertTo(str);
cout << str;
// ------------------------------------------------------------------
--
Best Regards,
Oleg V. Checherin
Tel: (416) 469-3962
Fax: (530) 687-6794
E-mail: ovc@mpei.ac.ru