+2002-05-07 Tim Coleman <tim@timcoleman.com>
+ * INullable.cs:
+ * SqlBinary.cs:
+ * SqlBoolean.cs:
+ * SqlByte.cs:
+ * SqlCompareOptions.cs:
+ * SqlDateTime.cs:
+ * SqlDecimal.cs:
+ * SqlDouble.cs:
+ * SqlGuid.cs:
+ * SqlInt16.cs:
+ * SqlInt32.cs:
+ * SqlInt64.cs:
+ * SqlMoney.cs:
+ * SqlSingle.cs:
+ * SqlString.cs:
+ Implement CompareTo, Equals, and String conversions
+ for many types
+
2002-05-05 Daniel Morgan <danmorg@sc.rr.com>
* Test/PostgresTest.cs: modified to run completely. There
namespace System.Data.SqlTypes
{
/// <summary>
- /// All of the System.Data.SqlTypes objects and structures implement the INullable interface, reflecting the fact that, unlike the corresponding system types, SqlTypes can legally contain the value null.
+ /// All of the System.Data.SqlTypes objects and structures implement the INullable interface,
+ /// reflecting the fact that, unlike the corresponding system types, SqlTypes can legally contain the value null.
/// </summary>
public interface INullable
{
- [MonoTODO]
bool IsNull {
get;
}
return (x + y);
}
- [MonoTODO]
public override bool Equals (object value)
{
- throw new NotImplementedException ();
+ if (!(value is SqlBinary))
+ return false;
+ else
+ return (bool) (this == value);
}
public static SqlBoolean Equals(SqlBinary x, SqlBinary y)
return (x & y);
}
- [MonoTODO]
public int CompareTo (object value)
{
- throw new NotImplementedException ();
+ if (value == null)
+ return 1;
+ else if (!(value is SqlBoolean))
+ throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlBoolean"));
+ else if (value.IsNull)
+ return 1;
+ else
+ return value.CompareTo (value.ByteValue);
}
- [MonoTODO]
public override bool Equals(object value)
{
- throw new NotImplementedException ();
+ if (!(value is SqlByte))
+ return false;
+ else
+ return (bool) (this == value);
}
public static SqlBoolean Equals(SqlBoolean x, SqlBoolean y)
public byte Value {
get {
if (this.IsNull)
- throw new SqlNullValueException ("The property contains Null.");
+ throw new SqlNullValueException ();
else
return value;
}
return (x | y);
}
- [MonoTODO]
public int CompareTo (object value)
{
- throw new NotImplementedException ();
+ if (value == null)
+ return 1;
+ else if (!(value is SqlByte))
+ throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlByte"));
+ else if (value.IsNull)
+ return 1;
+ else
+ return value.CompareTo (value.Value);
}
public static SqlByte Divide (SqlByte x, SqlByte y)
return (x / y);
}
- [MonoTODO]
public override bool Equals (object value)
{
- throw new NotImplementedException ();
+ if (!(value is SqlByte))
+ return false;
+ else
+ return (bool) (this == value);
}
public static SqlBoolean Equals (SqlByte x, SqlByte y)
return ~x;
}
- [MonoTODO]
public static SqlByte Parse (string s)
{
- throw new NotImplementedException ();
+ return new SqlByte (s.ToByte ());
}
public static SqlByte Subtract (SqlByte x, SqlByte y)
return ((SqlSingle)this);
}
- [MonoTODO]
public SqlString ToSqlString ()
{
- throw new NotImplementedException ();
+ return ((SqlString)this);
}
- [MonoTODO]
public override string ToString ()
{
- throw new NotImplementedException ();
+ if (this.IsNull)
+ return String.Empty;
+ else
+ return value.ToString ();
}
public static SqlByte Xor (SqlByte x, SqlByte y)
namespace System.Data.SqlTypes
{
- /// <summary>\r
- /// compare option values for SqlString\r
+ /// <summary>
+ /// compare option values for SqlString
/// </summary>
- [Flags]\r
- [Serializable]\r
+ [Flags]
+ [Serializable]
public enum SqlCompareOptions {
BinarySort,
IgnoreCase,
#region Methods
- [MonoTODO]
public int CompareTo (object value)
{
- throw new NotImplementedException ();
+ if (value == null)
+ return 1;
+ else if (!(value is SqlDateTime))
+ throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlDateTime"));
+ else if (value.IsNull)
+ return 1;
+ else
+ return value.CompareTo (value.Value);
}
- [MonoTODO]
public override bool Equals (object value)
{
- throw new NotImplementedException ();
+ if (!(value is SqlDateTime))
+ return false;
+ else
+ return (bool) (this == value);
}
public static SqlBoolean Equals (SqlDateTime x, SqlDateTime y)
public SqlString ToSqlString ()
{
- return new SqlString (value.ToString ());
+ return ((SqlString)this);
}
public override string ToString ()
{
- return value.ToString ();
+ if (this.IsNull)
+ return String.Empty;
+ else
+ return value.ToString ();
}
[MonoTODO]
public struct SqlDecimal : INullable, IComparable
{
#region Fields
+
private decimal value;
public static readonly byte MaxPrecision = 38;
-
- [MonoTODO]
- public static readonly byte MaxScale; // ????
-
+ 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 SqlDecimal Null;
[MonoTODO]
public SqlDecimal (byte bPrecision, byte bScale, bool fPositive, int[] bits)
{
- throw new NotImplementedException();
+ throw new NotImplementedException ();
}
[MonoTODO]
public SqlDecimal (byte bPrecision, byte bScale, bool fPositive, int data1, int data2, int data3, int data4)
{
- throw new NotImplementedException();
+ throw new NotImplementedException ();
}
#endregion
get { throw new NotImplementedException (); }
}
- [MonoTODO]
- public byte[] Data {
- get { throw new NotImplementedException (); }
+ public int[] Data {
+ get {
+ if (this.IsNull)
+ throw new SqlNullValueException ();
+ else
+ return Decimal.GetBits (value);
+ }
}
public bool IsNull {
public decimal Value {
get {
if (this.IsNull)
- throw new SqlNullValueException ("The property contains Null.");
+ throw new SqlNullValueException ();
else
return value;
}
throw new NotImplementedException();
}
- [MonoTODO]
public int CompareTo (object value)
{
- throw new NotImplementedException ();
+ if (value == null)
+ return 1;
+ else if (!(value is SqlDecimal))
+ throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlDecimal"));
+ else if (value.IsNull)
+ return 1;
+ else
+ return value.CompareTo (value.Value);
}
[MonoTODO]
return (x / y);
}
- [MonoTODO]
public override bool Equals (object value)
{
- throw new NotImplementedException ();
+ if (!(value is SqlDecimal))
+ return false;
+ else
+ return (bool) (this == value);
}
public static SqlBoolean Equals (SqlDecimal x, SqlDecimal y)
[MonoTODO]
public static SqlDecimal Floor (SqlDecimal n)
{
- throw new NotImplementedException();
+ throw new NotImplementedException ();
}
[MonoTODO]
return ((SqlSingle)this);
}
- [MonoTODO]
public SqlString ToSqlString ()
{
- throw new NotImplementedException ();
+ return ((SqlString)this);
}
- [MonoTODO]
public override string ToString ()
{
- throw new NotImplementedException ();
+ if (this.IsNull)
+ return String.Empty;
+ else
+ return value.ToString ();
}
[MonoTODO]
public double Value {
get {
if (this.IsNull)
- throw new SqlNullValueException ("The property contains Null.");
+ throw new SqlNullValueException ();
else
return value;
}
return (x + y);
}
- [MonoTODO]
public int CompareTo (object value)
{
- throw new NotImplementedException ();
+ if (value == null)
+ return 1;
+ else if (!(value is SqlDouble))
+ throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlDouble"));
+ else if (value.IsNull)
+ return 1;
+ else
+ return value.CompareTo (value.Value);
}
public static SqlDouble Divide (SqlDouble x, SqlDouble y)
return (x / y);
}
- [MonoTODO]
public override bool Equals (object value)
{
- throw new NotImplementedException ();
+ if (!(value is SqlDouble))
+ return false;
+ else
+ return (bool) (this == value);
}
public static SqlBoolean Equals (SqlDouble x, SqlDouble y)
return ((SqlSingle)this);
}
- [MonoTODO]
public SqlString ToSqlString ()
{
- throw new NotImplementedException ();
+ return ((SqlString)this);
}
- [MonoTODO]
public override string ToString ()
{
- throw new NotImplementedException ();
+ if (this.IsNull)
+ return String.Empty;
+ else
+ return value.ToString ();
}
public static SqlDouble operator + (SqlDouble x, SqlDouble y)
public struct SqlGuid : INullable, IComparable
{
#region Fields
- private Guid value;
+
+ Guid value;
public static readonly SqlGuid Null;
#region Methods
- [MonoTODO]
public int CompareTo (object value)
{
- throw new NotImplementedException ();
+ if (value == null)
+ return 1;
+ else if (!(value is SqlGuid))
+ throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlGuid"));
+ else if (value.IsNull)
+ return 1;
+ else
+ return value.CompareTo (value.Value);
}
- [MonoTODO]
public override bool Equals (object value)
{
- throw new NotImplementedException ();
+ if (!(value is SqlGuid))
+ return false;
+ else
+ return (bool) (this == value);
}
public static SqlBoolean Equals (SqlGuid x, SqlGuid y)
throw new NotImplementedException ();
}
- [MonoTODO]
public SqlBinary ToSqlBinary ()
{
- throw new NotImplementedException ();
+ return ((SqlBinary)this);
}
- [MonoTODO]
public SqlString ToSqlString ()
{
- throw new NotImplementedException ();
+ return ((SqlString)this);
}
- [MonoTODO]
public override string ToString ()
{
- throw new NotImplementedException ();
+ if (this.IsNull)
+ return String.Empty;
+ else
+ return value.ToString ();
}
public static SqlBoolean operator == (SqlGuid x, SqlGuid y)
public short Value {
get {
if (this.IsNull)
- throw new SqlNullValueException ("The property contains Null.");
+ throw new SqlNullValueException ();
else
return value;
}
return (x | y);
}
- [MonoTODO]
public int CompareTo (object value)
{
- throw new NotImplementedException ();
+ if (value == null)
+ return 1;
+ else if (!(value is SqlInt16))
+ throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlInt16"));
+ else if (value.IsNull)
+ return 1;
+ else
+ return value.CompareTo (value.Value);
}
public static SqlInt16 Divide (SqlInt16 x, SqlInt16 y)
return (x / y);
}
- [MonoTODO]
public override bool Equals (object value)
{
- throw new NotImplementedException ();
+ if (!(value is SqlInt16))
+ return false;
+ else
+ return (bool) (this == value);
}
public static SqlBoolean Equals (SqlInt16 x, SqlInt16 y)
return ((SqlSingle)this);
}
- [MonoTODO]
public SqlString ToSqlString ()
{
- throw new NotImplementedException ();
+ return ((SqlString)this);
}
- [MonoTODO]
public override string ToString ()
{
- throw new NotImplementedException ();
+ if (this.IsNull)
+ return String.Empty;
+ else
+ return value.ToString ();
}
public static SqlInt16 Xor (SqlInt16 x, SqlInt16 y)
public int Value {
get {
if (this.IsNull)
- throw new SqlNullValueException ("The property contains Null.");
+ throw new SqlNullValueException ();
else
return value;
}
return (x | y);
}
- [MonoTODO]
public int CompareTo(object value)
{
- throw new NotImplementedException ();
+ if (value == null)
+ return 1;
+ else if (!(value is SqlInt32))
+ throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlInt32"));
+ else if (value.IsNull)
+ return 1;
+ else
+ return value.CompareTo (value.Value);
}
public static SqlInt32 Divide(SqlInt32 x, SqlInt32 y)
return (x / y);
}
- [MonoTODO]
public override bool Equals(object value)
{
- throw new NotImplementedException ();
+ if (!(value is SqlInt32))
+ return false;
+ else
+ return (bool) (this == value);
}
public static SqlBoolean Equals(SqlInt32 x, SqlInt32 y)
return ((SqlSingle)this);
}
- [MonoTODO]
public SqlString ToSqlString ()
{
- throw new NotImplementedException ();
+ return ((SqlString)this);
}
- [MonoTODO]
public override string ToString()
{
- throw new NotImplementedException ();
+ if (this.IsNull)
+ return String.Empty;
+ else
+ return value.ToString ();
}
public static SqlInt32 Xor(SqlInt32 x, SqlInt32 y)
#region Properties
- [MonoTODO]
public bool IsNull {
get { return (bool) (this == Null); }
}
public long Value {
get {
if (this.IsNull)
- throw new SqlNullValueException ("The property contains Null.");
+ throw new SqlNullValueException ();
else
return value;
}
return (x | y);
}
- [MonoTODO]
public int CompareTo (object value)
{
- throw new NotImplementedException ();
+ if (value == null)
+ return 1;
+ else if (!(value is SqlInt64))
+ throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlInt64"));
+ else if (value.IsNull)
+ return 1;
+ else
+ return value.CompareTo (value.Value);
}
public static SqlInt64 Divide (SqlInt64 x, SqlInt64 y)
return (x / y);
}
- [MonoTODO]
public override bool Equals (object value)
{
- throw new NotImplementedException ();
+ if (!(value is SqlInt64))
+ return false;
+ else
+ return (bool) (this == value);
}
public static SqlBoolean Equals (SqlInt64 x, SqlInt64 y)
return ((SqlSingle)this);
}
- [MonoTODO]
public SqlString ToSqlString ()
{
- throw new NotImplementedException ();
+ return ((SqlString)this);
}
- [MonoTODO]
public override string ToString ()
{
- throw new NotImplementedException ();
+ return value.ToString ();
}
public static SqlInt64 Xor (SqlInt64 x, SqlInt64 y)
public decimal Value {
get {
if (this.IsNull)
- throw new SqlNullValueException ("The property contains Null.");
+ throw new SqlNullValueException ();
else
return value;
}
return (x + y);
}
- [MonoTODO]
public int CompareTo (object value)
{
- throw new NotImplementedException ();
+ if (value == null)
+ return 1;
+ else if (!(value is SqlMoney))
+ throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlMoney"));
+ else if (value.IsNull)
+ return 1;
+ else
+ return value.CompareTo (value.Value);
}
public static SqlMoney Divide (SqlMoney x, SqlMoney y)
return (x / y);
}
- [MonoTODO]
public override bool Equals (object value)
{
- throw new NotImplementedException ();
+ if (!(value is SqlMoney))
+ return false;
+ else
+ return (bool) (this == value);
}
public static SqlBoolean Equals (SqlMoney x, SqlMoney y)
return ((SqlSingle)this);
}
- [MonoTODO]
public SqlString ToSqlString ()
{
- throw new NotImplementedException ();
+ return ((SqlString)this);
}
- [MonoTODO]
public override string ToString ()
{
- throw new NotImplementedException ();
+ if (this.IsNull)
+ return String.Empty;
+ else
+ return value.ToString ();
}
public static SqlMoney operator + (SqlMoney x, SqlMoney y)
public float Value {
get {
if (this.IsNull)
- throw new SqlNullValueException ("The property contains Null.");
+ throw new SqlNullValueException ();
else
return value;
}
return (x + y);
}
- [MonoTODO]
public int CompareTo (object value)
{
- throw new NotImplementedException ();
+ if (value == null)
+ return 1;
+ else if (!(value is SqlSingle))
+ throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlSingle"));
+ else if (value.IsNull)
+ return 1;
+ else
+ return value.CompareTo (value.Value);
}
public static SqlSingle Divide (SqlSingle x, SqlSingle y)
return (x / y);
}
- [MonoTODO]
public override bool Equals (object value)
{
- throw new NotImplementedException ();
+ if (!(value is SqlSingle))
+ return false;
+ else
+ return (bool) (this == value);
}
public static SqlBoolean Equals (SqlSingle x, SqlSingle y)
}
- [MonoTODO]
public SqlString ToSqlString ()
{
- throw new NotImplementedException ();
+ return ((SqlString)this);
}
- [MonoTODO]
public override string ToString ()
{
- throw new NotImplementedException ();
+ return value.ToString ();
}
public static SqlSingle operator + (SqlSingle x, SqlSingle y)
}
[MonoTODO]
- public static CompareOptions CompareOptionsFromSqlCompareOptions ( SqlCompareOptions compareOptions)
+ public static CompareOptions CompareOptionsFromSqlCompareOptions (SqlCompareOptions compareOptions)
{
throw new NotImplementedException ();
}
// Comparison Methods
// **********************************
- [MonoTODO]
public int CompareTo(object value)
{
- throw new NotImplementedException ();
+ if (value == null)
+ return 1;
+ else if (!(value is SqlString))
+ throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlString"));
+ else if (value.IsNull)
+ return 1;
+ else
+ return value.CompareTo (value.Value);
}
public static SqlString Concat(SqlString x, SqlString y)
return (x + y);
}
- [MonoTODO]
public override bool Equals(object value)
{
- throw new NotImplementedException ();
+ if (!(value is SqlGuid))
+ return false;
+ else
+ return (bool) (this == value);
}
public static SqlBoolean Equals(SqlString x, SqlString y)
if (x.IsNull)
return Null;
else
- return new SqlString (x.ToString ());
+ return new SqlString (x.ByteValue.ToString ());
}
public static explicit operator SqlString (SqlByte x)
if (x.IsNull)
return Null;
else
- return new SqlString (x.ToString ());
+ return new SqlString (x.Value.ToString ());
}
public static explicit operator SqlString (SqlDateTime x)
if (x.IsNull)
return Null;
else
- return new SqlString (x.ToString ());
+ return new SqlString (x.Value.ToString ());
}
public static explicit operator SqlString (SqlDecimal x)
if (x.IsNull)
return Null;
else
- return new SqlString (x.ToString ());
+ return new SqlString (x.Value.ToString ());
}
public static explicit operator SqlString (SqlDouble x)
if (x.IsNull)
return Null;
else
- return new SqlString (x.ToString ());
+ return new SqlString (x.Value.ToString ());
}
public static explicit operator SqlString (SqlGuid x)
if (x.IsNull)
return Null;
else
- return new SqlString (x.ToString ());
+ return new SqlString (x.Value.ToString ());
}
public static explicit operator SqlString (SqlInt16 x)
if (x.IsNull)
return Null;
else
- return new SqlString (x.ToString ());
+ return new SqlString (x.Value.ToString ());
}
public static explicit operator SqlString (SqlInt32 x)
if (x.IsNull)
return Null;
else
- return new SqlString (x.ToString ());
+ return new SqlString (x.Value.ToString ());
}
public static explicit operator SqlString (SqlInt64 x)
if (x.IsNull)
return Null;
else
- return new SqlString (x.ToString ());
+ return new SqlString (x.Value.ToString ());
}
public static explicit operator SqlString (SqlMoney x)
if (x.IsNull)
return Null;
else
- return new SqlString (x.ToString ());
+ return new SqlString (x.Value.ToString ());
}
public static explicit operator SqlString (SqlSingle x)
if (x.IsNull)
return Null;
else
- return new SqlString (x.ToString ());
+ return new SqlString (x.Value.ToString ());
}
public static explicit operator string (SqlString x)