示例#1
0
        public void Conversions()
        {
            SqlInt64 test12   = new SqlInt64(12);
            SqlInt64 test0    = new SqlInt64(0);
            SqlInt64 TestNull = SqlInt64.Null;
            SqlInt64 test1000 = new SqlInt64(1000);
            SqlInt64 test288  = new SqlInt64(288);

            // ToSqlBoolean ()
            Assert.True(test12.ToSqlBoolean().Value);
            Assert.False(test0.ToSqlBoolean().Value);
            Assert.True(TestNull.ToSqlBoolean().IsNull);

            // ToSqlByte ()
            Assert.Equal((byte)12, test12.ToSqlByte().Value);
            Assert.Equal((byte)0, test0.ToSqlByte().Value);

            Assert.Throws <OverflowException>(() => test1000.ToSqlByte());

            // ToSqlDecimal ()
            Assert.Equal(12, test12.ToSqlDecimal().Value);
            Assert.Equal(0, test0.ToSqlDecimal().Value);
            Assert.Equal(288, test288.ToSqlDecimal().Value);

            // ToSqlDouble ()
            Assert.Equal(12, test12.ToSqlDouble().Value);
            Assert.Equal(0, test0.ToSqlDouble().Value);
            Assert.Equal(1000, test1000.ToSqlDouble().Value);

            // ToSqlInt32 ()
            Assert.Equal(12, test12.ToSqlInt32().Value);
            Assert.Equal(0, test0.ToSqlInt32().Value);
            Assert.Equal(288, test288.ToSqlInt32().Value);

            // ToSqlInt16 ()
            Assert.Equal((short)12, test12.ToSqlInt16().Value);
            Assert.Equal((short)0, test0.ToSqlInt16().Value);
            Assert.Equal((short)288, test288.ToSqlInt16().Value);

            // ToSqlMoney ()
            Assert.Equal(12.0000M, test12.ToSqlMoney().Value);
            Assert.Equal(0, test0.ToSqlMoney().Value);
            Assert.Equal(288.0000M, test288.ToSqlMoney().Value);

            // ToSqlSingle ()
            Assert.Equal(12, test12.ToSqlSingle().Value);
            Assert.Equal(0, test0.ToSqlSingle().Value);
            Assert.Equal(288, test288.ToSqlSingle().Value);

            // ToSqlString ()
            Assert.Equal("12", test12.ToSqlString().Value);
            Assert.Equal("0", test0.ToSqlString().Value);
            Assert.Equal("288", test288.ToSqlString().Value);

            // ToString ()
            Assert.Equal("12", test12.ToString());
            Assert.Equal("0", test0.ToString());
            Assert.Equal("288", test288.ToString());
        }
示例#2
0
        public void Conversions()
        {
            SqlInt64 Test12   = new SqlInt64(12);
            SqlInt64 Test0    = new SqlInt64(0);
            SqlInt64 TestNull = SqlInt64.Null;
            SqlInt64 Test1000 = new SqlInt64(1000);
            SqlInt64 Test288  = new SqlInt64(288);

            // ToSqlBoolean ()
            Assert.IsTrue(Test12.ToSqlBoolean().Value, "#P01");
            Assert.IsTrue(!Test0.ToSqlBoolean().Value, "#P02");
            Assert.IsTrue(TestNull.ToSqlBoolean().IsNull, "#P03");

            // ToSqlByte ()
            Assert.AreEqual((byte)12, Test12.ToSqlByte().Value, "#P04");
            Assert.AreEqual((byte)0, Test0.ToSqlByte().Value, "#P05");

            try {
                SqlByte b = (byte)Test1000.ToSqlByte();
                Assert.Fail("#P06");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#P07");
            }

            // ToSqlDecimal ()
            Assert.AreEqual((decimal)12, Test12.ToSqlDecimal().Value, "#P08");
            Assert.AreEqual((decimal)0, Test0.ToSqlDecimal().Value, "#P09");
            Assert.AreEqual((decimal)288, Test288.ToSqlDecimal().Value, "#P10");

            // ToSqlDouble ()
            Assert.AreEqual((double)12, Test12.ToSqlDouble().Value, "#P11");
            Assert.AreEqual((double)0, Test0.ToSqlDouble().Value, "#P12");
            Assert.AreEqual((double)1000, Test1000.ToSqlDouble().Value, "#P13");

            // ToSqlInt32 ()
            Assert.AreEqual((int)12, Test12.ToSqlInt32().Value, "#P14");
            Assert.AreEqual((int)0, Test0.ToSqlInt32().Value, "#P15");
            Assert.AreEqual((int)288, Test288.ToSqlInt32().Value, "#P16");

            // ToSqlInt16 ()
            Assert.AreEqual((short)12, Test12.ToSqlInt16().Value, "#P17");
            Assert.AreEqual((short)0, Test0.ToSqlInt16().Value, "#P18");
            Assert.AreEqual((short)288, Test288.ToSqlInt16().Value, "#P19");

            // ToSqlMoney ()
            Assert.AreEqual(12.0000M, Test12.ToSqlMoney().Value, "#P20");
            Assert.AreEqual((decimal)0, Test0.ToSqlMoney().Value, "#P21");
            Assert.AreEqual(288.0000M, Test288.ToSqlMoney().Value, "#P22");

            // ToSqlSingle ()
            Assert.AreEqual((float)12, Test12.ToSqlSingle().Value, "#P23");
            Assert.AreEqual((float)0, Test0.ToSqlSingle().Value, "#P24");
            Assert.AreEqual((float)288, Test288.ToSqlSingle().Value, "#P25");

            // ToSqlString ()
            Assert.AreEqual("12", Test12.ToSqlString().Value, "#P26");
            Assert.AreEqual("0", Test0.ToSqlString().Value, "#P27");
            Assert.AreEqual("288", Test288.ToSqlString().Value, "#P28");

            // ToString ()
            Assert.AreEqual("12", Test12.ToString(), "#P29");
            Assert.AreEqual("0", Test0.ToString(), "#P30");
            Assert.AreEqual("288", Test288.ToString(), "#P31");
        }
