Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Aggregate()

override object System.Data.Common.SqlInt16Storage.Aggregate ( int[] records,
AggregateType kind )
inlinevirtual

Reimplemented from System.Data.Common.DataStorage.

Definition at line 19 of file SqlInt16Storage.cs.

20 {
21 bool flag = false;
22 try
23 {
24 switch (kind)
25 {
26 case AggregateType.Sum:
27 {
29 foreach (int num3 in records)
30 {
31 if (!IsNull(num3))
32 {
34 flag = true;
35 }
36 }
37 if (flag)
38 {
39 return sqlInt2;
40 }
41 return _nullValue;
42 }
43 case AggregateType.Mean:
44 {
46 int num5 = 0;
47 foreach (int num6 in records)
48 {
49 if (!IsNull(num6))
50 {
52 num5++;
53 flag = true;
54 }
55 }
56 if (flag)
57 {
59 sqlInt4 = (sqlInt3 / num5).ToSqlInt16();
60 return sqlInt4;
61 }
62 return _nullValue;
63 }
64 case AggregateType.Var:
65 case AggregateType.StDev:
66 {
67 int num = 0;
68 SqlDouble sqlDouble = 0.0;
72 foreach (int num4 in records)
73 {
74 if (!IsNull(num4))
75 {
78 num++;
79 }
80 }
81 if (num > 1)
82 {
85 if (sqlDouble2 < 1E-15 || sqlDouble < 0.0)
86 {
87 sqlDouble = 0.0;
88 }
89 else
90 {
91 sqlDouble /= (SqlDouble)(num * (num - 1));
92 }
93 if (kind == AggregateType.StDev)
94 {
95 return Math.Sqrt(sqlDouble.Value);
96 }
97 return sqlDouble;
98 }
99 return _nullValue;
100 }
101 case AggregateType.Min:
102 {
104 foreach (int num2 in records)
105 {
106 if (!IsNull(num2))
107 {
108 if (SqlInt16.LessThan(_values[num2], sqlInt).IsTrue)
109 {
111 }
112 flag = true;
113 }
114 }
115 if (flag)
116 {
117 return sqlInt;
118 }
119 return _nullValue;
120 }
121 case AggregateType.Max:
122 {
124 foreach (int num7 in records)
125 {
126 if (!IsNull(num7))
127 {
129 {
131 }
132 flag = true;
133 }
134 }
135 if (flag)
136 {
137 return sqlInt5;
138 }
139 return _nullValue;
140 }
141 case AggregateType.First:
142 if (records.Length != 0)
143 {
144 return _values[records[0]];
145 }
146 return null;
147 case AggregateType.Count:
148 {
149 int num = 0;
150 for (int i = 0; i < records.Length; i++)
151 {
152 if (!IsNull(records[i]))
153 {
154 num++;
155 }
156 }
157 return num;
158 }
159 }
160 }
161 catch (OverflowException)
162 {
163 throw ExprException.Overflow(typeof(SqlInt16));
164 }
165 throw ExceptionBuilder.AggregateException(kind, _dataType);
166 }
static SqlBoolean LessThan(SqlInt16 x, SqlInt16 y)
Definition SqlInt16.cs:410
static SqlBoolean GreaterThan(SqlInt16 x, SqlInt16 y)
Definition SqlInt16.cs:415
static readonly SqlInt16 MinValue
Definition SqlInt16.cs:23
static readonly SqlInt16 MaxValue
Definition SqlInt16.cs:25

References System.Data.Common.DataStorage._dataType, System.Data.Common.DataStorage._nullValue, System.Data.Common.SqlInt16Storage._values, System.Data.ExceptionBuilder.AggregateException(), System.Xml.Dictionary, System.E, System.Data.SqlTypes.SqlInt16.GreaterThan(), System.Data.IsNull, System.L, System.Data.SqlTypes.SqlInt16.LessThan(), System.Data.SqlTypes.SqlInt16.MaxValue, System.Data.SqlTypes.SqlInt16.MinValue, System.Data.ExprException.Overflow(), System.Data.Common.SqlDouble, System.Data.Common.SqlInt64, System.Math.Sqrt(), System.Data.SqlTypes.SqlInt16.ToSqlDouble(), and System.Data.SqlTypes.SqlInt16.ToSqlInt64().