"George A.J" wrote:
>
> Hi,
> i don't know how to send a fix in the diff format so i am sending the
> corected file.
> i have changed the function ResolveNumericParam() in the file
> convert.c
> the function is given billow. i have commented the added/deleted
> lines. also attaching the file convert.c.
The first bug (0.0 -> .) is fixed in CVS already.
I would fix the second bug (.009 -> .9) according to
your code.
regards,
Hiroshi Inoue
> static BOOL
> ResolveNumericParam(const SQL_NUMERIC_STRUCT *ns, char *chrform)
> {
> static const int prec[] = {1, 3, 5, 8, 10, 13, 15, 17, 20, 22, 25,
> 29, 32, 34, 37, 39};
> Int4 i, j, k, ival, vlen, len, newlen;
> unsigned char calv[40];
> const unsigned char *val = (const unsigned char *) ns->val;
> BOOL next_figure;
>
> if (0 == ns->precision)
> {
> strcpy(chrform, "0");
> return TRUE;
> }
> else if (ns->precision < prec[sizeof(Int4)])
> {
> for (i = 0, ival = 0; i < sizeof(Int4) && prec[i] <= ns->precision;
> i++)
> {
> ival += (val[i] << (8 * i)); /* ns->val is little endian */
> }
> if (0 == ns->scale)
> {
> if (0 == ns->sign)
> ival *= -1;
> sprintf(chrform, "%d", ival);
> }
> else if (ns->scale > 0)
> {
> Int4 i, div, o1val, o2val;
>
> for (i = 0, div = 1; i < ns->scale; i++)
> div *= 10;
> o1val = ival / div;
> o2val = ival % div;
> if (0 == ns->sign)
> o1val *= -1;
> sprintf(chrform, "%d.%0.*d", o1val, ns->scale, o2val);
> }
> return TRUE;
> }
>
> for (i = 0; i < SQL_MAX_NUMERIC_LEN && prec[i] <= ns->precision; i++)
> ;
> vlen = i;
> len = 0;
> memset(calv, 0, sizeof(calv));
> for (i = vlen - 1; i >= 0; i--)
> {
> for (j = len - 1; j >= 0; j--)
> {
> if (!calv[j])
> continue;
> ival = (((Int4)calv[j]) << 8);
> calv[j] = (ival % 10);
> ival /= 10;
> calv[j + 1] += (ival % 10);
> ival /= 10;
> calv[j + 2] += (ival % 10);
> ival /= 10;
> calv[j + 3] += ival;
> for (k = j;; k++)
> {
> next_figure = FALSE;
> if (calv[k] > 0)
> {
> if (k >= len)
> len = k + 1;
> while (calv[k] > 9)
> {
> calv[k + 1]++;
> calv[k] -= 10;
> next_figure = TRUE;
> }
> }
> if (k >= j + 3 && !next_figure)
> break;
> }
> }
> ival = val[i];
> if (!ival)
> continue;
> calv[0] += (ival % 10);
> ival /= 10;
> calv[1] += (ival % 10);
> ival /= 10;
> calv[2] += ival;
> for (j = 0;; j++)
> {
> next_figure = FALSE;
> if (calv[j] > 0)
> {
> if (j >= len)
> len = j + 1;
> while (calv[j] > 9)
> {
> calv[j + 1]++;
> calv[j] -= 10;
> next_figure = TRUE;
> }
> }
> if (j >= 2 && !next_figure)
> break;
> }
> }
>
> /********* New code:*/
>
> /*Added to fix the numeric convertion bug.
> BUG:When 0.0 is the input function returns '.' Also if 0.0009 is
> input
> the fnction returns '.9'*/
>
> if (len <= ns->scale)
> len = ns->scale + 1;
>
> /********* End New code: */
>
> newlen = 0;
> if (0 == ns->sign)
> chrform[newlen++] = '-';
> for (i = len - 1; i >= ns->scale; i--)
> chrform[newlen++] = calv[i] + '0';
> if (ns->scale > 0)
> {
> chrform[newlen++] = '.';
> for (; i >= 0; i--)
> chrform[newlen++] = calv[i] + '0';
> }
>
> /********* deleted code:*/
>
> /*deleted to fix the numeric convertion bug. these lines are not
> needed
> if (0 == len)
> chrform[newlen++] = '0';*/
> /********* end deleted code:*/
>
> chrform[newlen] = '\0';
> return TRUE;
> }