示例#3
0
        public override object Aggregate(int[] records, AggregateType kind)
        {
            bool flag = false;

            try
            {
                int       num;
                SqlDouble num2;
                SqlDouble num3;
                int       num4;
                int       num5;
                int       num6;
                int       num7;
                int       num8;
                int       num9;
                int       num10;
                int       num11;
                SqlByte   minValue;
                int       num13;
                SqlByte   maxValue;
                SqlDouble num15;
                int       num16;
                SqlInt64  num17;
                SqlInt64  num18;
                int[]     numArray;
                SqlDouble num19;
                int       num21;
                int[]     numArray2;
                int       num22;
                int[]     numArray3;
                switch (kind)
                {
                case AggregateType.Sum:
                    num18     = 0L;
                    numArray3 = records;
                    num10     = 0;
                    goto Label_007D;

                case AggregateType.Mean:
                    num17     = 0L;
                    num16     = 0;
                    numArray2 = records;
                    num9      = 0;
                    goto Label_00EF;

                case AggregateType.Min:
                    maxValue = SqlByte.MaxValue;
                    num6     = 0;
                    goto Label_0313;

                case AggregateType.Max:
                    minValue = SqlByte.MinValue;
                    num5     = 0;
                    goto Label_0392;

                case AggregateType.First:
                    if (records.Length <= 0)
                    {
                        return(null);
                    }
                    return(this.values[records[0]]);

                case AggregateType.Count:
                    num  = 0;
                    num4 = 0;
                    goto Label_03F7;

                case AggregateType.Var:
                case AggregateType.StDev:
                    num      = 0;
                    num2     = 0.0;
                    num19    = 0.0;
                    num3     = 0.0;
                    num15    = 0.0;
                    numArray = records;
                    num8     = 0;
                    goto Label_01E6;

                default:
                    goto Label_041C;
                }
Label_0044:
                num22 = numArray3[num10];
                if (!this.IsNull(num22))
                {
                    num18 += this.values[num22];
                    flag   = true;
                }
                num10++;
Label_007D:
                if (num10 < numArray3.Length)
                {
                    goto Label_0044;
                }
                if (flag)
                {
                    return(num18);
                }
                return(base.NullValue);

Label_00B5:
                num21 = numArray2[num9];
                if (!this.IsNull(num21))
                {
                    num17 += this.values[num21].ToSqlInt64();
                    num16++;
                    flag = true;
                }
                num9++;
Label_00EF:
                if (num9 < numArray2.Length)
                {
                    goto Label_00B5;
                }
                if (flag)
                {
                    SqlInt64 num23 = num17 / ((long)num16);
                    return(num23.ToSqlByte());
                }
                return(base.NullValue);

Label_017E:
                num7 = numArray[num8];
                if (!this.IsNull(num7))
                {
                    num3  += this.values[num7].ToSqlDouble();
                    num15 += this.values[num7].ToSqlDouble() * this.values[num7].ToSqlDouble();
                    num++;
                }
                num8++;
Label_01E6:
                if (num8 < numArray.Length)
                {
                    goto Label_017E;
                }
                if (num <= 1)
                {
                    return(base.NullValue);
                }
                num2  = ((SqlDouble)(num * num15)) - (num3 * num3);
                num19 = num2 / (num3 * num3);
                bool x = num19 < 1E-15;
                if (!SqlBoolean.op_True(x))
                {
                }
                if (SqlBoolean.op_True(x | (num2 < 0.0)))
                {
                    num2 = 0.0;
                }
                else
                {
                    num2 /= (double)(num * (num - 1));
                }
                if (kind == AggregateType.StDev)
                {
                    return(Math.Sqrt(num2.Value));
                }
                return(num2);

Label_02C3:
                num13 = records[num6];
                if (!this.IsNull(num13))
                {
                    if (SqlByte.LessThan(this.values[num13], maxValue).IsTrue)
                    {
                        maxValue = this.values[num13];
                    }
                    flag = true;
                }
                num6++;
Label_0313:
                if (num6 < records.Length)
                {
                    goto Label_02C3;
                }
                if (flag)
                {
                    return(maxValue);
                }
                return(base.NullValue);

Label_0342:
                num11 = records[num5];
                if (!this.IsNull(num11))
                {
                    if (SqlByte.GreaterThan(this.values[num11], minValue).IsTrue)
                    {
                        minValue = this.values[num11];
                    }
                    flag = true;
                }
                num5++;
Label_0392:
                if (num5 < records.Length)
                {
                    goto Label_0342;
                }
                if (flag)
                {
                    return(minValue);
                }
                return(base.NullValue);

Label_03E1:
                if (!this.IsNull(records[num4]))
                {
                    num++;
                }
                num4++;
Label_03F7:
                if (num4 < records.Length)
                {
                    goto Label_03E1;
                }
                return(num);
            }
            catch (OverflowException)
            {
                throw ExprException.Overflow(typeof(SqlByte));
            }
Label_041C:
            throw ExceptionBuilder.AggregateException(kind, base.DataType);
        }
