Informix ESQL/C — How to initialize fields?

284 views Asked by At

How can I write a routine in ESQL/C which will initialize to 0 (zero) all numeric fields (smallint, decimal, etc) and to a space the other fields in a table?

1

There are 1 answers

1
Jonathan Leffler On

You asked this question on one of the IIUG (International Informix Users Group) mailing lists, and received answers there.

As I mentioned when I responded this morning, you need to think rather carefully about some of the types you don't mention. Zeroing a DATE sets it to 1899-12-31. Zeroing an INTERVAL makes sense (though you don't do it by setting all bytes zero; a similar comment applies to DECIMAL and MONEY and related types). Zeroing a DATETIME generates an invalid value. And BYTE, TEXT, BLOB, CLOB have separate sets of issues.

Setting character fields to a space is easy enough. Setting integer fields of various sorts to zero is also easy enough.

You can look at the code in either Art Kagel's utils2_ak package or in my SQLCMD package, both available from the IIUG Software Archive. They have code that cover many of the situations you're likely to encounter.

If they're not sufficient to help, then you need to show the code you're having problems with, explaining what is happening, what you want to happen, and (if appropriate) any messages your getting that are preventing it happening.