Skip to Content.
Sympa Menu

freetds - Re: Error in negative money values returned Linux/PHP4.0.x/MSSQL 6.5

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Brian Bruns <camber AT ais.org>
  • To: TDS Development Group <freetds AT franklin.oit.unc.edu>
  • Subject: Re: Error in negative money values returned Linux/PHP4.0.x/MSSQL 6.5
  • Date: Wed, 16 May 2001 21:23:37 -0400 (EDT)



Hi Andrew,

First I'd like to say thanks for the very well put together bug
report. Clear and concise. Others wanting help should take
note... I just checked the fix into CVS. If you want to apply it to 0.51
here it is:


in src/tds/numeric.c function tds_money_to_string()

replace:

for (i=7; i>=0; i--) {
number[7] += 1;
if (number[i]!=0) break;
}

with:

for (i=7; i>=0; i--) {
number[i] += 1;
if (number[i]!=0) break;
}

and you're on your way!

For the curious, multiples of 16 in two's complete have a last byte of 0
and thus it becomes 0xff when complemented. When adding 1 to the number
the field overflows to 0 (like it should) but never carried to the next
position.

Cheers,

Brian

On Wed, 16 May 2001, Andrew Bowman wrote:

>
> OS: Redhat 6.2
> Client: PHP Version 4.0.5-dev
> TDS: .51 (I think--i didn't build it--how do you check?)
> DB server: MS SQL Server 6.50.416
>
>
> I searched the archived mailing list and couldn't find anything about this
> problem.
>
> Here's my problem, and I can reproduce it. When I query on SQL Server 6.5
> money fields containing negative values that are multiples of 16, I get
> bogus results back. To test it, I wrote a php script that inserts
> sequential negative values in a money field and then retieves the same
> value immediately.
>
> As you can see, values up to 16 come back correctly.
>
> ID = 130073 Value = -1.00 DB = -1.0000
> ID = 130074 Value = -2.00 DB = -2.0000
> ID = 130075 Value = -3.00 DB = -3.0000
> ID = 130076 Value = -4.00 DB = -4.0000
> ID = 130077 Value = -5.00 DB = -5.0000
> ID = 130078 Value = -6.00 DB = -6.0000
> ID = 130079 Value = -7.00 DB = -7.0000
> ID = 130080 Value = -8.00 DB = -8.0000
> ID = 130081 Value = -9.00 DB = -9.0000
> ID = 130082 Value = -10.00 DB = -10.0000
> ID = 130083 Value = -11.00 DB = -11.0000
> ID = 130084 Value = -12.00 DB = -12.0000
> ID = 130085 Value = -13.00 DB = -13.0000
> ID = 130086 Value = -14.00 DB = -14.0000
> ID = 130087 Value = -15.00 DB = -15.0000
>
> 16 and all further multiples of 16 comback shy .0255.
>
> ID = 130088 Value = -16.00 DB = -15.9745
> ID = 130104 Value = -32.00 DB = -31.9745
> ID = 130120 Value = -48.00 DB = -47.9745
> ID = 130136 Value = -64.00 DB = -63.9745
> ID = 130152 Value = -80.00 DB = -79.9745
> ID = 130168 Value = -96.00 DB = -95.9745
> ID = 130184 Value = -112.00 DB = -111.9745
> ID = 130200 Value = -128.00 DB = -127.9745
> ID = 130216 Value = -144.00 DB = -143.9745
> ID = 130232 Value = -160.00 DB = -159.9745
> ID = 130248 Value = -176.00 DB = -175.9745
> ID = 130264 Value = -192.00 DB = -191.9745
> ID = 130280 Value = -208.00 DB = -207.9745
> ID = 130296 Value = -224.00 DB = -223.9745
> ID = 130312 Value = -240.00 DB = -239.9745
> ID = 130328 Value = -256.00 DB = -255.9745
> ID = 130344 Value = -272.00 DB = -271.9745
> ID = 130360 Value = -288.00 DB = -287.9745
> ID = 130376 Value = -304.00 DB = -303.9745
> ID = 130392 Value = -320.00 DB = -319.9745
> ID = 130408 Value = -336.00 DB = -335.9745
> ID = 130424 Value = -352.00 DB = -351.9745
>
> This only happens with negative values in money fields.
>
> Any suggestions? Let me know if you need more info.
>
> Thanks,
>
> Andrew
>





Archive powered by MHonArc 2.6.24.

Top of Page