[Mono-bugs] [Bug 77410][Maj] New - SybaseParameter,
Scale throws an InvalidCastException
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Mon Jan 30 16:03:18 EST 2006
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 sebastien.robitaille at croesus.com.
http://bugzilla.ximian.com/show_bug.cgi?id=77410
--- shadow/77410 2006-01-30 16:03:18.000000000 -0500
+++ shadow/77410.tmp.1216 2006-01-30 16:03:18.000000000 -0500
@@ -0,0 +1,91 @@
+Bug#: 77410
+Product: Mono: Class Libraries
+Version: 1.1
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Major
+Component: Sys.Data
+AssignedTo: tsenganal at novell.com
+ReportedBy: sebastien.robitaille at croesus.com
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: SybaseParameter,Scale throws an InvalidCastException
+
+Description of Problem:
+
+When using the Mono.Data.Sybase provider,
+I have a problem when using a decimal SybaseParameter with a scale of
+zero and a DBNull value.
+
+The following exception is thrown when accessing the
+SybaseParameter.Scale getter:
+
+an exception of type: {System.InvalidCastException} occurred
+
+
+After looking at the code (Mono.Data.Tds.TdsMetaParameter.cs),
+I realized that the exception is thrown because a conversion is executed
+everytime the Scale property is accessed, but there are no test to
+validate that Value is not the DBNull.Value.
+
+Please, refer to the following code snippet from the TdsMetaParameter.cs
+file:
+
+public byte Scale {
+ get {
+ if (TypeName == "decimal" || TypeName == "numeric") {
+ if (scale == 0) {
+ int[] arr = Decimal.GetBits (
+ Convert.ToDecimal(Value));
+ scale = (byte)((arr[3]>>16) & (int)0xFF);
+ }
+ }
+ return scale;
+ }
+ set { scale = value; }
+}
+
+A quick fix would be to test for Convert.IsDbNull(Value):
+
+public byte Scale {
+ get {
+ if (TypeName == "decimal" || TypeName == "numeric") {
+ if (scale == 0 && !Convert.IsDbNull(Value)) {
+ int[] arr = Decimal.GetBits (
+ Convert.ToDecimal(Value));
+ scale = (byte)((arr[3]>>16) & (int)0xFF);
+ }
+ }
+ return scale;
+ }
+ set { scale = value; }
+}
+
+
+Steps to reproduce the problem:
+1. Execute the following code:
+
+IDbDataParameter prm = myCommand.CreateParameter();
+prm.Value = DBNull.Value;
+prm.ParameterName = "@MyParam";
+prm.DbType = DbType.Decimal;
+prm.Precision = 10;
+prm.Scale = 0;
+
+byte myScale = prm.Scale; // Throws an exception.
+
+Actual Results:
+Exception thrown.
+
+Expected Results:
+No Exception. Zero returned by the Scale parameter.
+
+How often does this happen?
+Always.
+
+Additional Information:
More information about the mono-bugs
mailing list