Forráskód Böngészése

2002-11-07 Ville Palo <[email protected]>

	* System.Data.SqlTypes/SqlBinary.cs:
	* System.Data.SqlTypes/SqlBoolean.cs:
	* System.Data.SqlTypes/SqlByte.cs:
	* System.Data.SqlTypes/SqlDateTime.cs:
	* System.Data.SqlTypes/SqlDecimal.cs:
	* System.Data.SqlTypes/SqlDouble.cs:
	* System.Data.SqlTypes/SqlDecimal.cs:
	* System.Data.SqlTypes/SqlGuid.cs:
	* System.Data.SqlTypes/SqlInt16.cs:
	* System.Data.SqlTypes/SqlInt32.cs:
	* System.Data.SqlTypes/SqlInt64.cs:
	* System.Data.SqlTypes/SqlMoney.cs:
	* System.Data.SqlTypes/SqlSingle.cs:
	* System.Data.SqlTypes/SqlString.cs: Implemented more methods and
	fixed some. SqlBoolean Equals (object value) -method improvements to
	all classes.

svn path=/trunk/mcs/; revision=8873
Ville Palo 23 éve
szülő
commit
3eefaba65e

+ 19 - 0
mcs/class/System.Data/ChangeLog

@@ -1,3 +1,22 @@
+2002-11-07  Ville Palo <[email protected]>
+
+	* System.Data.SqlTypes/SqlBinary.cs:
+	* System.Data.SqlTypes/SqlBoolean.cs:
+	* System.Data.SqlTypes/SqlByte.cs:
+	* System.Data.SqlTypes/SqlDateTime.cs:
+	* System.Data.SqlTypes/SqlDecimal.cs:
+	* System.Data.SqlTypes/SqlDouble.cs:
+	* System.Data.SqlTypes/SqlDecimal.cs:
+	* System.Data.SqlTypes/SqlGuid.cs:
+	* System.Data.SqlTypes/SqlInt16.cs:
+	* System.Data.SqlTypes/SqlInt32.cs:
+	* System.Data.SqlTypes/SqlInt64.cs:
+	* System.Data.SqlTypes/SqlMoney.cs:
+	* System.Data.SqlTypes/SqlSingle.cs:
+	* System.Data.SqlTypes/SqlString.cs: Implemented more methods and 
+	fixed some. SqlBoolean Equals (object value) -method improvements to
+	all classes.
+	
 2002-11-07  Tim Coleman <[email protected]>
 	* System.Data.Common/DbDataAdapter.cs:
 		Remove NotImplementedException in Dispose

+ 3 - 0
mcs/class/System.Data/System.Data.SqlTypes/SqlBinary.cs

@@ -4,6 +4,7 @@
 // Author:
 //   Rodrigo Moya ([email protected])
 //   Tim Coleman ([email protected])
+//   Ville Palo ([email protected])
 //
 // (C) Ximian, Inc.
 // (C) Copyright 2002 Tim Coleman
