예제 #1
0
        public void Greaters()
        {
            SqlInt16 Test10   = new SqlInt16(10);
            SqlInt16 Test10II = new SqlInt16(10);
            SqlInt16 Test110  = new SqlInt16(110);

            // GreateThan ()
            Assert.IsTrue(!SqlInt16.GreaterThan(Test10, Test110).Value, "Test#1");
            Assert.IsTrue(SqlInt16.GreaterThan(Test110, Test10).Value, "Test#2");
            Assert.IsTrue(!SqlInt16.GreaterThan(Test10II, Test10).Value, "Test#3");

            // GreaterTharOrEqual ()
            Assert.IsTrue(!SqlInt16.GreaterThanOrEqual(Test10, Test110).Value, "Test#4");
            Assert.IsTrue(SqlInt16.GreaterThanOrEqual(Test110, Test10).Value, "Test#5");
            Assert.IsTrue(SqlInt16.GreaterThanOrEqual(Test10II, Test10).Value, "Test#6");
        }
예제 #2
0
        public void Greaters()
        {
            SqlInt16 test10   = new SqlInt16(10);
            SqlInt16 test10II = new SqlInt16(10);
            SqlInt16 test110  = new SqlInt16(110);

            // GreateThan ()
            Assert.False(SqlInt16.GreaterThan(test10, test110).Value);
            Assert.True(SqlInt16.GreaterThan(test110, test10).Value);
            Assert.False(SqlInt16.GreaterThan(test10II, test10).Value);

            // GreaterTharOrEqual ()
            Assert.False(SqlInt16.GreaterThanOrEqual(test10, test110).Value);
            Assert.True(SqlInt16.GreaterThanOrEqual(test110, test10).Value);
            Assert.True(SqlInt16.GreaterThanOrEqual(test10II, test10).Value);
        }
예제 #3
0
        public void Greaters()
        {
            SqlInt16 Test10   = new SqlInt16(10);
            SqlInt16 Test10II = new SqlInt16(10);
            SqlInt16 Test110  = new SqlInt16(110);

            // GreateThan ()
            Assert.True(!SqlInt16.GreaterThan(Test10, Test110).Value);
            Assert.True(SqlInt16.GreaterThan(Test110, Test10).Value);
            Assert.True(!SqlInt16.GreaterThan(Test10II, Test10).Value);

            // GreaterTharOrEqual ()
            Assert.True(!SqlInt16.GreaterThanOrEqual(Test10, Test110).Value);
            Assert.True(SqlInt16.GreaterThanOrEqual(Test110, Test10).Value);
            Assert.True(SqlInt16.GreaterThanOrEqual(Test10II, Test10).Value);
        }
예제 #4
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:
                    SqlInt64 meanSum   = 0;
                    int      meanCount = 0;
                    foreach (int record in records)
                    {
                        if (IsNull(record))
                        {
                            continue;
                        }
                        checked { meanSum += (_values[record]).ToSqlInt64(); }
                        meanCount++;
                        hasData = true;
                    }
                    if (hasData)
                    {
                        SqlInt16 mean = 0;
                        checked { mean = (meanSum / meanCount).ToSqlInt16(); }
                        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 /= (count * (count - 1));
                        }

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

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

                case AggregateType.Max:
                    SqlInt16 max = SqlInt16.MinValue;
                    for (int i = 0; i < records.Length; i++)
                    {
                        int record = records[i];
                        if (IsNull(record))
                        {
                            continue;
                        }
                        if ((SqlInt16.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(SqlInt16));
            }
            throw ExceptionBuilder.AggregateException(kind, _dataType);
        }
        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;
                SqlInt16  minValue;
                int       num13;
                SqlInt16  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 = SqlInt16.MaxValue;
                    num6     = 0;
                    goto Label_0313;

                case AggregateType.Max:
                    minValue = SqlInt16.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.ToSqlInt16());
                }
                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 (SqlInt16.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 (SqlInt16.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(SqlInt16));
            }
Label_041C:
            throw ExceptionBuilder.AggregateException(kind, base.DataType);
        }