[Mono-bugs] [Bug 70228][Nor] Changed - SybaseClient bug on reading Decimal Fields

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Wed, 12 Jan 2005 20:50:38 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by danielmorgan@verizon.net.

http://bugzilla.ximian.com/show_bug.cgi?id=70228

--- shadow/70228	2005-01-12 20:48:37.000000000 -0500
+++ shadow/70228.tmp.24600	2005-01-12 20:50:38.000000000 -0500
@@ -0,0 +1,83 @@
+Bug#: 70228
+Product: Mono: Class Libraries
+Version: 1.0
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: Unknown
+Priority: Normal
+Component: Sys.Data
+AssignedTo: danielmorgan@verizon.net                            
+ReportedBy: astevani@libero.it               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: SybaseClient bug on reading Decimal Fields
+
+Description of Problem:
+bug on SybaseClient data library on reading query with decimal fields with 
+lenght not multiple of 4 bytes
+
+Steps to reproduce the problem:
+1. Reading a query with decimal fields
+
+Actual Results:
+The library throw an exception
+
+Expected Results:
+Reading query
+
+How often does this happen? 
+Always
+
+Additional Information:
+
+I fix the problem rewriting the function GetDecimalValue in the class
+Mono.Data.Tds.Protocol.Tds
+
+		private object GetDecimalValue (byte precision, byte scale)
+		{
+			int[] bits = new int[4] {0,0,0,0};
+
+			int len = (comm.GetByte() & 0xff);
+			if (len == 0)
+				return DBNull.Value;
+
+			byte[] dec_bytes=comm.GetBytes(len,false);	
+		
+			byte[] easy=new byte[4];
+
+			bool positive = dec_bytes[0]==1;
+
+			if (len > 17)
+				throw new OverflowException ();
+
+			for (int i = 1, index = 0; i < len && i < 16; i += 
+4, index += 1) 
+			{
+				for(int j=0; j<4; j++)
+					if(i+j<len)
+						easy[j]=dec_bytes[len-
+(i+j)];
+					else
+						easy[j]=0;
+				if(!BitConverter.IsLittleEndian)
+					easy=comm.Swap(easy);
+				bits[index] = BitConverter.ToInt32(easy,0);
+			}
+			if (bits [3] != 0) 
+				return new TdsBigDecimal (precision, 
+scale, !positive, bits);
+			else
+				return new Decimal(bits[0], bits[1], bits
+[2], !positive, scale);
+			
+		}
+
+------- Additional Comments From sebastien.robitaille@croesus.com  2005-01-02 04:13 -------
+I can reproduce this bug with mono-1.0.4.
+
+------- Additional Comments From danielmorgan@verizon.net  2005-01-12 20:50 -------
+Do you have a simple repeatable test case?