@@ -100,6 +101,8 @@ namespace System.Data.SqlTypes
 		{
 			if (!(value is SqlBinary))
 				return false;
+			else if (this.IsNull && ((SqlBinary)value).IsNull)
+				return true;
 			else if (((SqlBinary)value).IsNull)
 				return false;
 			else

+ 58 - 34
mcs/class/System.Data/System.Data.SqlTypes/SqlBoolean.cs

@@ -118,7 +118,11 @@ namespace System.Data.SqlTypes
 
 		public override bool Equals(object value) 
 		{
-			if (!(value is SqlByte))
+			if (!(value is SqlBoolean))
+				return false;
+			if (this.IsNull && ((SqlBoolean)value).IsNull)
+				return true;
+			else if (((SqlBoolean)value).IsNull)
 				return false;
 			else
 				return (bool) (this == (SqlBoolean)value);
@@ -319,79 +323,99 @@ namespace System.Data.SqlTypes
 		// SqlByte to SqlBoolean
 		public static explicit operator SqlBoolean (SqlByte x) 
 		{
-			if (x.IsNull)
-				return Null;
-			else
-				return new SqlBoolean ((int)x.Value);
+			checked {
+				if (x.IsNull)
+					return Null;
+				else
+					return new SqlBoolean ((int)x.Value);
+			}
 		}
 
 		// SqlDecimal to SqlBoolean
 		public static explicit operator SqlBoolean (SqlDecimal x) 
 		{
-			if (x.IsNull)
-				return Null;
-			else
-				return new SqlBoolean ((int)x.Value);
+			checked {
+				if (x.IsNull)
+					return Null;
+				else
+					return new SqlBoolean ((int)x.Value);
+			}
 		}
 		
 		// SqlDouble to SqlBoolean
 		public static explicit operator SqlBoolean (SqlDouble x) 
 		{
-			if (x.IsNull)
-				return Null;
-			else
-				return new SqlBoolean ((int)x.Value);
+			// FIXME
+			//checked {
+				if (x.IsNull)
+					return Null;
+				else
+					return new SqlBoolean ((int)x.Value);
+				//}
 		}
 
 		// SqlInt16 to SqlBoolean
 		public static explicit operator SqlBoolean (SqlInt16 x) 
 		{
-			if (x.IsNull)
-				return Null;
-			else
-				return new SqlBoolean ((int)x.Value);
+			checked {
+				if (x.IsNull)
+					return Null;
+				else
+					return new SqlBoolean ((int)x.Value);
+			}
 		}
 
 		// SqlInt32 to SqlBoolean
 		public static explicit operator SqlBoolean (SqlInt32 x) 
 		{
-			if (x.IsNull)
-				return Null;
-			else
-				return new SqlBoolean (x.Value);
+			checked {
+				if (x.IsNull)
+					return Null;
+				else
+					return new SqlBoolean (x.Value);
+			}
 		}
 
 		// SqlInt64 to SqlBoolean
 		public static explicit operator SqlBoolean (SqlInt64 x) 
 		{
-			if (x.IsNull)
-				return Null;
-			else
-				return new SqlBoolean ((int)x.Value);
+			checked {
+				if (x.IsNull)
+					return Null;
+				else
+					return new SqlBoolean ((int)x.Value);
+			}
 		}
 
 		// SqlMoney to SqlBoolean
 		public static explicit operator SqlBoolean (SqlMoney x) 
 		{
-			if (x.IsNull)
-				return Null;
-			else
-				return new SqlBoolean ((int)x.Value);
+			checked {
+				if (x.IsNull)
+					return Null;
+				else
+					return new SqlBoolean ((int)x.Value);
+			}
 		}
 
 		// SqlSingle to SqlBoolean
 		public static explicit operator SqlBoolean (SqlSingle x) 
 		{
-			if (x.IsNull)
-				return Null;
-			else
-				return new SqlBoolean ((int)x.Value);
+			// FIXME
+			//checked {
+				if (x.IsNull)
+					return Null;
+				else
+					return new SqlBoolean ((int)x.Value);
+				//}
 		}
 
 		// SqlString to SqlBoolean
 		public static explicit operator SqlBoolean (SqlString x) 
 		{
-			return SqlBoolean.Parse (x.Value);
+			checked {
+				return SqlBoolean.Parse (x.Value);
+			}
 		}
 
 		// Boolean to SqlBoolean

+ 50 - 35
mcs/class/System.Data/System.Data.SqlTypes/SqlByte.cs

@@ -91,6 +91,10 @@ namespace System.Data.SqlTypes
 		{
 			if (!(value is SqlByte))
 				return false;
+			else if (this.IsNull && ((SqlByte)value).IsNull)
+				 return true;
+			else if (((SqlByte)value).IsNull)
+				return false;
 			else
 				return (bool) (this == (SqlByte)value);
 		}
@@ -234,7 +238,9 @@ namespace System.Data.SqlTypes
 
 		public static SqlByte operator / (SqlByte x, SqlByte y)
 		{
-			return new SqlByte ((byte) (x.Value / y.Value));
+			checked {
+				return new SqlByte ((byte) (x.Value / y.Value));
+			}
 		}
 
 		public static SqlBoolean operator == (SqlByte x, SqlByte y)
@@ -329,74 +335,83 @@ namespace System.Data.SqlTypes
 
 		public static explicit operator SqlByte (SqlDecimal x)
 		{
-			if (x.IsNull)
-				return Null;
-			else 
-				return new SqlByte ((byte)x.Value);
-
+			checked {
+				if (x.IsNull)
+					return Null;
+				else 
+					return new SqlByte ((byte)x.Value);
+			}
 		}
 
 		public static explicit operator SqlByte (SqlDouble x)
 		{
-			if (x.IsNull)
-				return Null;
-			else 				
-				return new SqlByte ((byte)x.Value);
+			// FIXME
+			//			checked {
+				if (x.IsNull)
+					return Null;
+				else 					
+					return new SqlByte ((byte)x.Value);
+				//}
 		}
 
 		public static explicit operator SqlByte (SqlInt16 x)
 		{
-			if (x.IsNull)
-				return Null;
-			else {
-				checked {
+			checked {
+				if (x.IsNull)
+					return Null;
+				else 			       
 					return new SqlByte ((byte)x.Value);
-				}
 			}
 		}
 
 		public static explicit operator SqlByte (SqlInt32 x)
 		{
-			if (x.IsNull)
-				return Null;
-			else {
-				checked {
+			checked {
+				if (x.IsNull)
+					return Null;
+				else 			       
 					return new SqlByte ((byte)x.Value);
-				}
 			}
 		}
 
 		public static explicit operator SqlByte (SqlInt64 x)
 		{
-			if (x.IsNull)
-				return Null;
-			else
-				return new SqlByte ((byte)x.Value);
+			// FIXME
+			//checked {
+				if (x.IsNull)
+					return Null;
+				else
+					return new SqlByte ((byte)x.Value);
+				//}
 		}
 
 		public static explicit operator SqlByte (SqlMoney x)
 		{
-			if (x.IsNull)
-				return Null;
-			else {
-				checked {
+			checked {
+				if (x.IsNull)
+					return Null;
+				else 					
 					return new SqlByte ((byte)x.Value);
-				}
 			}
 		}
 
 		public static explicit operator SqlByte (SqlSingle x)
 		{
-			if (x.IsNull)
-				return Null;
-			else
-				return new SqlByte (checked((byte)x.Value));
+			// FIXME:
+			//checked {
+				if (x.IsNull)
+					return Null;
+				else
+					return new SqlByte ((byte)x.Value);
+				//}
 		}
 
 
 		public static explicit operator SqlByte (SqlString x)
-		{
-			return SqlByte.Parse (x.Value);
+		{			
+			checked {
+				return SqlByte.Parse (x.Value);
+			}
 		}
 
 		public static implicit operator SqlByte (byte x)

+ 5 - 0
mcs/class/System.Data/System.Data.SqlTypes/SqlDateTime.cs

@@ -3,6 +3,7 @@
 //
 // Author:
 //   Tim Coleman <[email protected]>
+//   Ville Palo <[email protected]>
 //
 // (C) Copyright 2002 Tim Coleman
 //
@@ -112,6 +113,10 @@ namespace System.Data.SqlTypes
 		{
 			if (!(value is SqlDateTime))
 				return false;
+			else if (this.IsNull && ((SqlDateTime)value).IsNull)
+				return true;
+			else if (((SqlDateTime)value).IsNull)
+				return false;
 			else
 				return (bool) (this == (SqlDateTime)value);
 		}

+ 158 - 51
mcs/class/System.Data/System.Data.SqlTypes/SqlDecimal.cs

@@ -3,6 +3,7 @@
 //
 // Author:
 //   Tim Coleman <[email protected]>
+//   Ville Palo <[email protected]>
 //
 // (C) Copyright 2002 Tim Coleman
 //
@@ -30,9 +31,24 @@ namespace System.Data.SqlTypes
 		const int RESERVED_SS32_BITS = 0x7F00FFFF;
 
 		public static readonly byte MaxPrecision = 38; 
-		public static readonly byte MaxScale = 28;
-		public static readonly SqlDecimal MaxValue = new SqlDecimal (79228162514264337593543950335.0);
-		public static readonly SqlDecimal MinValue = new SqlDecimal (-79228162514264337593543950335.0);
+		public static readonly byte MaxScale = 38;
+
+		// This sould be 1E+38-1
+		public static readonly SqlDecimal MaxValue = new SqlDecimal (MaxPrecision, 
+									     (byte)0, 
+									     true, 
+									     (int)716002642, 
+									     (int)2858073428, 
+									     (int)1518778966, 
+									     (int)1262177448);
+		// This should be -1E+38
+		public static readonly SqlDecimal MinValue = new SqlDecimal (MaxPrecision, 
+									     (byte)0, false,
+									     (int)716002642, 
+									     (int)2858073428, 
+									     (int)1518778966, 
+									     (int)1262177448);
+
 		public static readonly SqlDecimal Null;
 
 		#endregion
@@ -50,21 +66,29 @@ namespace System.Data.SqlTypes
 			if (this.scale > MaxScale || ((uint)binData [3] & RESERVED_SS32_BITS) != 0)
 				throw new ArgumentException(Locale.GetText ("Invalid scale"));
 
-			this.positive = ((binData[3] >> SIGN_SHIFT) > 0);
 			this.value = new int[4];
 			this.value[0] = binData[0];
 			this.value[1] = binData[1];
 			this.value[2] = binData[2];
 			this.value[3] = 0;
+
+			if (value >= 0)
+				positive = true;
+			else 
+				positive = false;
+
+			precision = GetPrecision (value);
+
 			notNull = true;
 		}
-
+				
 		public SqlDecimal (double value) : this ((decimal)value) { }
 		public SqlDecimal (int value) : this ((decimal)value) { }
 		public SqlDecimal (long value) : this ((decimal)value) { }
 
 		public SqlDecimal (byte bPrecision, byte bScale, bool fPositive, int[] bits) : this (bPrecision, bScale, fPositive, bits[0], bits[1], bits[2], bits[3]) { }
 
+		[MonoTODO]
 		public SqlDecimal (byte bPrecision, byte bScale, bool fPositive, int data1, int data2, int data3, int data4) 
 		{
 			this.precision = bPrecision;
@@ -76,15 +100,33 @@ namespace System.Data.SqlTypes
 			this.value[2] = data3;
 			this.value[3] = data4;
 			notNull = true;
+
+			// FIXME: What is the right message of Exception
+			if (this.ToDouble () > (Math.Pow (10, 38) - 1)  || 
+			    this.ToDouble () < -(Math.Pow (10, 38)))
+				throw new SqlTypeException ("Can't convert to SqlDecimal");
 		}
 
 		#endregion
 
 		#region Properties
 
-		[MonoTODO]
 		public byte[] BinData {
-			get { throw new NotImplementedException (); }
+			get { 
+
+				byte [] b = new byte [value.Length * 4];
+				
+				int j = 0;
+				for (int i = 0; i < value.Length; i++) {
+
+					b [j++] = (byte)(0xff & value [i]);
+					b [j++] = (byte)(0xff & value [i] >> 8);
+					b [j++] = (byte)(0xff & value [i] >> 16);
+					b [j++] = (byte)(0xff & value [i] >> 24);
+				}
+
+				return b;
+			}
 		}
 
 		public int[] Data { 
@@ -120,7 +162,7 @@ namespace System.Data.SqlTypes
 				if (this.value[3] > 0)
 					throw new OverflowException ();
 
-				return new decimal (value[0], value[1], value[2], positive, scale);
+				return new decimal (value[0], value[1], value[2], !positive, scale);
 			}
 		}
 
@@ -128,10 +170,11 @@ namespace System.Data.SqlTypes
 
 		#region Methods
 
-		[MonoTODO]
 		public static SqlDecimal Abs (SqlDecimal n)
 		{
-			throw new NotImplementedException();
+				return new SqlDecimal (n.Precision, n.Scale, true, 
+						       n.BinData [0], n.BinData [1], 
+						       n.BinData [2], n.BinData [3]);
 		}
 
 		public static SqlDecimal Add (SqlDecimal x, SqlDecimal y)
@@ -139,16 +182,22 @@ namespace System.Data.SqlTypes
 			return (x + y);
 		}
 
-		[MonoTODO]
 		public static SqlDecimal AdjustScale (SqlDecimal n, int digits, bool fRound)
 		{
-			throw new NotImplementedException ();
+			if (n.IsNull)
+				throw new SqlNullValueException ();
+
+			if (fRound)
+				n = Round (n, digits + n.Scale);
+
+			return new SqlDecimal ((byte)(n.Precision + digits), 
+					       (byte)(n.Scale + digits), 
+					       n.IsPositive, n.Data);
 		}
 
-		[MonoTODO]
 		public static SqlDecimal Ceiling (SqlDecimal n)
 		{
-			throw new NotImplementedException();
+			return AdjustScale (n, -(n.Scale), true);
 		}
 
 		public int CompareTo (object value)
@@ -163,10 +212,9 @@ namespace System.Data.SqlTypes
 				return this.Value.CompareTo (((SqlDecimal)value).Value);
 		}
 
-		[MonoTODO]
 		public static SqlDecimal ConvertToPrecScale (SqlDecimal n, int precision, int scale)
 		{
-			throw new NotImplementedException ();
+			return new SqlDecimal ((byte)precision, (byte)scale, n.IsPositive, n.Data);
 		}
 
 		public static SqlDecimal Divide (SqlDecimal x, SqlDecimal y)
@@ -178,6 +226,10 @@ namespace System.Data.SqlTypes
 		{
 			if (!(value is SqlDecimal))
 				return false;
+			else if (this.IsNull && ((SqlDecimal)value).IsNull)
+				return true;			
+			else if (((SqlDecimal)value).IsNull)
+				return false;
 			else
 				return (bool) (this == (SqlDecimal)value);
 		}
@@ -187,10 +239,9 @@ namespace System.Data.SqlTypes
 			return (x == y);
 		}
 
-		[MonoTODO]
 		public static SqlDecimal Floor (SqlDecimal n)
 		{
-			throw new NotImplementedException ();
+			return AdjustScale (n, -(n.Scale), false);
 		}
 
 		internal static SqlDecimal FromTdsBigDecimal (TdsBigDecimal x)
@@ -203,7 +254,15 @@ namespace System.Data.SqlTypes
 
 		public override int GetHashCode ()
 		{
-			return (int)this.Value;
+			int result = 10;
+			result = 91 * result + this.Data[0];
+			result = 91 * result + this.Data[1];
+			result = 91 * result + this.Data[2];
+			result = 91 * result + this.Data[3];
+			result = 91 * result + (int)this.Scale;
+			result = 91 * result + (int)this.Precision;
+
+			return result;
 		}
 
 		public static SqlBoolean GreaterThan (SqlDecimal x, SqlDecimal y)
@@ -239,25 +298,46 @@ namespace System.Data.SqlTypes
 		[MonoTODO]
 		public static SqlDecimal Parse (string s)
 		{
-			throw new NotImplementedException ();		       
+			// FIXME: Huh, There must be better way to do this
+			if (s == null)
+				throw new ArgumentNullException ();
+			else 
+				return SqlDouble.Parse (s).ToSqlDecimal ();
 		}
 
-		[MonoTODO]
 		public static SqlDecimal Power (SqlDecimal n, double exp)
 		{
-			throw new NotImplementedException ();
+			if (n.IsNull)
+				return SqlDecimal.Null;
+
+			return new SqlDecimal (Math.Pow (n.ToDouble (), exp));
 		}
 
 		[MonoTODO]
 		public static SqlDecimal Round (SqlDecimal n, int position)
 		{
-			throw new NotImplementedException ();
+			// FIXME: There must be better way to do this
+			if (n.IsNull)
+				throw new SqlNullValueException ();
+
+			SqlDecimal result = new SqlDecimal (Math.Round (
+				(double)(n.ToDouble () * Math.Pow (10, position))));
+
+			result = result / new SqlDecimal(Math.Pow (10, position));
+			
+			return result;				
 		}
 
-		[MonoTODO]
 		public static SqlInt32 Sign (SqlDecimal n)
 		{
-			throw new NotImplementedException ();
+			SqlInt32 result = 0;
+
+			if (n >= new SqlDecimal (0))
+				result = 1;
+			else
+				result = -1;
+
+			return result;
 		}
 
 		public static SqlDecimal Subtract (SqlDecimal x, SqlDecimal y)
@@ -265,9 +345,29 @@ namespace System.Data.SqlTypes
 			return (x - y);
 		}
 
