X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id BC367D1B4D5 for ; Mon, 5 Jan 2004 09:34:14 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 36170-07 for ; Mon, 5 Jan 2004 05:33:26 -0400 (AST) Received: from sd.tpf.co.jp (sd.tpf.co.jp [210.161.239.34]) by svr1.postgresql.org (Postfix) with SMTP id 98889D1B479 for ; Mon, 5 Jan 2004 05:33:23 -0400 (AST) Received: (qmail 10637 invoked from network); 5 Jan 2004 18:33:25 +0900 Received: from unknown (HELO viscomail.tpf.co.jp) (100.0.0.108) by sd2.tpf-fw-c.co.jp with SMTP; 5 Jan 2004 18:33:25 +0900 Received: from tpf.co.jp ([126.0.1.67]) by viscomail.tpf.co.jp (8.8.8+Sun/8.8.8) with ESMTP id SAA05346; Mon, 5 Jan 2004 18:33:24 +0900 (JST) Message-ID: <3FF93015.315FF61B@tpf.co.jp> Date: Mon, 05 Jan 2004 18:36:21 +0900 From: Hiroshi Inoue X-Mailer: Mozilla 4.73 [ja] (Windows NT 5.0; U) X-Accept-Language: ja MIME-Version: 1.0 To: "George A.J" Cc: pgsql-odbc@postgresql.org Subject: Re: Bug correction References: <20031231024542.24968.qmail@web14903.mail.yahoo.com> Content-Type: text/plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/7 X-Sequence-Number: 3636 "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; > }