Пример #1
0
        public void GetRawValue()
        {
            SqlType type = new SqlDecimal(5.27m, 10, 5, ParameterDirection.Input);
            Assert.AreEqual(5.27m, type.GetRawValue());

            type = new SqlDecimal(null, 10, 5, ParameterDirection.Input);
            Assert.Null(type.GetRawValue());
        }
Пример #2
0
        public void CreateMetaData()
        {
            Assert.Throws<TypeCannotBeUsedAsAClrTypeException>(() => SqlDecimal.GetTypeHandler().CreateMetaData("Test"));

            SqlTypeHandler col = new SqlDecimal(5.27m, null, null, ParameterDirection.Input);
            Assert.Throws<TypePropertiesMustBeSetExplicitlyException>(() => col.CreateMetaData("Test"));

            col = new SqlDecimal(5.27m, 10, 5, ParameterDirection.Input);
            var meta = col.CreateMetaData("Test");
            Assert.AreEqual(SqlDbType.Decimal, meta.SqlDbType);
            Assert.AreEqual(10, meta.Precision);
            Assert.AreEqual(5, meta.Scale);
            Assert.AreEqual("Test", meta.Name);
        }
Пример #3
0
 // valid for SqlDbType.Numeric (uses SqlDecimal since Decimal cannot hold full range)
 public override void SetSqlDecimal(SmiEventSink sink, int ordinal, SqlDecimal value)
 {
     _buffer[ordinal].SqlDecimal = value;
 }
Пример #4
0
 public void Truncate()
 {
     // NOT WORKING
     Assert.Equal(new SqlDecimal(6464.6400m).Value, SqlDecimal.Truncate(_test1, 2).Value);
     Assert.Equal(6464.6400m, SqlDecimal.Truncate(_test1, 2).Value);
 }
