Re: R: datetime type data
Posted in 1993
>From: gm0564@swuts.sbc.com (George Ma) >Subject: Re: datetime type data >Date: 14 Sep 93 13:40:24 GMT >X-Informix-List-Id: <news.4327> > >Jonathan: >I used the same way to load data to sqlda as you showed in your program. >However, the problem was not there. The problem occurred when I called > dttoasc((dtime_t *)col->sqldata, buf); > /* buf is a char string with size of 26 */ > >The data placed into buf was incorrect. The Informix version I'm using is >4.10. Could that be the problem? > >George Ma No, that shouldn't be the problem. I had no problems with 4.10 once I'd got the correct amount of data space allocated and aligned correctly. The code I use for printing the datetime/interval types is: case CDTIMETYPE: case SQLDTIME: case CINVTYPE: case SQLINTERVAL: if (col->sqltype == CDTIMETYPE || col->sqltype == SQLDTIME) dttoasc((Datetime *)col->sqldata, buffer); else intoasc((Interval *)col->sqldata, buffer); str = buffer; if (formt != OP_FIXED) str = skipblanks(buffer); else { p = rtypwidth(col->sqltype, col->sqllen) + 1; jlss_stchar(buffer, buffer, p); } output(str, QUOTE_NONE); break; The second half of that (from str = buffer) is dealing with the minutiae of the output for my program which gets unduly fussy about fixed width output fields. Datetime is a typedef of dtime_t; what I have looks remarkably like your code. Are you sure you have your memory allocation set up right? What do you get if you do a dump of the sqlda structure? What do you get if you do a dump of the components of the dtime_t structure? What do you get if you convert the dec_t part of the dtime_t structure as a decimal: /* Uncompiled code */ dtime_t dt = (dtime_t *)col->sqldata; dectoasc(&dt->dt_dec, buffer, sizeof(buffer), 5); You should get a decimal value which is recognisably related to the value you are expecting to see. Yours in some puzzlement, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>