Re: Dynamic SQL problems
Posted in 1998
On Wed, 23 Sep 1998 nezza@rocketmail.com wrote: > INFORMIX Dynamic SQL problem in ESQL/C. > > Could someone tell me why this is returning enexpected results for Datetime: > All the other data type conversions work fine, this doesn't why? > > It produces bad results. Probably because ESQL/C assumes that it only needs to send the dec_t part of a DATETIME (or INTERVAL) when the type in the sqlda structure is SQLDTIME or SQLINTRVL, primarily on the grounds that you already know the qualifier part. Did you allocate enough space for a dtime_t? If so, then you can fix it up with: ((dtime_t *)(pcol->sqldata))->dt_qual = pCol->sqllen; The sqllen member should contain the encoded precision information for the DATETIME column. If you didn't allocate enough space for a dtime_t, then create a local and initialize it: dtime_t local; local.dt_qual = pCol->sqllen; local.dt_dec = *((dec_t *)(pCol->sqldata)); nErrNo = dttoasc(&local, zsColData); You should also check the call to dttoasc -- where's the buffer which it is converting to? I simply translated your code, but I'm virtually certain you're missing an argument to dttoasc(). > pCol->sqldata has been allocated enough memory for storage. > dttoasc doesn't complain, but when i view the result, it's crap. > > > case SQLDTIME: > if ( *(pCol->sqlind) == 0 ) > { > nErrNo = dttoasc((dtime_t*)(pCol->sqldata), szColData); > > if ( nErrNo !=0 ) > { > fprintf(stderr, "SQLERROR %ld, Converting %s COLUMN, " > "File: %s, Line: %d\\n", nErrNo, > rtypname(pCol->sqltype), __FILE__, __LINE__); > return TRUE; > } > > /* ClipString( szColData ); */ > fputs(szColData, pUnlFile); > } > > fputs(pszDelimiter, pUnlFile); > break; > > Any help would be great. Yours, Jonathan Leffler (jleffler@informix.com) #include <witticism.h> Guardian of DBD::Informix v0.60 -- http://www.perl.com/CPAN Informix IDN for D4GL & Linux -- http://www.informix.com/idn