[Mono-bugs] [Bug 70228][Wis] New - SybaseClient bug on reading Decimal Fields
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Sun, 5 Dec 2004 13:05:26 -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 astevani@libero.it.
http://bugzilla.ximian.com/show_bug.cgi?id=70228
--- shadow/70228 2004-12-05 13:05:26.000000000 -0500
+++ shadow/70228.tmp.12068 2004-12-05 13:05:26.000000000 -0500
@@ -0,0 +1,77 @@
+Bug#: 70228
+Product: Mono: Class Libraries
+Version: 1.1
+OS: All
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: Sys.Data
+AssignedTo: mono-bugs@ximian.com
+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);
+
+ }