1

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?

apaderno
  • 28,547
  • 16
  • 75
  • 90
famedoro
  • 1,223
  • 2
  • 17
  • 41

1 Answers1

1

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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • Avoiding any kind of NULL values can be established when creating or altering tables. NULL values are a necessity in certain circumstances, such as in DATE and DATETIME columns which are best set to NULL in order to avoid incorrect date arithmetic calculations. The OP needs to examine how each column is used within the application in order to determine if a default zero value or a NULL is adequate. – Joe R. Aug 19 '12 at 12:53