From: rhh@tachy.uah.ualberta.ca (Roy Hann) Date: 6 Dec 1994 06:56:49 GMT helmc@sotovento.NoSubdomain.NoDomain (Hellawell M C) writes: : Help I am having problems reading integer and floating point numbers into an : sqlvar structure when I print out the contents of what sqldata is pointing : to I get either 0 or 0.0 Here is just a fraction of code that sets type : information : : case -IISQ_MNY_TYPE: : case IISQ_MNY_TYPE: : sqlda->sqlvar[x].sqltype = IISQ_FLT_TYPE; : sqlda->sqlvar[x].sqllen = sizeof(double); : sqlda->sqlvar[x].sqldata = (char *)calloc(1, sizeof(double)); : sqlda->sqlvar[x].sqlind = (short *)calloc(1, sizeof(short)); : break; : case -IISQ_INT_TYPE: : case IISQ_INT_TYPE: : sqlda->sqlvar[x].sqltype = IISQ_INT_TYPE; : sqlda->sqlvar[x].sqllen = sizeof(long); : sqlda->sqlvar[x].sqldata = (char *)calloc(1, sizeof(long)); : sqlda->sqlvar[x].sqlind = (short *)0; : break; A few potential gotchas spring to mind. The first thing that I notice you doing differently from what I do (which works), is that you are using "calloc". Just glancing at the documentation on an Ultrix box (which is where I happen to be reading this), it does not explicitly note that the space is allocated starting on a word boundary. If it does not force alignment, that could be a problem with some machines. Also, you are allocating space for each column individually. I don't have a manual handy to check if it's important, but I always figure out how big an area I need and then allocate a single contiguous chunk--that is probably more efficient anyway (if you care about milliseconds). Apart from that, the other two things that have got me in the past were: forgetting to allocate space for a short for the null indicator when the column is nullable, and not adding space to align character strings on 4-byte word boundaries. --Roy Hann
© William Yuan 2000
Email William