RE: ESQL/C and date/datetimes
Posted in 1998
---------- Arun Shastry apparently wrote: > Jonathan Leffler wrote: > > Arun Shastry wrote: > > > I hope Informix is planning on providing more functions/features in > > > their next ESQL/C release with regards to date/datetime fields > > > manipulation. > > > What they currently have in 7.2 is totally inadequate and buggy. > > > > Inadequate, maybe. Buggy? Justify this assertion! > > Is it just me or are you getting defensive here Jon :-) I'm not sure. I was trying to get some concrete information from you, rather than vague assertions. I'm more curious than defensive, because I've done more with DATETIME and INTERVAL than most people and I have not yet run into either bugs or inadequacies which I regarded as insurmountable. Maybe I have a bigger tolerance for stupidities than you do. I've been working with Informix products long enough that it could be I'm too used to what there is (and what there isn't) than you are, and that I'm not sufficiently aware of what the alternatives could be to miss the stuff that's not available in Informix - what the eye doesn't see, the heart doesn't grieve over. But I was quite prepared to accept arguments of inadequacy; I was really wanting to know what bugs you have found. Anyway, I'm sorry if I was defensive; I would genuinely like to know what you are seeking. If you want improvements made, you surely have some suggestions about what needs to be provided? > Try this for starters: Example code? > Two datetime year to minute variables - 1997-07-31 15:33, 1997-08-06 > 10:21. O Convert them to decimal using rinvtodec Timeout! Why are we converting datetime values with interval routines? Intervals and datetimes are not interchangeable logically, even though they have the same general memory layout at the C level. And what values are you expecting from the conversion? Also, where do you find documentation on rinvtodec() - it isn't in my 7.2 ESQL/C manual or the 9.1 ESQL/C manual as far as I can see. This is not a fundamental objection, unlike the question of what the conversion is supposed to do; it is merely exposing my ignorance of a particular function, its purpose and its interface. O Convert the decimals to long (1997-08-06 10:21 will overflow. Why?) Again, what values are you expecting? And if the values overflow, then all further operations are invalid, aren't they? Why not compare the decimals, anyway, using the decimal arithmetic routines? > Convert the decimals to double > 1997-07-31 15:33 gives you 34563813, 1997-08-06 10:21 gives you 34528941 > So we just proved that 1997-07-31 15:33 > 1997-08-06 10:21 Actually, I don't think you've proved anything yet, unless it is that arguing from false premises allows you to reach any conclusion. But, I don't yet have enough information from you to be positive about anything, especially not your conclusion. That isn't meant to be inflammatory - consider this a repeated request for specific information, with some amplification of what I think is needed as the specific information. I'd like to know about the interface to rinvtodec(), and I'd like to know what you think rinvtodec() will convert your DATETIME values into. And I'd be curious to see your code. And I'd like you to expand on what you think should be provided in the way of facilities. Yours, Jonathan Leffler (jleffler@visa.com) #include <bother.ms-exchange.h> PS: I guess you are trying to compare two DATETIME YEAR TO MINUTE values to see which is bigger. My code to do this would be as follows. When I ran it on Solaris 2.5.1 and ESQL/C 7.23.UC4, I got the output: decimal value of t1 = 19970731153300 decimal value of t2 = 19970806102100 t1 is less than t2 This seems correct to me, and wasn't very hard, primarily because the qualifiers of the two values was the same. If the qualifiers had been different, then the comparison would not be valid, of course. #include <stdio.h> #include <datetime.h> #include <decimal.h> int main(void) { dtime_t t1; dtime_t t2; int rc; char buff[60]; t1.dt_qual = t2.dt_qual = TU_DTENCODE(TU_YEAR, TU_MINUTE); if ((rc = dtcvasc("1997-07-31 15:33", &t1)) != 0) { printf("conversion 1 failed: rc = %d\\n", rc); exit(1); } if ((rc = dtcvasc("1997-08-06 10:21", &t2)) != 0) { printf("conversion 2 failed: rc = %d\\n", rc); exit(1); } if ((rc = dectoasc(&t1.dt_dec, buff, sizeof(buff) - 1, 0)) < 0) { printf("conversion 3 failed: rc = %d\\n", rc); exit(1); } printf("decimal value of t1 = %s\\n", buff); if ((rc = dectoasc(&t2.dt_dec, buff, sizeof(buff) - 1, 0)) < 0) { printf("conversion 4 failed: rc = %d\\n", rc); exit(1); } printf("decimal value of t2 = %s\\n", buff); rc = deccmp(&t1.dt_dec, &t2.dt_dec); if (rc == -1) printf("t1 is less than t2\\n"); else if (rc == 0) printf("t1 is equal to t2\\n"); else if (rc == 1) printf("t1 is greater than t2\\n"); else printf("comparison failed or a value is null\\n"); return 0; }