示例#4
0
        public void Conversions()
        {
            SqlInt64 Test12   = new SqlInt64(12);
            SqlInt64 Test0    = new SqlInt64(0);
            SqlInt64 TestNull = SqlInt64.Null;
            SqlInt64 Test1000 = new SqlInt64(1000);
            SqlInt64 Test288  = new SqlInt64(288);

            // ToSqlBoolean ()
            Assert.True(Test12.ToSqlBoolean().Value);
            Assert.True(!Test0.ToSqlBoolean().Value);
            Assert.True(TestNull.ToSqlBoolean().IsNull);

            // ToSqlByte ()
            Assert.Equal((byte)12, Test12.ToSqlByte().Value);
            Assert.Equal((byte)0, Test0.ToSqlByte().Value);

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

            // ToSqlDecimal ()
            Assert.Equal(12, Test12.ToSqlDecimal().Value);
            Assert.Equal(0, Test0.ToSqlDecimal().Value);
            Assert.Equal(288, Test288.ToSqlDecimal().Value);

            // ToSqlDouble ()
            Assert.Equal(12, Test12.ToSqlDouble().Value);
            Assert.Equal(0, Test0.ToSqlDouble().Value);
            Assert.Equal(1000, Test1000.ToSqlDouble().Value);

            // ToSqlInt32 ()
            Assert.Equal(12, Test12.ToSqlInt32().Value);
            Assert.Equal(0, Test0.ToSqlInt32().Value);
            Assert.Equal(288, Test288.ToSqlInt32().Value);

            // ToSqlInt16 ()
            Assert.Equal((short)12, Test12.ToSqlInt16().Value);
            Assert.Equal((short)0, Test0.ToSqlInt16().Value);
            Assert.Equal((short)288, Test288.ToSqlInt16().Value);

            // ToSqlMoney ()
            Assert.Equal(12.0000M, Test12.ToSqlMoney().Value);
            Assert.Equal(0, Test0.ToSqlMoney().Value);
            Assert.Equal(288.0000M, Test288.ToSqlMoney().Value);

            // ToSqlSingle ()
            Assert.Equal(12, Test12.ToSqlSingle().Value);
            Assert.Equal(0, Test0.ToSqlSingle().Value);
            Assert.Equal(288, Test288.ToSqlSingle().Value);

            // ToSqlString ()
            Assert.Equal("12", Test12.ToSqlString().Value);
            Assert.Equal("0", Test0.ToSqlString().Value);
            Assert.Equal("288", Test288.ToSqlString().Value);

            // ToString ()
            Assert.Equal("12", Test12.ToString());
            Assert.Equal("0", Test0.ToString());
            Assert.Equal("288", Test288.ToString());
        }