+		private byte GetPrecision (decimal value)
+		{
+			string str = value.ToString ();
+			byte result = 0;
+
+			foreach (char c in str) {
+				
+				if (c >= '0' && c <= '9')
+					result++;
+			}
+			
+			return result;
+		}
+
 		public double ToDouble ()
 		{
-			return ((double)this.Value);
+			// FIXME: This is wrong way to do this
+			double d = this.Data [0];
+			d += ((uint)this.Data [1]) << 32;
+			d += ((uint)this.Data [2]) << 64;
+			d += ((uint)this.Data [3]) << 96;
+
+			return d;
 		}
 
 		public SqlBoolean ToSqlBoolean ()
@@ -323,10 +423,9 @@ namespace System.Data.SqlTypes
 				return value.ToString ();
 		}
 
-		[MonoTODO]
 		public static SqlDecimal Truncate (SqlDecimal n, int position)
 		{
-			throw new NotImplementedException ();
+			return AdjustScale (n, position - n.Scale, false);
 		}
 
 		public static SqlDecimal operator + (SqlDecimal x, SqlDecimal y)
@@ -375,10 +474,11 @@ namespace System.Data.SqlTypes
 				return new SqlDecimal (resultPrecision, x.Scale, x.IsPositive, resultBits);
 		}
 
