Re: How to initialize fields
Posted in 2012
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
On Thu, Aug 16, 2012 at 12:00 AM, Francesco Alfano <edacedpa@yahoo.it>wrote: > How can I write a routine in Esql/C which initialize to 0 (zero) all > numeric fields (smallint, decimal, etc) and to (' ') space the other > fields in a table? > You've been given answers. I'm going to raise the types not covered by your question, notably the date and time types. Zeroing a DATE gives you 1899-12-31. Zeroing an INTERVAL is fine. Zeroing a DATETIME gives you an error; so does blanking it. What about BYTE and TEXT and BLOB and CLOB and ... You don't have to respond to this question — you probably should think about it enough that you know what you want to do with these types when they appear. -- Jonathan Leffler <jonathan.leffler@gmail.com> #include <disclaimer.h> Guardian of DBD::Informix - v2011.0612 - http://dbi.perl.org "Blessed are we who can laugh at ourselves, for we shall never cease to be amused."
Jonathan Leffler <jonathan.leffler@gmail.com> wrote: > Zeroing a DATETIME gives you an error; so does blanking it you can use TU_DTENCODE macro (see datetime.h) to fix this generating a structure clearing macro for your tables: 1. memset whole structure with zeroes 2. use TU_DTENCODE to encode precision in dt_qual field of datetime structure (see also #define TU_YEAR up to TU_F5) 3. rsetnull datetime fields to get the proper arguments for TU_DTENCODE you need a syscolumns.collength value and some simple calculations