Explorar o código

2004-04-12 Atsushi Enomoto <[email protected]>

	* SqlBoolean.cs : Allow "0" and "1" on Parse(). Allow SqlString.Null
	  in conversion.
	* SqlString.cs : CompareOption should not be None.

svn path=/trunk/mcs/; revision=25352
Atsushi Eno %!s(int64=22) %!d(string=hai) anos
pai
achega
df471d99c8

+ 6 - 0
mcs/class/System.Data/System.Data.SqlTypes/ChangeLog

@@ -1,3 +1,9 @@
+2004-04-12  Atsushi Enomoto  <[email protected]>
+
+	* SqlBoolean.cs : Allow "0" and "1" on Parse(). Allow SqlString.Null
+	  in conversion.
+	* SqlString.cs : CompareOption should not be None.
+
 2004-04-01  Lluis Sanchez Gual  <[email protected]>
 
 	* SqlNullValueException.cs: Use a more clarifying error message.

+ 8 - 0
mcs/class/System.Data/System.Data.SqlTypes/SqlBoolean.cs

@@ -161,6 +161,12 @@ namespace System.Data.SqlTypes
 
 		public static SqlBoolean Parse(string s) 
 		{
+			switch (s) {
+			case "0":
+				return new SqlBoolean (false);
+			case "1":
+				return new SqlBoolean (true);
+			}
 			return new SqlBoolean (Boolean.Parse (s));
 		}
 
@@ -414,6 +420,8 @@ namespace System.Data.SqlTypes
 		public static explicit operator SqlBoolean (SqlString x) 
 		{
 			checked {
+				if (x.IsNull)
+					return Null;
 				return SqlBoolean.Parse (x.Value);
 			}
 		}

+ 37 - 6
mcs/class/System.Data/System.Data.SqlTypes/SqlString.cs

@@ -41,17 +41,32 @@ namespace System.Data.SqlTypes
 		public static readonly int IgnoreWidth = 0x10;
 		public static readonly SqlString Null;
 
+		internal static readonly NumberFormatInfo MoneyFormat;
+		internal static NumberFormatInfo DecimalFormat;
 		#endregion // Fields
 
 		#region Constructors
 
+		static SqlString ()
+		{
+			MoneyFormat = (NumberFormatInfo) NumberFormatInfo.InvariantInfo.Clone ();
+			MoneyFormat.NumberDecimalDigits = 4;
+			MoneyFormat.NumberGroupSeparator = String.Empty;
+
+			DecimalFormat = (NumberFormatInfo) NumberFormatInfo.InvariantInfo.Clone ();
+			DecimalFormat.NumberDecimalDigits = 13;
+			DecimalFormat.NumberGroupSeparator = String.Empty;
+		}
+
 		// init with a string data
 		public SqlString (string data) 
 		{
 			this.value = data;
 			lcid = CultureInfo.CurrentCulture.LCID;
 			notNull = true;
-			this.compareOptions = SqlCompareOptions.None;
+			this.compareOptions = SqlCompareOptions.IgnoreCase |
+				SqlCompareOptions.IgnoreKanaType |
+				SqlCompareOptions.IgnoreWidth;
 		}
 
 		// init with a string data and locale id values.
@@ -60,7 +75,9 @@ namespace System.Data.SqlTypes
 			this.value = data;
 			this.lcid = lcid;
 			notNull = true;
-			this.compareOptions = SqlCompareOptions.None;
+			this.compareOptions = SqlCompareOptions.IgnoreCase |
+				SqlCompareOptions.IgnoreKanaType |
+				SqlCompareOptions.IgnoreWidth;
 		}
 
 		// init with locale id, compare options, 
@@ -167,6 +184,17 @@ namespace System.Data.SqlTypes
 			}
 		}
 
+		public CompareOptions CompareOptions {
+			get {
+				return 
+					(this.compareOptions & SqlCompareOptions.BinarySort) != 0 ? 
+					CompareOptions.Ordinal :
+					// 27 == all SqlCompareOptions - BinarySort 
+					// (1,2,8,24 are common to CompareOptions)
+					(CompareOptions) ((int) this.compareOptions & 27);
+			}
+		}
+
 		public bool IsNull {
 			get { return !notNull; }
 		}
@@ -225,7 +253,7 @@ namespace System.Data.SqlTypes
 		// Comparison Methods
 		// **********************************
 
-		public int CompareTo(object value)
+		public int CompareTo (object value)
 		{
 			if (value == null)
 				return 1;
@@ -233,8 +261,9 @@ namespace System.Data.SqlTypes
 				throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlString"));
 			else if (((SqlString)value).IsNull)
 				return 1;
-			else
-				return this.value.CompareTo (((SqlString)value).Value);
+//			else
+//				return String.Compare (this.value, ((SqlString)value).Value, (this.SqlCompareOptions & SqlCompareOptions.IgnoreCase) != 0, this.CultureInfo);
+			return CultureInfo.CompareInfo.Compare (this.value, ((SqlString)value).Value, this.CompareOptions);
 		}
 
 		public static SqlString Concat(SqlString x, SqlString y) 
@@ -478,12 +507,13 @@ namespace System.Data.SqlTypes
 				return new SqlString (x.Value.ToString ());
 		}
 
-		public static explicit operator SqlString (SqlDecimal x) 
+		public static explicit operator SqlString (SqlDecimal x)
 		{
 			if (x.IsNull)
 				return Null;
 			else
 				return new SqlString (x.Value.ToString ());
+				return new SqlString (x.Value.ToString ("N", DecimalFormat));
 		}
 
 		public static explicit operator SqlString (SqlDouble x) 
@@ -532,6 +562,7 @@ namespace System.Data.SqlTypes
 				return Null;
 			else
 				return new SqlString (x.Value.ToString ());
+				return new SqlString (x.Value.ToString ("N", MoneyFormat));
 		}
 
 		public static explicit operator SqlString (SqlSingle x)