-		[MonoTODO]
 		public static SqlDecimal operator / (SqlDecimal x, SqlDecimal y)
 		{
-			throw new NotImplementedException ();
+			checked {
+				return (x.ToSqlDouble () / y.ToSqlDouble ()).ToSqlDecimal ();
+			}
 		}
 
 		public static SqlBoolean operator == (SqlDecimal x, SqlDecimal y)
@@ -387,9 +487,9 @@ namespace System.Data.SqlTypes
 				return SqlBoolean.Null;
 
 			if (x.Scale > y.Scale)
-				x = SqlDecimal.AdjustScale(x, y.Scale - x.Scale, true);
+				y = SqlDecimal.AdjustScale(y, x.Scale - y.Scale, false);
 			else if (y.Scale > x.Scale)
-				y = SqlDecimal.AdjustScale(y, x.Scale - y.Scale, true);
+				x = SqlDecimal.AdjustScale(y, y.Scale - x.Scale, false);
 
 			for (int i = 0; i < 4; i += 1)
 			{
@@ -405,11 +505,11 @@ namespace System.Data.SqlTypes
 				return SqlBoolean.Null;
 
 			if (x.Scale > y.Scale)
-				x = SqlDecimal.AdjustScale(x, y.Scale - x.Scale, true);
+				y = SqlDecimal.AdjustScale(y, x.Scale - y.Scale, false);
 			else if (y.Scale > x.Scale)
-				y = SqlDecimal.AdjustScale(y, x.Scale - y.Scale, true);
+				x = SqlDecimal.AdjustScale(x, y.Scale - x.Scale, false);
 
-			for (int i = 3; i >= 0; i -= 1)
+			for (int i = 3; i >= 0; i--)
 			{
 				if (x.Data[i] == 0 && y.Data[i] == 0) 
 					continue;
@@ -425,9 +525,9 @@ namespace System.Data.SqlTypes
 				return SqlBoolean.Null;
 
 			if (x.Scale > y.Scale)
-				x = SqlDecimal.AdjustScale(x, y.Scale - x.Scale, true);
-			else if (y.Scale > x.Scale)
 				y = SqlDecimal.AdjustScale(y, x.Scale - y.Scale, true);
+			else if (y.Scale > x.Scale)
+				x = SqlDecimal.AdjustScale(x, y.Scale - x.Scale, true);
 
 			for (int i = 3; i >= 0; i -= 1)
 			{
@@ -459,13 +559,14 @@ namespace System.Data.SqlTypes
 
 		public static SqlBoolean operator < (SqlDecimal x, SqlDecimal y)
 		{
+
 			if (x.IsNull || y.IsNull) 
 				return SqlBoolean.Null;
 
 			if (x.Scale > y.Scale)
-				x = SqlDecimal.AdjustScale(x, y.Scale - x.Scale, true);
-			else if (y.Scale > x.Scale)
 				y = SqlDecimal.AdjustScale(y, x.Scale - y.Scale, true);
+			else if (y.Scale > x.Scale)
+				x = SqlDecimal.AdjustScale(x, y.Scale - x.Scale, true);
 
 			for (int i = 3; i >= 0; i -= 1)
 			{
@@ -475,6 +576,7 @@ namespace System.Data.SqlTypes
 				return new SqlBoolean (x.Data[i] < y.Data[i]);
 			}
 			return new SqlBoolean (false);
+
 		}
 
 		public static SqlBoolean operator <= (SqlDecimal x, SqlDecimal y)
@@ -483,9 +585,9 @@ namespace System.Data.SqlTypes
 				return SqlBoolean.Null;
 
 			if (x.Scale > y.Scale)
-				x = SqlDecimal.AdjustScale(x, y.Scale - x.Scale, true);
-			else if (y.Scale > x.Scale)
 				y = SqlDecimal.AdjustScale(y, x.Scale - y.Scale, true);
+			else if (y.Scale > x.Scale)
+				x = SqlDecimal.AdjustScale(x, y.Scale - x.Scale, true);
 
 			for (int i = 3; i >= 0; i -= 1)
 			{
@@ -580,23 +682,29 @@ namespace System.Data.SqlTypes
 
 		public static explicit operator SqlDecimal (SqlDouble x)
 		{
-			if (x.IsNull) 
-				return Null;
-			else
-				return new SqlDecimal ((decimal)x.Value);
+			checked {
+				if (x.IsNull) 
+					return Null;
+				else
+					return new SqlDecimal ((decimal)x.Value);
+			}
 		}
 
 		public static explicit operator SqlDecimal (SqlSingle x)
 		{
-			if (x.IsNull) 
-				return Null;
-			else
-				return new SqlDecimal ((decimal)x.Value);
+			checked {
+				if (x.IsNull) 
+					return Null;
+				else
+					return new SqlDecimal ((decimal)x.Value);
+			}
 		}
 
 		public static explicit operator SqlDecimal (SqlString x)
 		{
-			return Parse (x.Value);
+			checked {
+				return Parse (x.Value);
+			}
 		}
 
 		public static implicit operator SqlDecimal (decimal x)
@@ -647,4 +755,3 @@ namespace System.Data.SqlTypes
 		#endregion
 	}
 }
-			

+ 21 - 9
mcs/class/System.Data/System.Data.SqlTypes/SqlDouble.cs

@@ -3,6 +3,7 @@
 //
 // Author:
 //   Tim Coleman <[email protected]>
+//   Ville Palo <[email protected]>
 //
 // (C) Copyright 2002 Tim Coleman
 //
@@ -19,8 +20,8 @@ namespace System.Data.SqlTypes
 
 		private bool notNull;
 
-		public static readonly SqlDouble MaxValue = new SqlDouble (1.7976931348623157e308);
-		public static readonly SqlDouble MinValue = new SqlDouble (-1.7976931348623157e308);
+		public static readonly SqlDouble MaxValue = new SqlDouble (1.7976931348623157E+308);
+		public static readonly SqlDouble MinValue = new SqlDouble (-1.7976931348623157E+308);
 		public static readonly SqlDouble Null;
 		public static readonly SqlDouble Zero = new SqlDouble (0);
 
@@ -81,6 +82,10 @@ namespace System.Data.SqlTypes
 		{
 			if (!(value is SqlDouble))
 				return false;
+			if (this.IsNull && ((SqlDouble)value).IsNull)
+				return true;
+			else if (((SqlDouble)value).IsNull)
+				return false;
 			else
 				return (bool) (this == (SqlDouble)value);
 		}
@@ -89,7 +94,6 @@ namespace System.Data.SqlTypes
 		{
 			return (x == y);
 		}
-
 		public override int GetHashCode ()
 		{
 			long LongValue = (long)value;
@@ -199,7 +203,9 @@ namespace System.Data.SqlTypes
 
 		public static SqlDouble operator / (SqlDouble x, SqlDouble y)
 		{
-			return new SqlDouble (x.Value / y.Value);
+			checked {
+				return new SqlDouble (x.Value / y.Value);
+			}
 		}
 
 		public static SqlBoolean operator == (SqlDouble x, SqlDouble y)
@@ -252,16 +258,20 @@ namespace System.Data.SqlTypes
 
 		public static SqlDouble operator * (SqlDouble x, SqlDouble y)
 		{
-			return new SqlDouble (x.Value * y.Value);
+			checked {
+				return new SqlDouble (x.Value * y.Value);
+			}
 		}
 
 		public static SqlDouble operator - (SqlDouble x, SqlDouble y)
 		{
-			return new SqlDouble (x.Value - y.Value);
+			checked {
+				return new SqlDouble (x.Value - y.Value);
+			}
 		}
 
 		public static SqlDouble operator - (SqlDouble n)
-		{
+		{			
 			return new SqlDouble (-(n.Value));
 		}
 
@@ -280,7 +290,9 @@ namespace System.Data.SqlTypes
 
 		public static explicit operator SqlDouble (SqlString x)
 		{
-			return SqlDouble.Parse (x.Value);
+			checked {
+				return SqlDouble.Parse (x.Value);
+			}
 		}
 
 		public static implicit operator SqlDouble (double x)
@@ -301,7 +313,7 @@ namespace System.Data.SqlTypes
 			if (x.IsNull) 
 				return Null;
 			else
-				return new SqlDouble ((double)x.Value);
+				return new SqlDouble (x.ToDouble ());
 		}
 
 		public static implicit operator SqlDouble (SqlInt16 x)

+ 5 - 0
mcs/class/System.Data/System.Data.SqlTypes/SqlGuid.cs

@@ -3,6 +3,7 @@
 //
 // Author:
 //   Tim Coleman <[email protected]>
+//   Ville Palo <[email protected]>
 //
 // (C) Copyright 2002 Tim Coleman
 //
@@ -87,6 +88,10 @@ namespace System.Data.SqlTypes
 		{
 			if (!(value is SqlGuid))
 				return false;
+			else if (this.IsNull && ((SqlGuid)value).IsNull)
+				return true;
+			else if (((SqlGuid)value).IsNull)
+				return false;
 			else
 				return (bool) (this == (SqlGuid)value);
 		}

+ 50 - 40
mcs/class/System.Data/System.Data.SqlTypes/SqlInt16.cs

@@ -3,6 +3,7 @@
 //
 // Author:
 //   Tim Coleman <[email protected]>
+//   Ville Palo <[email protected]>
 //
 // (C) Copyright 2002 Tim Coleman
 //
@@ -91,8 +92,12 @@ namespace System.Data.SqlTypes
 		{
 			if (!(value is SqlInt16))
 				return false;
+			else if (this.IsNull && ((SqlInt16)value).IsNull)
+				return true;
+			else if (((SqlInt16)value).IsNull)
+				return false;
 			else
-				return (bool) (this == (SqlInt16)value);
+				return (bool)(this == (SqlInt16)value);
 		}
 
 		public static SqlBoolean Equals (SqlInt16 x, SqlInt16 y)
@@ -237,7 +242,9 @@ namespace System.Data.SqlTypes
 
 		public static SqlInt16 operator / (SqlInt16 x, SqlInt16 y)
 		{
-			return new SqlInt16 ((short) (x.Value / y.Value));
+			checked {
+				return new SqlInt16 ((short) (x.Value / y.Value));
+			}
 		}
 
 		public static SqlBoolean operator == (SqlInt16 x, SqlInt16 y)
@@ -322,7 +329,9 @@ namespace System.Data.SqlTypes
 
 		public static SqlInt16 operator - (SqlInt16 n)
 		{
-			return new SqlInt16 ((short) (-n.Value));
+			checked {
+				return new SqlInt16 ((short) (-n.Value));
+			}
 		}
 
 		public static explicit operator SqlInt16 (SqlBoolean x)
@@ -334,19 +343,23 @@ namespace System.Data.SqlTypes
 		}
 
 		public static explicit operator SqlInt16 (SqlDecimal x)
-		{			
-			if (x.IsNull)
-				return Null;
-			else 
-				return new SqlInt16 ((short)x.Value);
+		{		
+			checked {
+				if (x.IsNull)
+					return Null;
+				else 
+					return new SqlInt16 ((short)x.Value);
+			}
 		}
 
 		public static explicit operator SqlInt16 (SqlDouble x)
 		{
-			if (x.IsNull)
-				return Null;
-			else
-				return new SqlInt16 (checked ((short)x.Value));
+			//			checked {
+				if (x.IsNull)
+					return Null;
+				else 
+					return new SqlInt16 (checked ((short)x.Value));
+				//}
 		}
 
 		public static explicit operator short (SqlInt16 x)
@@ -356,52 +369,52 @@ namespace System.Data.SqlTypes
 
 		public static explicit operator SqlInt16 (SqlInt32 x)
 		{
-			if (x.IsNull)
-				return Null;
-			else {
-				checked {
+			checked {
+				if (x.IsNull)
+					return Null;
+				else 
 					return new SqlInt16 ((short)x.Value);
-				}
 			}
 		}
 
 		public static explicit operator SqlInt16 (SqlInt64 x)
 		{
-			if (x.IsNull)
-				return Null;
-			else {
-				//				checked {
+			//checked {
+				if (x.IsNull)
+					return Null;
+				else
 					return new SqlInt16 ((short)x.Value);
-				//}
-			}
+				//		}
 		}
 
 		public static explicit operator SqlInt16 (SqlMoney x)
 		{
-			if (x.IsNull)
-				return Null;
-			else {
-				checked {
+			checked {
+				if (x.IsNull)
+					return Null;
+				else 
 					return new SqlInt16 ((short)x.Value);
-				}
-			}
+			}			
 		}
 
 
 		public static explicit operator SqlInt16 (SqlSingle x)
 		{
-			if (x.IsNull)
-				return Null;
-			else {
-				//	checked {
+			// FIXME
+			//checked {
+				if (x.IsNull)
+					return Null;
+				else 
 					return new SqlInt16 ((short)x.Value);
 				//}
-			}
 		}
 
 		public static explicit operator SqlInt16 (SqlString x)
-		{		       			
-			return SqlInt16.Parse (x.Value);		
+		{	
+			if (x.IsNull)
+				return Null;
+
+			return SqlInt16.Parse (x.Value);
 		}
 
 		public static implicit operator SqlInt16 (short x)
@@ -411,10 +424,7 @@ namespace System.Data.SqlTypes
 
 		public static implicit operator SqlInt16 (SqlByte x)
 		{
-			if (x.IsNull)
-				return Null;
-			else
-				return new SqlInt16 ((short)x.Value);
+			return new SqlInt16 ((short)x.Value);
 		}
 
 		#endregion

+ 53 - 26
mcs/class/System.Data/System.Data.SqlTypes/SqlInt32.cs

@@ -5,6 +5,7 @@
 //   Rodrigo Moya ([email protected])
 //   Daniel Morgan ([email protected])
 //   Tim Coleman ([email protected])
+//   Ville Palo ([email protected])
 //
 // (C) Ximian, Inc. 2002
 // (C) Copyright 2002 Tim Coleman 
@@ -99,6 +100,10 @@ namespace System.Data.SqlTypes
 		{
 			if (!(value is SqlInt32))
 				return false;
+			else if (this.IsNull && ((SqlInt32)value).IsNull)
+				return true;
+			else if (((SqlInt32)value).IsNull)
+				return false;
 			else
 				return (bool) (this == (SqlInt32)value);
 		}
@@ -228,7 +233,9 @@ namespace System.Data.SqlTypes
 		// Compute Addition
 		public static SqlInt32 operator + (SqlInt32 x, SqlInt32 y) 
 		{
-			return new SqlInt32 (x.Value + y.Value);
+			checked {
+				return new SqlInt32 (x.Value + y.Value);
+			}
 		}
 
 		// Bitwise AND
@@ -240,13 +247,17 @@ namespace System.Data.SqlTypes
 		// Bitwise OR
 		public static SqlInt32 operator | (SqlInt32 x, SqlInt32 y) 
 		{
-			return new SqlInt32 (x.Value | y.Value);
+			checked {
+				return new SqlInt32 (x.Value | y.Value);
+			}
 		}
 
 		// Compute Division
 		public static SqlInt32 operator / (SqlInt32 x, SqlInt32 y) 
 		{
-			return new SqlInt32 (x.Value / y.Value);
+			checked {
+				return new SqlInt32 (x.Value / y.Value);
+			}
 		}
 
 		// Compare Equality
@@ -318,7 +329,9 @@ namespace System.Data.SqlTypes
 		// Compute Multiplication
 		public static SqlInt32 operator * (SqlInt32 x, SqlInt32 y) 
 		{
-			return new SqlInt32 (x.Value * y.Value);
+			checked {
+				return new SqlInt32 (x.Value * y.Value);
+			}
 		}
 
 		// Ones Complement
@@ -330,7 +343,9 @@ namespace System.Data.SqlTypes
 		// Subtraction
 		public static SqlInt32 operator - (SqlInt32 x, SqlInt32 y) 
 		{
-			return new SqlInt32 (x.Value - y.Value);
+			checked {
+				return new SqlInt32 (x.Value - y.Value);
+			}
 		}
 
 		// Negates the Value
@@ -350,18 +365,22 @@ namespace System.Data.SqlTypes
 
 		public static explicit operator SqlInt32 (SqlDecimal x) 
 		{
-			if (x.IsNull) 
-				return Null;
-			else 
-				return new SqlInt32 ((int)x.Value);
+			checked {
+				if (x.IsNull) 
+					return Null;
+				else 
+					return new SqlInt32 ((int)x.Value);
+			}
 		}
 
 		public static explicit operator SqlInt32 (SqlDouble x) 
 		{
-			if (x.IsNull) 
-				return Null;
-			else 
-				return new SqlInt32 ((int)x.Value);
+			checked {
+				if (x.IsNull) 
+					return Null;
+				else 
+					return new SqlInt32 ((int)x.Value);
+			}
 		}
 
 		public static explicit operator int (SqlInt32 x)
@@ -371,31 +390,39 @@ namespace System.Data.SqlTypes
 
 		public static explicit operator SqlInt32 (SqlInt64 x) 
 		{
-			if (x.IsNull) 
-				return Null;
-			else 
-				return new SqlInt32 ((int)x.Value);
+			checked {
+				if (x.IsNull) 
+					return Null;
+				else 
+					return new SqlInt32 ((int)x.Value);
+			}
 		}
 
 		public static explicit operator SqlInt32(SqlMoney x) 
 		{
-			if (x.IsNull) 
-				return Null;
-			else 
-				return new SqlInt32 ((int)x.Value);
+			checked {
+				if (x.IsNull) 
+					return Null;
+				else 
+					return new SqlInt32 ((int)x.Value);
+			}
 		}
 
 		public static explicit operator SqlInt32(SqlSingle x) 
 		{
-			if (x.IsNull) 
-				return Null;
-			else 
-				return new SqlInt32 ((int)x.Value);
+			checked {
+				if (x.IsNull) 
+					return Null;
+				else 
+					return new SqlInt32 ((int)x.Value);
+			}
 		}
 
 		public static explicit operator SqlInt32(SqlString x) 
 		{
-			return SqlInt32.Parse (x.Value);
+			checked {
+				return SqlInt32.Parse (x.Value);
+			}
 		}
 
 		public static implicit operator SqlInt32(int x) 

+ 38 - 18
mcs/class/System.Data/System.Data.SqlTypes/SqlInt64.cs

@@ -3,6 +3,7 @@
 //
 // Author:
 //   Tim Coleman <[email protected]>
+//   Ville Palo <[email protected]>
 //
 // (C) Copyright 2002 Tim Coleman
 //
@@ -93,6 +94,10 @@ namespace System.Data.SqlTypes
 		{
 			if (!(value is SqlInt64))
 				return false;
+			else if (this.IsNull && ((SqlInt64)value).IsNull)
+				return true;
+			else if (((SqlInt64)value).IsNull)
+				return false;
 			else
 				return (bool) (this == (SqlInt64)value);
 		}
@@ -240,7 +245,9 @@ namespace System.Data.SqlTypes
 
 		public static SqlInt64 operator / (SqlInt64 x, SqlInt64 y)
 		{
-			return new SqlInt64 (x.Value / y.Value);
+			checked {
+				return new SqlInt64 (x.Value / y.Value);
+			}
 		}
 
 		public static SqlBoolean operator == (SqlInt64 x, SqlInt64 y)
@@ -310,6 +317,9 @@ namespace System.Data.SqlTypes
 
 		public static SqlInt64 operator ~ (SqlInt64 x)
 		{
+			if (x.IsNull)
+				return SqlInt64.Null;
+
 			return new SqlInt64 (~(x.Value));
 		}
 
@@ -335,18 +345,22 @@ namespace System.Data.SqlTypes
 
 		public static explicit operator SqlInt64 (SqlDecimal x)
 		{
-			if (x.IsNull) 
-				return SqlInt64.Null;
-			else
-				return new SqlInt64 ((long)x.Value);
+			checked {
+				if (x.IsNull) 
+					return SqlInt64.Null;
+				else
+					return new SqlInt64 ((long)x.Value);
+			}
 		}
 
 		public static explicit operator SqlInt64 (SqlDouble x)
 		{
-			if (x.IsNull) 
-				return SqlInt64.Null;
-			else
-				return new SqlInt64 ((long)x.Value);
+			//checked {
+				if (x.IsNull) 
+					return SqlInt64.Null;
+				else
+					return new SqlInt64 ((long)x.Value);
+				//}
 		}
 
 		public static explicit operator long (SqlInt64 x)
@@ -356,23 +370,29 @@ namespace System.Data.SqlTypes
 
 		public static explicit operator SqlInt64 (SqlMoney x)
 		{
-			if (x.IsNull) 
-				return SqlInt64.Null;
-			else
-				return new SqlInt64 ((long)x.Value);
+			checked {
+				if (x.IsNull) 
+					return SqlInt64.Null;
+				else
+					return new SqlInt64 ((long)x.Value);
+			}
 		}
 
 		public static explicit operator SqlInt64 (SqlSingle x)
 		{
-			if (x.IsNull) 
-				return SqlInt64.Null;
-			else
-				return new SqlInt64 ((long)x.Value);
+			//checked {
+				if (x.IsNull) 
+					return SqlInt64.Null;
+				else
+					return new SqlInt64 ((long)x.Value);
+				//}
 		}
 
 		public static explicit operator SqlInt64 (SqlString x)
 		{
-			return SqlInt64.Parse (x.Value);
+			checked {
+				return SqlInt64.Parse (x.Value);
+			}
 		}
 
 		public static implicit operator SqlInt64 (long x)

+ 46 - 23
mcs/class/System.Data/System.Data.SqlTypes/SqlMoney.cs

@@ -3,6 +3,7 @@
 //
 // Author:
 //   Tim Coleman <[email protected]>
+//   Ville Palo <[email protected]>
 //
 // (C) Copyright 2002 Tim Coleman
 //
@@ -20,8 +21,8 @@ namespace System.Data.SqlTypes
 		
 		private bool notNull;
 
-		public static readonly SqlMoney MaxValue = new SqlMoney (922337203685477.5807);
-		public static readonly SqlMoney MinValue = new SqlMoney (-922337203685477.5808);
+		public static readonly SqlMoney MaxValue = new SqlMoney (922337203685477.5807m);
+		public static readonly SqlMoney MinValue = new SqlMoney (-922337203685477.5808m);
 		public static readonly SqlMoney Null;
 		public static readonly SqlMoney Zero = new SqlMoney (0);
 
@@ -101,6 +102,10 @@ namespace System.Data.SqlTypes
 		{
 			if (!(value is SqlMoney))
 				return false;
+			if (this.IsNull && ((SqlMoney)value).IsNull)
+				return true;
+			else if (((SqlMoney)value).IsNull)
+				return false;
 			else
 				return (bool) (this == (SqlMoney)value);
 		}
@@ -235,12 +240,16 @@ namespace System.Data.SqlTypes
 
 		public static SqlMoney operator + (SqlMoney x, SqlMoney y)
 		{
-			return new SqlMoney (x.Value + y.Value);
+			checked {
+				return new SqlMoney (x.Value + y.Value);
+			}
 		}
 
 		public static SqlMoney operator / (SqlMoney x, SqlMoney y)
 		{
-			return new SqlMoney (x.Value / y.Value);
+			checked {
+				return new SqlMoney (x.Value / y.Value);
+			}
 		}
 
 		public static SqlBoolean operator == (SqlMoney x, SqlMoney y)
@@ -291,12 +300,16 @@ namespace System.Data.SqlTypes
 
 		public static SqlMoney operator * (SqlMoney x, SqlMoney y)
 		{
-			return new SqlMoney (x.Value * y.Value);
+			checked {
+				return new SqlMoney (x.Value * y.Value);
+			}
 		}
 
 		public static SqlMoney operator - (SqlMoney x, SqlMoney y)
 		{
-			return new SqlMoney (x.Value - y.Value);
+			checked {
+				return new SqlMoney (x.Value - y.Value);
+			}
 		}
 
 		public static SqlMoney operator - (SqlMoney n)
@@ -306,26 +319,32 @@ namespace System.Data.SqlTypes
 
 		public static explicit operator SqlMoney (SqlBoolean x)
 		{
-			if (x.IsNull) 
-				return Null;
-			else
-				return new SqlMoney ((decimal)x.ByteValue);
+			checked {
+				if (x.IsNull) 
+					return Null;
+				else
+					return new SqlMoney ((decimal)x.ByteValue);
+			}
 		}
 
 		public static explicit operator SqlMoney (SqlDecimal x)
 		{
-			if (x.IsNull) 
-				return Null;
-			else
-				return new SqlMoney (x.Value);
+			checked {
+				if (x.IsNull) 
+					return Null;
+				else
+					return new SqlMoney (x.Value);
+			}
 		}
 
 		public static explicit operator SqlMoney (SqlDouble x)
 		{
-			if (x.IsNull) 
-				return Null;
-			else
-				return new SqlMoney ((decimal)x.Value);
+			checked {
+				if (x.IsNull) 
+					return Null;
+				else
+					return new SqlMoney ((decimal)x.Value);
+			}
 		}
 
 		public static explicit operator decimal (SqlMoney x)
@@ -335,15 +354,19 @@ namespace System.Data.SqlTypes
 
 		public static explicit operator SqlMoney (SqlSingle x)
 		{
-			if (x.IsNull) 
-				return Null;
-			else
-				return new SqlMoney ((decimal)x.Value);
+			checked {
+				if (x.IsNull) 
+					return Null;
+				else
+					return new SqlMoney ((decimal)x.Value);
+			}
 		}
 
 		public static explicit operator SqlMoney (SqlString x)
 		{
-			return SqlMoney.Parse (x.Value);
+			checked {
+				return SqlMoney.Parse (x.Value);
+			}
 		}
 
 		public static implicit operator SqlMoney (decimal x)

+ 38 - 10
mcs/class/System.Data/System.Data.SqlTypes/SqlSingle.cs

@@ -3,6 +3,7 @@
 //
 // Author:
 //   Tim Coleman <[email protected]>
+//   Ville Palo <[email protected]>
 //
 // (C) Copyright 2002 Tim Coleman
 //
@@ -20,8 +21,8 @@ namespace System.Data.SqlTypes
 
 		private bool notNull;
 
-		public static readonly SqlSingle MaxValue = new SqlSingle (3.40282346638528859e38);
-		public static readonly SqlSingle MinValue = new SqlSingle (-3.40282346638528859e38);
+		public static readonly SqlSingle MaxValue = new SqlSingle (3.40282346638528859E+38f);
+		public static readonly SqlSingle MinValue = new SqlSingle (-3.40282346638528859E+38f);
 		public static readonly SqlSingle Null;
 		public static readonly SqlSingle Zero = new SqlSingle (0);
 
@@ -88,6 +89,10 @@ namespace System.Data.SqlTypes
 		{
 			if (!(value is SqlSingle))
 				return false;
+			else if (this.IsNull && ((SqlSingle)value).IsNull)
+				return true;
+			else if (((SqlSingle)value).IsNull)
+				return false;
 			else
 				return (bool) (this == (SqlSingle)value);
 		}
@@ -196,12 +201,16 @@ namespace System.Data.SqlTypes
 
 		public static SqlSingle operator + (SqlSingle x, SqlSingle y)
 		{
-			return new SqlSingle (x.Value + y.Value);
+			checked {
+				return new SqlSingle ((float)(x.Value + y.Value));
+			}
 		}
 
 		public static SqlSingle operator / (SqlSingle x, SqlSingle y)
 		{
-			return new SqlSingle (x.Value / y.Value);
+			checked {
+				return new SqlSingle (x.Value / y.Value);
+			}
 		}
 
 		public static SqlBoolean operator == (SqlSingle x, SqlSingle y)
@@ -242,12 +251,16 @@ namespace System.Data.SqlTypes
 
 		public static SqlSingle operator * (SqlSingle x, SqlSingle y)
 		{
-			return new SqlSingle (x.Value * y.Value);
+			checked {
+				return new SqlSingle (x.Value * y.Value);
+			}
 		}
 
 		public static SqlSingle operator - (SqlSingle x, SqlSingle y)
 		{
-			return new SqlSingle (x.Value - y.Value);
+			checked {
+				return new SqlSingle (x.Value - y.Value);
+			}
 		}
 
 		public static SqlSingle operator - (SqlSingle n)
@@ -257,12 +270,22 @@ namespace System.Data.SqlTypes
 
 		public static explicit operator SqlSingle (SqlBoolean x)
 		{
-			return new SqlSingle((float)x.ByteValue);
+			checked {
+				if (x.IsNull)
+					return Null;
+				
+				return new SqlSingle((float)x.ByteValue);
+			}
 		}
 
 		public static explicit operator SqlSingle (SqlDouble x)
 		{
-			return new SqlSingle((float)x.Value);
+			checked {
+				if (x.IsNull)
+					return Null;
+				
+				return new SqlSingle((float)x.Value);
+			}
 		}
 
 		public static explicit operator float (SqlSingle x)
@@ -272,7 +295,12 @@ namespace System.Data.SqlTypes
 
 		public static explicit operator SqlSingle (SqlString x)
 		{
-			return SqlSingle.Parse (x.Value);
+			checked {
+				if (x.IsNull)
+					return Null;
+				
+				return SqlSingle.Parse (x.Value);
+			}
 		}
 
 		public static implicit operator SqlSingle (float x)
@@ -284,7 +312,7 @@ namespace System.Data.SqlTypes
 		{
 			if (x.IsNull) 
 				return Null;
-			else
+			else 
 				return new SqlSingle((float)x.Value);
 		}
 

+ 5 - 0
mcs/class/System.Data/System.Data.SqlTypes/SqlString.cs

@@ -5,6 +5,7 @@
 //   Rodrigo Moya ([email protected])
 //   Daniel Morgan ([email protected])
 //   Tim Coleman ([email protected])
+//   Ville Palo ([email protected])
 //
 // (C) Ximian, Inc. 2002
 // (C) Copyright 2002 Tim Coleman
@@ -178,6 +179,10 @@ namespace System.Data.SqlTypes
 		{
 			if (!(value is SqlString))
 				return false;
+			if (this.IsNull && ((SqlString)value).IsNull)
+				return true;
+			else if (((SqlString)value).IsNull)
+				return false;
 			else
 				return (bool) (this == (SqlString)value);
 		}