Пример #5
0
        public void Create()
        {
            // SqlDecimal (decimal)
            SqlDecimal Test = new SqlDecimal(30.3098m);

            Assert.Equal((decimal)30.3098, Test.Value);

            try
            {
                decimal    d    = decimal.MaxValue;
                SqlDecimal test = new SqlDecimal(d + 1);
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // SqlDecimal (double)
            Test = new SqlDecimal(10E+10d);
            Assert.Equal(100000000000.00000m, Test.Value);

            try
            {
                SqlDecimal test = new SqlDecimal(10E+200d);
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // SqlDecimal (int)
            Test = new SqlDecimal(-1);
            Assert.Equal(-1m, Test.Value);

            // SqlDecimal (long)
            Test = new SqlDecimal((long)(-99999));
            Assert.Equal(-99999m, Test.Value);

            // SqlDecimal (byte, byte, bool. int[]
            Test = new SqlDecimal(10, 3, false, new int[4] {
                200, 1, 0, 0
            });
            Assert.Equal(-4294967.496m, Test.Value);

            try
            {
                Test = new SqlDecimal(100, 100, false,
                                      new int[4] {
                    int.MaxValue,
                    int.MaxValue, int.MaxValue,
                    int.MaxValue
                });
                Assert.False(true);
            }
            catch (SqlTypeException)
            {
            }

            // sqlDecimal (byte, byte, bool, int, int, int, int)
            Test = new SqlDecimal(12, 2, true, 100, 100, 0, 0);
            Assert.Equal(4294967297.00m, Test.Value);

            try
            {
                Test = new SqlDecimal(100, 100, false,
                                      int.MaxValue,
                                      int.MaxValue, int.MaxValue,
                                      int.MaxValue);
                Assert.False(true);
            }
            catch (SqlTypeException)
            {
            }
        }
Пример #6
0
 public virtual void SetSqlDecimal(int ordinal, SqlDecimal value)
 {
     throw ADP.InternalError(ADP.InternalErrorCode.UnimplementedSMIMethod);
 }
Пример #7
0
        public void ArithmeticMethods()
        {
            // Abs
            Assert.Equal(6m, SqlDecimal.Abs(_test4));
            Assert.Equal(new SqlDecimal(6464.6464m).Value, SqlDecimal.Abs(_test1).Value);

            Assert.Equal(SqlDecimal.Null, SqlDecimal.Abs(SqlDecimal.Null));

            // Add()
            SqlDecimal test2 = new SqlDecimal(-2000m);

            Assert.Equal(16464.6464m, SqlDecimal.Add(_test1, _test2).Value);
            Assert.Equal("158456325028528675187087900670", SqlDecimal.Add(_test5, _test5).ToString());
            Assert.Equal(9994.00m, SqlDecimal.Add(_test3, _test4));
            Assert.Equal(-2006m, SqlDecimal.Add(_test4, test2));
            Assert.Equal(8000.00m, SqlDecimal.Add(test2, _test3));

            try
            {
                SqlDecimal test = SqlDecimal.Add(SqlDecimal.MaxValue, SqlDecimal.MaxValue);
                Assert.False(true);
            }
            catch (OverflowException)
            {
            }

            Assert.Equal(6465m, SqlDecimal.Ceiling(_test1));
            Assert.Equal(SqlDecimal.Null, SqlDecimal.Ceiling(SqlDecimal.Null));

            // Divide() => Notworking

            /*
             *          Assert.Equal ((SqlDecimal)(-1077.441066m), SqlDecimal.Divide (Test1, Test4));
             *          Assert.Equal (1.54687501546m, SqlDecimal.Divide (Test2, Test1).Value);
             *
             *          try {
             *                  SqlDecimal test = SqlDecimal.Divide(Test1, new SqlDecimal(0)).Value;
             * Assert.False(true);
             *          } catch (DivideByZeroException e) {
             *                  Assert.Equal (typeof (DivideByZeroException), e.GetType ());
             *          }
             */

            Assert.Equal(6464m, SqlDecimal.Floor(_test1));

            // Multiply()
            SqlDecimal Test;
            SqlDecimal test1 = new SqlDecimal(2m);

            Assert.Equal(64646464.000000m, SqlDecimal.Multiply(_test1, _test2).Value);
            Assert.Equal(-38787.8784m, SqlDecimal.Multiply(_test1, _test4).Value);
            Test = SqlDecimal.Multiply(_test5, test1);
            Assert.Equal("158456325028528675187087900670", Test.ToString());

            try
            {
                SqlDecimal test = SqlDecimal.Multiply(SqlDecimal.MaxValue, _test1);
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // Power => NotWorking
            //Assert.Equal ((SqlDecimal)41791653.0770m, SqlDecimal.Power (Test1, 2));

            // Round
            Assert.Equal(6464.65m, SqlDecimal.Round(_test1, 2));

            // Subtract()
            Assert.Equal(-3535.3536m, SqlDecimal.Subtract(_test1, _test3).Value);
            Assert.Equal(10006.00m, SqlDecimal.Subtract(_test3, _test4).Value);
            Assert.Equal("99999999920771837485735662406456049664", SqlDecimal.Subtract(SqlDecimal.MaxValue, decimal.MaxValue).ToString());

            try
            {
                SqlDecimal test = SqlDecimal.Subtract(SqlDecimal.MinValue, SqlDecimal.MaxValue);
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            Assert.Equal(1, SqlDecimal.Sign(_test1));
            Assert.Equal(new SqlInt32(-1), SqlDecimal.Sign(_test4));
        }
Пример #8
0
        public void GetXsdTypeTest()
        {
            XmlQualifiedName qualifiedName = SqlDecimal.GetXsdType(null);

            Assert.Equal("decimal", qualifiedName.Name);
        }
Пример #9
0
        public override object Aggregate(int[] records, AggregateType kind)
        {
            bool hasData = false;

            try
            {
                switch (kind)
                {
                case AggregateType.Sum:
                    SqlInt64 sum = 0;
                    foreach (int record in records)
                    {
                        if (IsNull(record))
                        {
                            continue;
                        }
                        checked { sum += _values[record]; }
                        hasData = true;
                    }
                    if (hasData)
                    {
                        return(sum);
                    }
                    return(_nullValue);

                case AggregateType.Mean:
                    SqlDecimal meanSum   = 0;
                    int        meanCount = 0;
                    foreach (int record in records)
                    {
                        if (IsNull(record))
                        {
                            continue;
                        }
                        checked { meanSum += _values[record].ToSqlDecimal(); }
                        meanCount++;
                        hasData = true;
                    }
                    if (hasData)
                    {
                        SqlInt64 mean = 0;
                        checked { mean = (meanSum / meanCount).ToSqlInt64(); }
                        return(mean);
                    }
                    return(_nullValue);

                case AggregateType.Var:
                case AggregateType.StDev:
                    int       count  = 0;
                    SqlDouble var    = 0;
                    SqlDouble prec   = 0;
                    SqlDouble dsum   = 0;
                    SqlDouble sqrsum = 0;

                    foreach (int record in records)
                    {
                        if (IsNull(record))
                        {
                            continue;
                        }
                        dsum   += (_values[record]).ToSqlDouble();
                        sqrsum += (_values[record]).ToSqlDouble() * (_values[record]).ToSqlDouble();
                        count++;
                    }

                    if (count > 1)
                    {
                        var  = count * sqrsum - (dsum * dsum);
                        prec = var / (dsum * dsum);

                        // we are dealing with the risk of a cancellation error
                        // double is guaranteed only for 15 digits so a difference
                        // with a result less than 1e-15 should be considered as zero

                        if ((prec < 1e-15) || (var < 0))
                        {
                            var = 0;
                        }
                        else
                        {
                            var = var / (count * (count - 1));
                        }

                        if (kind == AggregateType.StDev)
                        {
                            return(Math.Sqrt(var.Value));
                        }
                        return(var);
                    }
                    return(_nullValue);

                case AggregateType.Min:
                    SqlInt64 min = SqlInt64.MaxValue;
                    for (int i = 0; i < records.Length; i++)
                    {
                        int record = records[i];
                        if (IsNull(record))
                        {
                            continue;
                        }
                        if ((SqlInt64.LessThan(_values[record], min)).IsTrue)
                        {
                            min = _values[record];
                        }
                        hasData = true;
                    }
                    if (hasData)
                    {
                        return(min);
                    }
                    return(_nullValue);

                case AggregateType.Max:
                    SqlInt64 max = SqlInt64.MinValue;
                    for (int i = 0; i < records.Length; i++)
                    {
                        int record = records[i];
                        if (IsNull(record))
                        {
                            continue;
                        }

                        if ((SqlInt64.GreaterThan(_values[record], max)).IsTrue)
                        {
                            max = _values[record];
                        }
                        hasData = true;
                    }
                    if (hasData)
                    {
                        return(max);
                    }
                    return(_nullValue);

                case AggregateType.First:     // Does not seem to be implemented
                    if (records.Length > 0)
                    {
                        return(_values[records[0]]);
                    }
                    return(null !);   // no data => null

                case AggregateType.Count:
                    count = 0;
                    for (int i = 0; i < records.Length; i++)
                    {
                        if (!IsNull(records[i]))
                        {
                            count++;
                        }
                    }
                    return(count);
                }
            }
            catch (OverflowException)
            {
                throw ExprException.Overflow(typeof(SqlInt64));
            }
            throw ExceptionBuilder.AggregateException(kind, _dataType);
        }
        /// <summary>
        /// Purpose: Select method for a unique field. This method will Select one row from the database, based on the unique field 'AvailedAmenity_ID'
        /// </summary>
        /// <returns>DataTable object if succeeded, otherwise an Exception is thrown. </returns>
        /// <remarks>
        /// Properties needed for this method:
        /// <UL>
        ///		 <LI>AvailedAmenity_ID</LI>
        /// </UL>
        /// Properties set after a succesful call of this method:
        /// <UL>
        ///		 <LI>ErrorCode</LI>
        ///		 <LI>AvailedAmenity_ID</LI>
        ///		 <LI>AmenitiesID</LI>
        ///		 <LI>CheckIn_ID</LI>
        ///		 <LI>Quantity</LI>
        ///		 <LI>Cost</LI>
        ///		 <LI>TotalCost</LI>
        ///		 <LI>LastModifiedDate</LI>
        ///		 <LI>LastModifiedUser</LI>
        /// </UL>
        /// Will fill all properties corresponding with a field in the table with the value of the row selected.
        /// </remarks>
        public DataTable SelectOneWAvailedAmenity_IDLogic()
        {
            SqlCommand cmdToExecute = new SqlCommand();

            cmdToExecute.CommandText = "dbo.[pr_AvailedAmenities_SelectOneWAvailedAmenity_IDLogic]";
            cmdToExecute.CommandType = CommandType.StoredProcedure;
            DataTable      toReturn = new DataTable("AvailedAmenities");
            SqlDataAdapter adapter  = new SqlDataAdapter(cmdToExecute);

            // Use base class' connection object
            cmdToExecute.Connection = _mainConnection;

            try
            {
                cmdToExecute.Parameters.Add(new SqlParameter("@iAvailedAmenity_ID", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _availedAmenity_ID));
                cmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, false, 10, 0, "", DataRowVersion.Proposed, _errorCode));

                if (_mainConnectionIsCreatedLocal)
                {
                    // Open connection.
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                // Execute query.
                adapter.Fill(toReturn);
                _errorCode = (SqlInt32)cmdToExecute.Parameters["@iErrorCode"].Value;

                if (_errorCode != (int)LLBLError.AllOk)
                {
                    // Throw error.
                    throw new Exception("Stored Procedure 'pr_AvailedAmenities_SelectOneWAvailedAmenity_IDLogic' reported the ErrorCode: " + _errorCode);
                }

                if (toReturn.Rows.Count > 0)
                {
                    _availedAmenity_ID = (Int32)toReturn.Rows[0]["AvailedAmenity_ID"];
                    _amenitiesID       = (Int32)toReturn.Rows[0]["AmenitiesID"];
                    _checkIn_ID        = (Int32)toReturn.Rows[0]["CheckIn_ID"];
                    _quantity          = (Decimal)toReturn.Rows[0]["Quantity"];
                    _cost             = toReturn.Rows[0]["Cost"] == System.DBNull.Value ? SqlMoney.Null : (Decimal)toReturn.Rows[0]["Cost"];
                    _totalCost        = toReturn.Rows[0]["TotalCost"] == System.DBNull.Value ? SqlMoney.Null : (Decimal)toReturn.Rows[0]["TotalCost"];
                    _lastModifiedDate = toReturn.Rows[0]["LastModifiedDate"] == System.DBNull.Value ? SqlDateTime.Null : (DateTime)toReturn.Rows[0]["LastModifiedDate"];
                    _lastModifiedUser = toReturn.Rows[0]["LastModifiedUser"] == System.DBNull.Value ? SqlInt32.Null : (Int32)toReturn.Rows[0]["LastModifiedUser"];
                }
                return(toReturn);
            }
            catch (Exception ex)
            {
                // some error occured. Bubble it to caller and encapsulate Exception object
                throw new Exception("AvailedAmenities::SelectOneWAvailedAmenity_IDLogic::Error occured.", ex);
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    // Close connection.
                    _mainConnection.Close();
                }
                cmdToExecute.Dispose();
                adapter.Dispose();
            }
        }
Пример #11
0
        // devnote: This method should not be used with SqlDbType.Date and SqlDbType.DateTime2.
        //          With these types the values should be used directly as CLR types instead of being converted to a SqlValue
        internal static object GetSqlValueFromComVariant(object comVal)
        {
            object sqlVal = null;

            if ((null != comVal) && (DBNull.Value != comVal))
            {
                if (comVal is float)
                {
                    sqlVal = new SqlSingle((float)comVal);
                }
                else if (comVal is string)
                {
                    sqlVal = new SqlString((string)comVal);
                }
                else if (comVal is double)
                {
                    sqlVal = new SqlDouble((double)comVal);
                }
                else if (comVal is byte[])
                {
                    sqlVal = new SqlBinary((byte[])comVal);
                }
                else if (comVal is char)
                {
                    sqlVal = new SqlString(((char)comVal).ToString());
                }
                else if (comVal is char[])
                {
                    sqlVal = new SqlChars((char[])comVal);
                }
                else if (comVal is System.Guid)
                {
                    sqlVal = new SqlGuid((Guid)comVal);
                }
                else if (comVal is bool)
                {
                    sqlVal = new SqlBoolean((bool)comVal);
                }
                else if (comVal is byte)
                {
                    sqlVal = new SqlByte((byte)comVal);
                }
                else if (comVal is short)
                {
                    sqlVal = new SqlInt16((short)comVal);
                }
                else if (comVal is int)
                {
                    sqlVal = new SqlInt32((int)comVal);
                }
                else if (comVal is long)
                {
                    sqlVal = new SqlInt64((long)comVal);
                }
                else if (comVal is decimal)
                {
                    sqlVal = new SqlDecimal((decimal)comVal);
                }
                else if (comVal is DateTime)
                {
                    // devnote: Do not use with SqlDbType.Date and SqlDbType.DateTime2. See comment at top of method.
                    sqlVal = new SqlDateTime((DateTime)comVal);
                }
                else if (comVal is XmlReader)
                {
                    sqlVal = new SqlXml((XmlReader)comVal);
                }
                else if (comVal is TimeSpan || comVal is DateTimeOffset)
                {
                    sqlVal = comVal;
                }
#if DEBUG
                else
                {
                    Debug.Fail("unknown SqlType class stored in sqlVal");
                }
#endif
            }
            return(sqlVal);
        }
 public override void SetSqlDecimal(SmiEventSink sink, int ordinal, SqlDecimal value)
 {
     this._fieldSetters[ordinal].SetSqlDecimal(value);
 }
Пример #13
0
        public void Conversions()
        {
            SqlDouble Test0    = new SqlDouble(0);
            SqlDouble Test1    = new SqlDouble(250);
            SqlDouble Test2    = new SqlDouble(64e64);
            SqlDouble Test3    = new SqlDouble(64e164);
            SqlDouble TestNull = SqlDouble.Null;

            // ToSqlBoolean ()
            Assert.IsTrue(Test1.ToSqlBoolean().Value, "#M01A");
            Assert.IsTrue(!Test0.ToSqlBoolean().Value, "#M02A");
            Assert.IsTrue(TestNull.ToSqlBoolean().IsNull, "#M03A");

            // ToSqlByte ()
            Assert.AreEqual((byte)250, Test1.ToSqlByte().Value, "#M01B");
            Assert.AreEqual((byte)0, Test0.ToSqlByte().Value, "#M02B");

            try {
                SqlByte b = (byte)Test2.ToSqlByte();
                Assert.Fail("#M03B");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04B");
            }

            // ToSqlDecimal ()
            Assert.AreEqual(250.00000000000000M, Test1.ToSqlDecimal().Value, "#M01C");
            Assert.AreEqual((decimal)0, Test0.ToSqlDecimal().Value, "#M02C");

            try {
                SqlDecimal test = Test3.ToSqlDecimal().Value;
                Assert.Fail("#M03C");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04C");
            }

            // ToSqlInt16 ()
            Assert.AreEqual((short)250, Test1.ToSqlInt16().Value, "#M01D");
            Assert.AreEqual((short)0, Test0.ToSqlInt16().Value, "#M02D");

            try {
                SqlInt16 test = Test2.ToSqlInt16().Value;
                Assert.Fail("#M03D");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04D");
            }

            // ToSqlInt32 ()
            Assert.AreEqual((int)250, Test1.ToSqlInt32().Value, "#M01E");
            Assert.AreEqual((int)0, Test0.ToSqlInt32().Value, "#M02E");

            try {
                SqlInt32 test = Test2.ToSqlInt32().Value;
                Assert.Fail("#M03E");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04E");
            }

            // ToSqlInt64 ()
            Assert.AreEqual((long)250, Test1.ToSqlInt64().Value, "#M01F");
            Assert.AreEqual((long)0, Test0.ToSqlInt64().Value, "#M02F");

            try {
                SqlInt64 test = Test2.ToSqlInt64().Value;
                Assert.Fail("#M03F");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04F");
            }

            // ToSqlMoney ()
            Assert.AreEqual(250.0000M, Test1.ToSqlMoney().Value, "#M01G");
            Assert.AreEqual((decimal)0, Test0.ToSqlMoney().Value, "#M02G");

            try {
                SqlMoney test = Test2.ToSqlMoney().Value;
                Assert.Fail("#M03G");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04G");
            }

            // ToSqlSingle ()
            Assert.AreEqual((float)250, Test1.ToSqlSingle().Value, "#M01H");
            Assert.AreEqual((float)0, Test0.ToSqlSingle().Value, "#M02H");

            try {
                SqlSingle test = Test2.ToSqlSingle().Value;
                Assert.Fail("#MO3H");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04H");
            }

            // ToSqlString ()
            Assert.AreEqual("250", Test1.ToSqlString().Value, "#M01I");
            Assert.AreEqual("0", Test0.ToSqlString().Value, "#M02I");
            Assert.AreEqual("6.4E+65", Test2.ToSqlString().Value, "#M03I");

            // ToString ()
            Assert.AreEqual("250", Test1.ToString(), "#M01J");
            Assert.AreEqual("0", Test0.ToString(), "#M02J");
            Assert.AreEqual("6.4E+65", Test2.ToString(), "#M03J");
        }
 public OverigProduct(SqlString category, SqlString subcategory, SqlString name, SqlString description, SqlDecimal price, SqlBoolean spicy, SqlBoolean vegetarian)
 {
     Category    = category;
     Subcategory = subcategory;
     Name        = name;
     Description = description;
     Price       = price;
     Spicy       = spicy;
     Vegetarian  = vegetarian;
 }
Пример #15
0
    public static void GetDebtsTotalFillRow(Object obj, out SqlInt32 AccountID, out SqlDateTime PeriodStr, out SqlDecimal SumSaldo)
    {
        DataRow row = (DataRow)obj;

        AccountID = row.ToSql <SqlInt32>("AccountID");
        PeriodStr = row.ToSql <SqlDateTime>("PeriodStr");
        SumSaldo  = row.ToSql <SqlDecimal>("SumSaldo");
    }
Пример #16
0
 public virtual void SetSqlDecimal(object o, SqlDecimal value)
 {
     SetValue(o, value);
 }
Пример #17
0
        // this should be called for XmlSerialization
        public static object ChangeTypeForXML(object value, Type type)
        {
            Debug.Assert(value is string || type == typeof(string), "invalid call to ChangeTypeForXML");
            StorageType destinationType = DataStorage.GetStorageType(type);
            Type        valueType       = value.GetType();
            StorageType vtype           = DataStorage.GetStorageType(valueType);

            switch (destinationType)
            { // if destination is not string
            case StorageType.SqlBinary:
                return(new SqlBinary(Convert.FromBase64String((string)value)));

            case StorageType.SqlBoolean:
                return(new SqlBoolean(XmlConvert.ToBoolean((string)value)));

            case StorageType.SqlByte:
                return(new SqlByte(XmlConvert.ToByte((string)value)));

            case StorageType.SqlBytes:
                return(new SqlBytes(Convert.FromBase64String((string)value)));

            case StorageType.SqlChars:
                return(new SqlChars(((string)value).ToCharArray()));

            case StorageType.SqlDateTime:
                return(new SqlDateTime(XmlConvert.ToDateTime((string)value, XmlDateTimeSerializationMode.RoundtripKind)));

            case StorageType.SqlDecimal:
                return(SqlDecimal.Parse((string)value));    // parses invariant format and is larger has larger range then Decimal

            case StorageType.SqlDouble:
                return(new SqlDouble(XmlConvert.ToDouble((string)value)));

            case StorageType.SqlGuid:
                return(new SqlGuid(XmlConvert.ToGuid((string)value)));

            case StorageType.SqlInt16:
                return(new SqlInt16(XmlConvert.ToInt16((string)value)));

            case StorageType.SqlInt32:
                return(new SqlInt32(XmlConvert.ToInt32((string)value)));

            case StorageType.SqlInt64:
                return(new SqlInt64(XmlConvert.ToInt64((string)value)));

            case StorageType.SqlMoney:
                return(new SqlMoney(XmlConvert.ToDecimal((string)value)));

            case StorageType.SqlSingle:
                return(new SqlSingle(XmlConvert.ToSingle((string)value)));

            case StorageType.SqlString:
                return(new SqlString((string)value));

            //                case StorageType.SqlXml: // What to do
            //                    if (DataStorage.IsObjectNull(value)) {
            //                        return SqlXml.Null;
            //                    }
            //                    goto default;
            case StorageType.Boolean:
                if ("1" == (string)value)
                {
                    return(true);
                }
                if ("0" == (string)value)
                {
                    return(false);
                }
                return(XmlConvert.ToBoolean((string)value));

            case StorageType.Char:
                return(XmlConvert.ToChar((string)value));

            case StorageType.SByte:
                return(XmlConvert.ToSByte((string)value));

            case StorageType.Byte:
                return(XmlConvert.ToByte((string)value));

            case StorageType.Int16:
                return(XmlConvert.ToInt16((string)value));

            case StorageType.UInt16:
                return(XmlConvert.ToUInt16((string)value));

            case StorageType.Int32:
                return(XmlConvert.ToInt32((string)value));

            case StorageType.UInt32:
                return(XmlConvert.ToUInt32((string)value));

            case StorageType.Int64:
                return(XmlConvert.ToInt64((string)value));

            case StorageType.UInt64:
                return(XmlConvert.ToUInt64((string)value));

            case StorageType.Single:
                return(XmlConvert.ToSingle((string)value));

            case StorageType.Double:
                return(XmlConvert.ToDouble((string)value));

            case StorageType.Decimal:
                return(XmlConvert.ToDecimal((string)value));

            case StorageType.DateTime:
                return(XmlConvert.ToDateTime((string)value, XmlDateTimeSerializationMode.RoundtripKind));

            case StorageType.Guid:
                return(XmlConvert.ToGuid((string)value));

            case StorageType.Uri:
                return(new Uri((string)value));

            case StorageType.DateTimeOffset:
                return(XmlConvert.ToDateTimeOffset((string)value));

            case StorageType.TimeSpan:
                switch (vtype)
                {
                case StorageType.String:
                    return(XmlConvert.ToTimeSpan((string)value));

                case StorageType.Int32:
                    return(new TimeSpan((int)value));

                case StorageType.Int64:
                    return(new TimeSpan((long)value));

                default:
                    return((TimeSpan)value);
                }

            default:
            {
                if ((DBNull.Value == value) || (null == value))
                {
                    return(DBNull.Value);
                }

                switch (vtype)
                {         // To String
                case StorageType.SqlBinary:
                    return(Convert.ToBase64String(((SqlBinary)value).Value));

                case StorageType.SqlBoolean:
                    return(XmlConvert.ToString(((SqlBoolean)value).Value));

                case StorageType.SqlByte:
                    return(XmlConvert.ToString(((SqlByte)value).Value));

                case StorageType.SqlBytes:
                    return(Convert.ToBase64String(((SqlBytes)value).Value));

                case StorageType.SqlChars:
                    return(new string(((SqlChars)value).Value));

                case StorageType.SqlDateTime:
                    return(XmlConvert.ToString(((SqlDateTime)value).Value, XmlDateTimeSerializationMode.RoundtripKind));

                case StorageType.SqlDecimal:
                    return(((SqlDecimal)value).ToString());            // converts using invariant format and is larger has larger range then Decimal

                case StorageType.SqlDouble:
                    return(XmlConvert.ToString(((SqlDouble)value).Value));

                case StorageType.SqlGuid:
                    return(XmlConvert.ToString(((SqlGuid)value).Value));

                case StorageType.SqlInt16:
                    return(XmlConvert.ToString(((SqlInt16)value).Value));

                case StorageType.SqlInt32:
                    return(XmlConvert.ToString(((SqlInt32)value).Value));

                case StorageType.SqlInt64:
                    return(XmlConvert.ToString(((SqlInt64)value).Value));

                case StorageType.SqlMoney:
                    return(XmlConvert.ToString(((SqlMoney)value).Value));

                case StorageType.SqlSingle:
                    return(XmlConvert.ToString(((SqlSingle)value).Value));

                case StorageType.SqlString:
                    return(((SqlString)value).Value);

                case StorageType.Boolean:
                    return(XmlConvert.ToString((bool)value));

                case StorageType.Char:
                    return(XmlConvert.ToString((char)value));

                case StorageType.SByte:
                    return(XmlConvert.ToString((sbyte)value));

                case StorageType.Byte:
                    return(XmlConvert.ToString((byte)value));

                case StorageType.Int16:
                    return(XmlConvert.ToString((short)value));

                case StorageType.UInt16:
                    return(XmlConvert.ToString((ushort)value));

                case StorageType.Int32:
                    return(XmlConvert.ToString((int)value));

                case StorageType.UInt32:
                    return(XmlConvert.ToString((uint)value));

                case StorageType.Int64:
                    return(XmlConvert.ToString((long)value));

                case StorageType.UInt64:
                    return(XmlConvert.ToString((ulong)value));

                case StorageType.Single:
                    return(XmlConvert.ToString((float)value));

                case StorageType.Double:
                    return(XmlConvert.ToString((double)value));

                case StorageType.Decimal:
                    return(XmlConvert.ToString((decimal)value));

                case StorageType.DateTime:
                    return(XmlConvert.ToString((DateTime)value, XmlDateTimeSerializationMode.RoundtripKind));

                case StorageType.TimeSpan:
                    return(XmlConvert.ToString((TimeSpan)value));

                case StorageType.Guid:
                    return(XmlConvert.ToString((Guid)value));

                case StorageType.String:
                    return((string)value);

                case StorageType.CharArray:
                    return(new string((char[])value));

                case StorageType.DateTimeOffset:
                    return(XmlConvert.ToString((DateTimeOffset)value));

                default:
                    IConvertible iconvertible = (value as IConvertible);
                    if (null != iconvertible)
                    {
                        return(iconvertible.ToString(System.Globalization.CultureInfo.InvariantCulture));
                    }
                    // catch additional classes like Guid
                    IFormattable iformattable = (value as IFormattable);
                    if (null != iformattable)
                    {
                        return(iformattable.ToString(null, System.Globalization.CultureInfo.InvariantCulture));
                    }
                    return(value.ToString());
                }
            }
            }
        }
Пример #18
0
        public static SqlBoolean op_Explicit(SqlDecimal x)
        {
            if (x.IsNull)
                return SqlBoolean.Null;

            return new SqlBoolean(x.ToDouble() != 0.0D);
        }
Пример #19
0
        static Dictionary <MethodInfo, SoodaLinqMethod> Initialize()
        {
            Dictionary <MethodInfo, SoodaLinqMethod> method2id  = new Dictionary <MethodInfo, SoodaLinqMethod>();
            Expression <Func <object, bool> >        predicate  = o => true;
            Expression <Func <object, int> >         selector   = o => 0;
            Expression <Func <object, decimal> >     selectorM  = o => 0;
            Expression <Func <object, double> >      selectorD  = o => 0;
            Expression <Func <object, long> >        selectorL  = o => 0;
            Expression <Func <object, int?> >        selectorN  = o => 0;
            Expression <Func <object, decimal?> >    selectorNM = o => 0;
            Expression <Func <object, double?> >     selectorND = o => 0;
            Expression <Func <object, long?> >       selectorNL = o => 0;

            method2id.Add(MethodOf(() => Queryable.Where(null, predicate)), SoodaLinqMethod.Queryable_Where);
            method2id.Add(MethodOf(() => Queryable.OrderBy(null, selector)), SoodaLinqMethod.Queryable_OrderBy);
            method2id.Add(MethodOf(() => Queryable.OrderByDescending(null, selector)), SoodaLinqMethod.Queryable_OrderByDescending);
            method2id.Add(MethodOf(() => Queryable.ThenBy(null, selector)), SoodaLinqMethod.Queryable_ThenBy);
            method2id.Add(MethodOf(() => Queryable.ThenByDescending(null, selector)), SoodaLinqMethod.Queryable_ThenByDescending);
            method2id.Add(MethodOf(() => Queryable.Skip <object>(null, 0)), SoodaLinqMethod.Queryable_Skip);
            method2id.Add(MethodOf(() => Queryable.Take <object>(null, 0)), SoodaLinqMethod.Queryable_Take);
            method2id.Add(MethodOf(() => Queryable.Select(null, selector)), SoodaLinqMethod.Queryable_Select);
            method2id.Add(MethodOf(() => Queryable.Select(null, (object o, int i) => i)), SoodaLinqMethod.Queryable_SelectIndexed);
            method2id.Add(MethodOf(() => Queryable.GroupBy(null, selector)), SoodaLinqMethod.Queryable_GroupBy);
            method2id.Add(MethodOf(() => Queryable.Reverse <object>(null)), SoodaLinqMethod.Queryable_Reverse);
            method2id.Add(MethodOf(() => Queryable.Distinct <object>(null)), SoodaLinqMethod.Queryable_Distinct);
            method2id.Add(MethodOf(() => Queryable.OfType <object>(null)), SoodaLinqMethod.Queryable_OfType);
            method2id.Add(MethodOf(() => Queryable.Except <object>(null, null)), SoodaLinqMethod.Queryable_Except);
            method2id.Add(MethodOf(() => Queryable.Intersect <object>(null, null)), SoodaLinqMethod.Queryable_Intersect);
            method2id.Add(MethodOf(() => Queryable.Union <object>(null, null)), SoodaLinqMethod.Queryable_Union);
            method2id.Add(MethodOf(() => Queryable.All(null, predicate)), SoodaLinqMethod.Enumerable_All);
            method2id.Add(MethodOf(() => Queryable.Any <object>(null)), SoodaLinqMethod.Enumerable_Any);
            method2id.Add(MethodOf(() => Queryable.Any(null, predicate)), SoodaLinqMethod.Enumerable_AnyFiltered);
            method2id.Add(MethodOf(() => Queryable.Contains <object>(null, null)), SoodaLinqMethod.Enumerable_Contains);
            method2id.Add(MethodOf(() => Queryable.Count <object>(null)), SoodaLinqMethod.Enumerable_Count);
            method2id.Add(MethodOf(() => Queryable.Count(null, predicate)), SoodaLinqMethod.Enumerable_CountFiltered);
            method2id.Add(MethodOf(() => Queryable.First <object>(null)), SoodaLinqMethod.Queryable_First);
            method2id.Add(MethodOf(() => Queryable.First(null, predicate)), SoodaLinqMethod.Queryable_FirstFiltered);
            method2id.Add(MethodOf(() => Queryable.FirstOrDefault <object>(null)), SoodaLinqMethod.Queryable_FirstOrDefault);
            method2id.Add(MethodOf(() => Queryable.FirstOrDefault(null, predicate)), SoodaLinqMethod.Queryable_FirstOrDefaultFiltered);
            method2id.Add(MethodOf(() => Queryable.Last <object>(null)), SoodaLinqMethod.Queryable_Last);
            method2id.Add(MethodOf(() => Queryable.Last(null, predicate)), SoodaLinqMethod.Queryable_LastFiltered);
            method2id.Add(MethodOf(() => Queryable.LastOrDefault <object>(null)), SoodaLinqMethod.Queryable_LastOrDefault);
            method2id.Add(MethodOf(() => Queryable.LastOrDefault(null, predicate)), SoodaLinqMethod.Queryable_LastOrDefaultFiltered);
            method2id.Add(MethodOf(() => Queryable.Single <object>(null)), SoodaLinqMethod.Queryable_Single);
            method2id.Add(MethodOf(() => Queryable.Single(null, predicate)), SoodaLinqMethod.Queryable_SingleFiltered);
            method2id.Add(MethodOf(() => Queryable.SingleOrDefault <object>(null)), SoodaLinqMethod.Queryable_SingleOrDefault);
            method2id.Add(MethodOf(() => Queryable.SingleOrDefault(null, predicate)), SoodaLinqMethod.Queryable_SingleOrDefaultFiltered);
            method2id.Add(MethodOf(() => Queryable.Average((IQueryable <decimal>)null)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Queryable.Average((IQueryable <double>)null)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Queryable.Average((IQueryable <int>)null)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Queryable.Average((IQueryable <long>)null)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Queryable.Average((IQueryable <decimal?>)null)), SoodaLinqMethod.Queryable_AverageNullable);
            method2id.Add(MethodOf(() => Queryable.Average((IQueryable <double?>)null)), SoodaLinqMethod.Queryable_AverageNullable);
            method2id.Add(MethodOf(() => Queryable.Average((IQueryable <int?>)null)), SoodaLinqMethod.Queryable_AverageNullable);
            method2id.Add(MethodOf(() => Queryable.Average((IQueryable <long?>)null)), SoodaLinqMethod.Queryable_AverageNullable);
            method2id.Add(MethodOf(() => Queryable.Max <int>(null)), SoodaLinqMethod.Enumerable_Max);
            method2id.Add(MethodOf(() => Queryable.Min <int>(null)), SoodaLinqMethod.Enumerable_Min);
            method2id.Add(MethodOf(() => Queryable.Sum((IQueryable <decimal>)null)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Queryable.Sum((IQueryable <double>)null)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Queryable.Sum((IQueryable <int>)null)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Queryable.Sum((IQueryable <long>)null)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Queryable.Sum((IQueryable <decimal?>)null)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Queryable.Sum((IQueryable <double?>)null)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Queryable.Sum((IQueryable <int?>)null)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Queryable.Sum((IQueryable <long?>)null)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Queryable.Average(null, selectorM)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Queryable.Average(null, selectorD)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Queryable.Average(null, selector)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Queryable.Average(null, selectorL)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Queryable.Average(null, selectorNM)), SoodaLinqMethod.Queryable_AverageNullable);
            method2id.Add(MethodOf(() => Queryable.Average(null, selectorND)), SoodaLinqMethod.Queryable_AverageNullable);
            method2id.Add(MethodOf(() => Queryable.Average(null, selectorN)), SoodaLinqMethod.Queryable_AverageNullable);
            method2id.Add(MethodOf(() => Queryable.Average(null, selectorNL)), SoodaLinqMethod.Queryable_AverageNullable);
            method2id.Add(MethodOf(() => Queryable.Max(null, selector)), SoodaLinqMethod.Enumerable_Max);
            method2id.Add(MethodOf(() => Queryable.Min(null, selector)), SoodaLinqMethod.Enumerable_Min);
            method2id.Add(MethodOf(() => Queryable.Sum(null, selectorM)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Queryable.Sum(null, selectorD)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Queryable.Sum(null, selector)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Queryable.Sum(null, selectorL)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Queryable.Sum(null, selectorNM)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Queryable.Sum(null, selectorND)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Queryable.Sum(null, selectorN)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Queryable.Sum(null, selectorNL)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Enumerable.All(null, (object o) => true)), SoodaLinqMethod.Enumerable_All);
            method2id.Add(MethodOf(() => Enumerable.Any <object>(null)), SoodaLinqMethod.Enumerable_Any);
            method2id.Add(MethodOf(() => Enumerable.Any(null, (object o) => true)), SoodaLinqMethod.Enumerable_AnyFiltered);
            method2id.Add(MethodOf(() => Enumerable.Contains <object>(null, null)), SoodaLinqMethod.Enumerable_Contains);
            method2id.Add(MethodOf(() => Enumerable.Count <object>(null)), SoodaLinqMethod.Enumerable_Count);
            method2id.Add(MethodOf(() => Enumerable.Count(null, (object o) => true)), SoodaLinqMethod.Enumerable_CountFiltered);
            method2id.Add(MethodOf(() => Enumerable.Average(null, (object o) => 0M)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Enumerable.Average(null, (object o) => 0D)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Enumerable.Average(null, (object o) => 0)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Enumerable.Average(null, (object o) => 0L)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Enumerable.Average(null, (object o) => (decimal?)0)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Enumerable.Average(null, (object o) => (double?)0)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Enumerable.Average(null, (object o) => (int?)0)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Enumerable.Average(null, (object o) => (long?)0)), SoodaLinqMethod.Enumerable_Average);
            method2id.Add(MethodOf(() => Enumerable.Max(null, (object o) => 0M)), SoodaLinqMethod.Enumerable_Max);
            method2id.Add(MethodOf(() => Enumerable.Max(null, (object o) => 0D)), SoodaLinqMethod.Enumerable_Max);
            method2id.Add(MethodOf(() => Enumerable.Max(null, (object o) => 0)), SoodaLinqMethod.Enumerable_Max);
            method2id.Add(MethodOf(() => Enumerable.Max(null, (object o) => 0L)), SoodaLinqMethod.Enumerable_Max);
            method2id.Add(MethodOf(() => Enumerable.Max(null, (object o) => (decimal?)0)), SoodaLinqMethod.Enumerable_Max);
            method2id.Add(MethodOf(() => Enumerable.Max(null, (object o) => (double?)0)), SoodaLinqMethod.Enumerable_Max);
            method2id.Add(MethodOf(() => Enumerable.Max(null, (object o) => (int?)0)), SoodaLinqMethod.Enumerable_Max);
            method2id.Add(MethodOf(() => Enumerable.Max(null, (object o) => (long?)0)), SoodaLinqMethod.Enumerable_Max);
            method2id.Add(MethodOf(() => Enumerable.Max(null, (object o) => string.Empty)), SoodaLinqMethod.Enumerable_Max);
            method2id.Add(MethodOf(() => Enumerable.Min(null, (object o) => 0M)), SoodaLinqMethod.Enumerable_Min);
            method2id.Add(MethodOf(() => Enumerable.Min(null, (object o) => 0D)), SoodaLinqMethod.Enumerable_Min);
            method2id.Add(MethodOf(() => Enumerable.Min(null, (object o) => 0)), SoodaLinqMethod.Enumerable_Min);
            method2id.Add(MethodOf(() => Enumerable.Min(null, (object o) => 0L)), SoodaLinqMethod.Enumerable_Min);
            method2id.Add(MethodOf(() => Enumerable.Min(null, (object o) => (decimal?)0)), SoodaLinqMethod.Enumerable_Min);
            method2id.Add(MethodOf(() => Enumerable.Min(null, (object o) => (double?)0)), SoodaLinqMethod.Enumerable_Min);
            method2id.Add(MethodOf(() => Enumerable.Min(null, (object o) => (int?)0)), SoodaLinqMethod.Enumerable_Min);
            method2id.Add(MethodOf(() => Enumerable.Min(null, (object o) => (long?)0)), SoodaLinqMethod.Enumerable_Min);
            method2id.Add(MethodOf(() => Enumerable.Min(null, (object o) => string.Empty)), SoodaLinqMethod.Enumerable_Min);
            method2id.Add(MethodOf(() => Enumerable.Sum(null, (object o) => 0M)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Enumerable.Sum(null, (object o) => 0D)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Enumerable.Sum(null, (object o) => 0)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Enumerable.Sum(null, (object o) => 0L)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Enumerable.Sum(null, (object o) => (decimal?)0)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Enumerable.Sum(null, (object o) => (double?)0)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Enumerable.Sum(null, (object o) => (int?)0)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => Enumerable.Sum(null, (object o) => (long?)0)), SoodaLinqMethod.Enumerable_Sum);
            method2id.Add(MethodOf(() => ((ICollection <object>)null).Contains(null)), SoodaLinqMethod.ICollection_Contains);
            method2id.Add(MethodOf(() => ((List <object>)null).Contains(null)), SoodaLinqMethod.ICollection_Contains);
            method2id.Add(MethodOf(() => ((System.Collections.ArrayList)null).Contains(null)), SoodaLinqMethod.ICollection_Contains);
            method2id.Add(MethodOf(() => ((System.Collections.IList)null).Contains(null)), SoodaLinqMethod.ICollection_Contains);
            method2id.Add(MethodOf(() => ((Sooda.ObjectMapper.SoodaObjectCollectionWrapperGeneric <object>)null).Contains(null)), SoodaLinqMethod.ICollection_Contains);
            method2id.Add(MethodOf(() => string.Empty.GetType()), SoodaLinqMethod.Object_GetType);
            method2id.Add(MethodOf(() => ((object)null).Equals(null)), SoodaLinqMethod.Object_InstanceEquals);
            method2id.Add(MethodOf(() => false.Equals(false)), SoodaLinqMethod.Object_InstanceEquals);
            method2id.Add(MethodOf(() => 0M.Equals(0M)), SoodaLinqMethod.Object_InstanceEquals);
            method2id.Add(MethodOf(() => 0D.Equals(0D)), SoodaLinqMethod.Object_InstanceEquals);
            method2id.Add(MethodOf(() => 0.Equals(0)), SoodaLinqMethod.Object_InstanceEquals);
            method2id.Add(MethodOf(() => 0L.Equals(0L)), SoodaLinqMethod.Object_InstanceEquals);
            method2id.Add(MethodOf(() => string.Empty.Equals(string.Empty)), SoodaLinqMethod.Object_InstanceEquals);
            method2id.Add(MethodOf(() => DateTime.Now.Equals(DateTime.Now)), SoodaLinqMethod.Object_InstanceEquals);
            method2id.Add(MethodOf(() => object.Equals(null, null)), SoodaLinqMethod.Object_StaticEquals);
            method2id.Add(MethodOf(() => string.Equals(null, null)), SoodaLinqMethod.Object_StaticEquals);
            method2id.Add(MethodOf(() => DateTime.Equals(DateTime.Now, DateTime.Now)), SoodaLinqMethod.Object_StaticEquals);
            method2id.Add(MethodOf(() => SqlBoolean.Equals(SqlBoolean.Null, SqlBoolean.Null)), SoodaLinqMethod.Object_StaticEquals);
            method2id.Add(MethodOf(() => SqlDateTime.Equals(SqlDateTime.Null, SqlDateTime.Null)), SoodaLinqMethod.Object_StaticEquals);
            method2id.Add(MethodOf(() => SqlDecimal.Equals(SqlDecimal.Null, SqlDecimal.Null)), SoodaLinqMethod.Object_StaticEquals);
            method2id.Add(MethodOf(() => SqlDouble.Equals(SqlDouble.Null, SqlDouble.Null)), SoodaLinqMethod.Object_StaticEquals);
            method2id.Add(MethodOf(() => SqlGuid.Equals(SqlGuid.Null, SqlGuid.Null)), SoodaLinqMethod.Object_StaticEquals);
            method2id.Add(MethodOf(() => SqlInt32.Equals(SqlInt32.Null, SqlInt32.Null)), SoodaLinqMethod.Object_StaticEquals);
            method2id.Add(MethodOf(() => SqlInt64.Equals(SqlInt64.Null, SqlInt64.Null)), SoodaLinqMethod.Object_StaticEquals);
            method2id.Add(MethodOf(() => SqlSingle.Equals(SqlSingle.Null, SqlSingle.Null)), SoodaLinqMethod.Object_StaticEquals);
            method2id.Add(MethodOf(() => SqlString.Equals(SqlString.Null, SqlString.Null)), SoodaLinqMethod.Object_StaticEquals);
            method2id.Add(MethodOf(() => string.Concat(string.Empty, string.Empty)), SoodaLinqMethod.String_Concat);
            method2id.Add(MethodOf(() => LinqUtils.Like(string.Empty, string.Empty)), SoodaLinqMethod.String_Like);
            method2id.Add(MethodOf(() => string.Empty.Remove(0)), SoodaLinqMethod.String_Remove);
            method2id.Add(MethodOf(() => string.Empty.Substring(0, 0)), SoodaLinqMethod.String_Substring);
            method2id.Add(MethodOf(() => string.Empty.Replace(string.Empty, string.Empty)), SoodaLinqMethod.String_Replace);
            method2id.Add(MethodOf(() => string.Empty.ToLower()), SoodaLinqMethod.String_ToLower);
            method2id.Add(MethodOf(() => string.Empty.ToUpper()), SoodaLinqMethod.String_ToUpper);
            method2id.Add(MethodOf(() => string.Empty.StartsWith(string.Empty)), SoodaLinqMethod.String_StartsWith);
            method2id.Add(MethodOf(() => string.Empty.EndsWith(string.Empty)), SoodaLinqMethod.String_EndsWith);
            method2id.Add(MethodOf(() => string.Empty.Contains(string.Empty)), SoodaLinqMethod.String_Contains);
            method2id.Add(MethodOf(() => string.IsNullOrEmpty(null)), SoodaLinqMethod.String_IsNullOrEmpty);
            method2id.Add(MethodOf(() => 0.ToString()), SoodaLinqMethod.Int_ToString);
            method2id.Add(MethodOf(() => 0L.ToString()), SoodaLinqMethod.Long_ToString);
            method2id.Add(MethodOf(() => 0D.ToString()), SoodaLinqMethod.Double_ToString);
            method2id.Add(MethodOf(() => 0M.ToString()), SoodaLinqMethod.Decimal_ToString);
            method2id.Add(MethodOf(() => false.ToString()), SoodaLinqMethod.Bool_ToString);
            method2id.Add(MethodOf(() => Math.Abs(0M)), SoodaLinqMethod.Math_Abs);
            method2id.Add(MethodOf(() => Math.Abs(0D)), SoodaLinqMethod.Math_Abs);
            method2id.Add(MethodOf(() => Math.Abs((short)0)), SoodaLinqMethod.Math_Abs);
            method2id.Add(MethodOf(() => Math.Abs(0)), SoodaLinqMethod.Math_Abs);
            method2id.Add(MethodOf(() => Math.Abs(0L)), SoodaLinqMethod.Math_Abs);
            method2id.Add(MethodOf(() => Math.Abs((sbyte)0)), SoodaLinqMethod.Math_Abs);
            method2id.Add(MethodOf(() => Math.Abs(0F)), SoodaLinqMethod.Math_Abs);
            method2id.Add(MethodOf(() => Math.Acos(0)), SoodaLinqMethod.Math_Acos);
            method2id.Add(MethodOf(() => Math.Asin(0)), SoodaLinqMethod.Math_Asin);
            method2id.Add(MethodOf(() => Math.Atan(0)), SoodaLinqMethod.Math_Atan);
            method2id.Add(MethodOf(() => Math.Cos(0)), SoodaLinqMethod.Math_Cos);
            method2id.Add(MethodOf(() => Math.Exp(0)), SoodaLinqMethod.Math_Exp);
            method2id.Add(MethodOf(() => Math.Floor(0M)), SoodaLinqMethod.Math_Floor);
            method2id.Add(MethodOf(() => Math.Floor(0D)), SoodaLinqMethod.Math_Floor);
            method2id.Add(MethodOf(() => Math.Pow(1, 1)), SoodaLinqMethod.Math_Pow);
            method2id.Add(MethodOf(() => Math.Round(0M, 0)), SoodaLinqMethod.Math_Round);
            method2id.Add(MethodOf(() => Math.Round(0D, 0)), SoodaLinqMethod.Math_Round);
            method2id.Add(MethodOf(() => Math.Sign(0M)), SoodaLinqMethod.Math_Sign);
            method2id.Add(MethodOf(() => Math.Sign(0D)), SoodaLinqMethod.Math_Sign);
            method2id.Add(MethodOf(() => Math.Sign((short)0)), SoodaLinqMethod.Math_Sign);
            method2id.Add(MethodOf(() => Math.Sign(0)), SoodaLinqMethod.Math_Sign);
            method2id.Add(MethodOf(() => Math.Sign(0L)), SoodaLinqMethod.Math_Sign);
            method2id.Add(MethodOf(() => Math.Sign((sbyte)0)), SoodaLinqMethod.Math_Sign);
            method2id.Add(MethodOf(() => Math.Sign(0F)), SoodaLinqMethod.Math_Sign);
            method2id.Add(MethodOf(() => Math.Sin(0)), SoodaLinqMethod.Math_Sin);
            method2id.Add(MethodOf(() => Math.Sqrt(0)), SoodaLinqMethod.Math_Sqrt);
            method2id.Add(MethodOf(() => Math.Tan(0)), SoodaLinqMethod.Math_Tan);
            method2id.Add(MethodOf(() => ((SoodaObject)null).GetPrimaryKeyValue()), SoodaLinqMethod.SoodaObject_GetPrimaryKeyValue);
            method2id.Add(MethodOf(() => ((SoodaObject)null).GetLabel(false)), SoodaLinqMethod.SoodaObject_GetLabel);

            // doesn't compile: method2id.Add(MethodOf(() => ((SoodaObject) null)[string.Empty]), SoodaLinqMethod.SoodaObject_GetItem);
            method2id.Add(typeof(SoodaObject).GetMethod("get_Item"), SoodaLinqMethod.SoodaObject_GetItem);

            _method2id = method2id;
            return(method2id);
        }
Пример #20
0
 public override void SetSqlDecimal(object o, int index, SqlDecimal value)
 {
     this[index].SetSqlDecimal(o, value);
 }
Пример #21
0
        public void SqlDecimalToSqlString()
        {
            SqlDecimal TestDecimal = new SqlDecimal(1000.2345);

            Assert.AreEqual("1000.2345000000000", ((SqlString)TestDecimal).Value, "#U01");
        }
 public static SqlString ConvertToChineseMoney(SqlDecimal money)
 {
     // 在此处放置代码
     return(new SqlString(ConvertToChinese(money.ToDouble())));
 }
Пример #23
0
 /// <include file='..\..\..\..\..\..\..\..\doc\snippets\Microsoft.Data.SqlClient.Server\SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SetSqlDecimal/*' />
 public virtual void SetSqlDecimal(int ordinal, SqlDecimal value)
 {
     EnsureSubclassOverride();
     ValueUtilsSmi.SetSqlDecimal(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value);
 }
        private void SaveEventsWithinReadOrderRange(AggregateRootEvent[] newEvents, SqlDecimal rangeStart, SqlDecimal rangeEnd)
        {
            var increment = (rangeEnd - rangeStart) / (newEvents.Length + 1);

            IReadOnlyList <EventWithManualReadorder> eventsToPersist = newEvents.Select(
                (@event, index) => new EventWithManualReadorder
            {
                Event           = @event,
                ManualReadOrder = rangeStart + (index + 1) * increment
            })
                                                                       .ToList();

            SaveEventsInternal(eventsToPersist);
        }
 // valid for SqlDbType.Numeric (uses SqlDecimal since Decimal cannot hold full range)
 public override void SetSqlDecimal(SmiEventSink sink, int ordinal, SqlDecimal value)
 {
     CheckSettingColumn(ordinal);
     _fieldSetters[ordinal].SetSqlDecimal(value);
 }
 private static SqlDecimal ToCorrectPrecisionAndScale(SqlDecimal value)
 {
     return(SqlDecimal.ConvertToPrecScale(value, 38, 19));
 }
Пример #27
0
 internal static ArgumentException ParameterValueOutOfRange(SqlDecimal value)
 {
     return(ADP.Argument(System.StringsHelper.GetString(Strings.ADP_ParameterValueOutOfRange, value.ToString())));
 }
 public EventOrderNeighbourhood(long insertionOrder, SqlDecimal effectiveReadOrder, SqlDecimal previousReadOrder, SqlDecimal nextReadOrder)
 {
     InsertionOrder     = insertionOrder;
     EffectiveReadOrder = effectiveReadOrder;
     NextReadOrder      = UseNextIntegerInsteadIfNullSinceThatMeansThisEventIsTheLastInTheEventStore(nextReadOrder);
     PreviousReadOrder  = UseZeroInsteadIfNegativeSinceThisMeansThisIsTheFirstEventInTheEventStore(previousReadOrder);
 }
Пример #29
0
        public void Conversions()
        {
            // ToDouble
            Assert.Equal(6464.6464, _test1.ToDouble());

            // ToSqlBoolean ()
            Assert.Equal(new SqlBoolean(1), _test1.ToSqlBoolean());

            SqlDecimal Test = new SqlDecimal(0);

            Assert.True(!Test.ToSqlBoolean().Value);

            Test = new SqlDecimal(0);
            Assert.True(!Test.ToSqlBoolean().Value);
            Assert.True(SqlDecimal.Null.ToSqlBoolean().IsNull);

            // ToSqlByte ()
            Test = new SqlDecimal(250);
            Assert.Equal((byte)250, Test.ToSqlByte().Value);

            try
            {
                SqlByte b = (byte)_test2.ToSqlByte();
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // ToSqlDouble ()
            Assert.Equal(6464.6464, _test1.ToSqlDouble());

            // ToSqlInt16 ()
            Assert.Equal((short)1, new SqlDecimal(1).ToSqlInt16().Value);

            try
            {
                SqlInt16 test = SqlDecimal.MaxValue.ToSqlInt16().Value;
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // ToSqlInt32 ()
            // LAMESPEC: 6464.6464 --> 64646464 ??? with windows
            // MS.NET seems to return the first 32 bit integer (i.e.
            // Data [0]) but we don't have to follow such stupidity.
            //			Assert.Equal ((int)64646464, Test1.ToSqlInt32 ().Value);
            //			Assert.Equal ((int)1212, new SqlDecimal(12.12m).ToSqlInt32 ().Value);

            try
            {
                SqlInt32 test = SqlDecimal.MaxValue.ToSqlInt32().Value;
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // ToSqlInt64 ()
            Assert.Equal(6464, _test1.ToSqlInt64().Value);

            // ToSqlMoney ()
            Assert.Equal((decimal)6464.6464, _test1.ToSqlMoney().Value);

            try
            {
                SqlMoney test = SqlDecimal.MaxValue.ToSqlMoney().Value;
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // ToSqlSingle ()
            Assert.Equal((float)6464.6464, _test1.ToSqlSingle().Value);

            // ToSqlString ()
            Assert.Equal("6464.6464", _test1.ToSqlString().Value);

            // ToString ()
            Assert.Equal("6464.6464", _test1.ToString());
            // NOT WORKING
            Assert.Equal("792281625142643375935439503350000.00", SqlDecimal.Multiply(_test5, _test2).ToString());
            Assert.Equal(1E+38, SqlDecimal.MaxValue.ToSqlDouble());
        }
 private SqlDecimal UseZeroInsteadIfNegativeSinceThisMeansThisIsTheFirstEventInTheEventStore(SqlDecimal previousReadOrder)
 {
     return(previousReadOrder > 0 ? previousReadOrder : ToCorrectPrecisionAndScale(new SqlDecimal(0)));
 }
Пример #31
0
        public void ArithmeticOperators()
        {
            // "+"-operator
            Assert.Equal(new SqlDecimal(16464.6464m), _test1 + _test2);
            Assert.Equal("79228162514264337593543960335.00", (_test5 + _test3).ToString());

            SqlDecimal test2 = new SqlDecimal(-2000m);

            Assert.Equal(8000.00m, _test3 + test2);
            Assert.Equal(-2006m, _test4 + test2);
            Assert.Equal(8000.00m, test2 + _test3);

            try
            {
                SqlDecimal test = SqlDecimal.MaxValue + SqlDecimal.MaxValue;
                Assert.False(true);
            }
            catch (OverflowException) { }

            // "/"-operator => NotWorking
            //Assert.Equal ((SqlDecimal)1.54687501546m, Test2 / Test1);

            try
            {
                SqlDecimal test = _test3 / new SqlDecimal(0);
                Assert.False(true);
            }
            catch (DivideByZeroException e)
            {
                Assert.Equal(typeof(DivideByZeroException), e.GetType());
            }

            // "*"-operator
            Assert.Equal(64646464.000000m, _test1 * _test2);

            SqlDecimal Test = _test5 * (new SqlDecimal(2m));

            Assert.Equal("158456325028528675187087900670", Test.ToString());

            try
            {
                SqlDecimal test = SqlDecimal.MaxValue * _test1;
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // "-"-operator
            Assert.Equal(3535.3536m, _test2 - _test1);
            Assert.Equal(-10006.00m, _test4 - _test3);

            try
            {
                SqlDecimal test = SqlDecimal.MinValue - SqlDecimal.MaxValue;
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            Assert.Equal(SqlDecimal.Null, SqlDecimal.Null + _test1);
        }
 private SqlDecimal UseNextIntegerInsteadIfNullSinceThatMeansThisEventIsTheLastInTheEventStore(SqlDecimal nextReadOrder)
 {
     return(!nextReadOrder.IsNull ? nextReadOrder : ToCorrectPrecisionAndScale(new SqlDecimal(InsertionOrder + 1)));
 }
Пример #33
0
        public void SqlTypes_SqlDecimal()
        {
            NpgsqlParameter parameter;
            SqlDecimal value = new SqlDecimal(45m);

#if NET_2_0
            parameter = new NpgsqlParameter ();
            parameter.NpgsqlValue = value;
            Assert.AreEqual (NpgsqlDbType.Decimal, parameter.NpgsqlDbType, "#A:NpgsqlDbType");
            Assert.AreEqual (value, parameter.NpgsqlValue, "#A:NpgsqlValue");
            Assert.AreEqual (value, parameter.Value, "#A:Value");

            parameter = new NpgsqlParameter ();
            parameter.NpgsqlValue = SqlDecimal.Null;
            Assert.AreEqual (NpgsqlDbType.Decimal, parameter.NpgsqlDbType, "#B:NpgsqlDbType");
            Assert.AreEqual (SqlDecimal.Null, parameter.NpgsqlValue, "#B:NpgsqlValue");
            Assert.AreEqual (SqlDecimal.Null, parameter.Value, "#B:Value");
#endif

            parameter = new NpgsqlParameter();
            parameter.Value = value;
            Assert.AreEqual(NpgsqlDbType.Decimal, parameter.NpgsqlDbType, "#C:NpgsqlDbType");
#if NET_2_0
            Assert.AreEqual (value, parameter.NpgsqlValue, "#C:NpgsqlValue");
#endif
            Assert.AreEqual(value, parameter.Value, "#C:Value");
        }
Пример #34
0
        // Extract metadata for a single DataColumn
        internal static SmiExtendedMetaData SmiMetaDataFromDataColumn(DataColumn column, DataTable parent)
        {
            SqlDbType dbType = InferSqlDbTypeFromType_Katmai(column.DataType);

            if (InvalidSqlDbType == dbType)
            {
                throw SQL.UnsupportedColumnTypeForSqlProvider(column.ColumnName, column.DataType.Name);
            }

            long maxLength = AdjustMaxLength(dbType, column.MaxLength);

            if (InvalidMaxLength == maxLength)
            {
                throw SQL.InvalidColumnMaxLength(column.ColumnName, maxLength);
            }

            byte precision;
            byte scale;

            if (column.DataType == typeof(SqlDecimal))
            {
                // Must scan all values in column to determine best-fit precision & scale
                Debug.Assert(null != parent);
                scale = 0;
                byte nonFractionalPrecision = 0; // finds largest non-Fractional portion of precision
                foreach (DataRow row in parent.Rows)
                {
                    object obj = row[column];
                    if (!(obj is DBNull))
                    {
                        SqlDecimal value = (SqlDecimal)obj;
                        if (!value.IsNull)
                        {
                            byte tempNonFractPrec = checked ((byte)(value.Precision - value.Scale));
                            if (tempNonFractPrec > nonFractionalPrecision)
                            {
                                nonFractionalPrecision = tempNonFractPrec;
                            }

                            if (value.Scale > scale)
                            {
                                scale = value.Scale;
                            }
                        }
                    }
                }

                precision = checked ((byte)(nonFractionalPrecision + scale));

                if (SqlDecimal.MaxPrecision < precision)
                {
                    throw SQL.InvalidTableDerivedPrecisionForTvp(column.ColumnName, precision);
                }
                else if (0 == precision)
                {
                    precision = 1;
                }
            }
            else if (dbType == SqlDbType.DateTime2 || dbType == SqlDbType.DateTimeOffset || dbType == SqlDbType.Time)
            {
                // Time types care about scale, too.  But have to infer maximums for these.
                precision = 0;
                scale     = SmiMetaData.DefaultTime.Scale;
            }
            else if (dbType == SqlDbType.Decimal)
            {
                // Must scan all values in column to determine best-fit precision & scale
                Debug.Assert(null != parent);
                scale = 0;
                byte nonFractionalPrecision = 0; // finds largest non-Fractional portion of precision
                foreach (DataRow row in parent.Rows)
                {
                    object obj = row[column];
                    if (!(obj is DBNull))
                    {
                        SqlDecimal value            = (SqlDecimal)(Decimal)obj;
                        byte       tempNonFractPrec = checked ((byte)(value.Precision - value.Scale));
                        if (tempNonFractPrec > nonFractionalPrecision)
                        {
                            nonFractionalPrecision = tempNonFractPrec;
                        }

                        if (value.Scale > scale)
                        {
                            scale = value.Scale;
                        }
                    }
                }

                precision = checked ((byte)(nonFractionalPrecision + scale));

                if (SqlDecimal.MaxPrecision < precision)
                {
                    throw SQL.InvalidTableDerivedPrecisionForTvp(column.ColumnName, precision);
                }
                else if (0 == precision)
                {
                    precision = 1;
                }
            }
            else
            {
                precision = 0;
                scale     = 0;
            }

            // In Net Core, since DataColumn.Locale is not accessible because it is internal and in a separate assembly,
            // we try to get the Locale from the parent
            CultureInfo columnLocale = ((null != parent) ? parent.Locale : CultureInfo.CurrentCulture);

            return(new SmiExtendedMetaData(
                       dbType,
                       maxLength,
                       precision,
                       scale,
                       columnLocale.LCID,
                       SmiMetaData.DefaultNVarChar.CompareOptions,
                       false,                   // no support for multi-valued columns in a TVP yet
                       null,                    // no support for structured columns yet
                       null,                    // no support for structured columns yet
                       column.ColumnName,
                       null,
                       null,
                       null));
        }