public User[] Get(NpgsqlConnection connection, CriteriaType criteriaType, string name, int count) { IWhereOp whereOp; bool asc; switch (criteriaType) { case CriteriaType.DownFromInfinity: whereOp = null; asc = true; break; case CriteriaType.DownFrom: whereOp = new Gt(DbStr.Name, name); asc = true; break; case CriteriaType.DownFromOrEqual: whereOp = new Ge(DbStr.Name, name); asc = true; break; case CriteriaType.UpFromInfinity: whereOp = null; asc = false; break; case CriteriaType.UpFrom: whereOp = new Lt(DbStr.Name, name); asc = false; break; case CriteriaType.UpFromOrEqual: whereOp = new Le(DbStr.Name, name); asc = false; break; default: throw new NotSupportedException("CriteriaType " + criteriaType); } var limit = Math.Min(count, MaxUsersToRetrieve); var query = _npgQueryHelper.Select( DbStr.Users, _userColumns, whereOp, new[] { DbStr.Name }, asc, limit); var users = _npgHelper.ExecuteReader(connection, query, GetUser); return asc ? users : users.Reverse().ToArray(); }
public LogItem[] GetItems( NpgsqlConnection connection, CriteriaType criteriaType, DateTime criteria, int maxCount, bool includeBytes) { IWhereOp whereOp; bool asc; switch (criteriaType) { case CriteriaType.DownFromInfinity: whereOp = null; asc = false; break; case CriteriaType.DownFrom: whereOp = new Lt(DbStr.Time, criteria.Ticks); asc = false; break; case CriteriaType.DownFromOrEqual: whereOp = new Le(DbStr.Time, criteria.Ticks); asc = false; break; case CriteriaType.UpFromInfinity: whereOp = null; asc = true; break; case CriteriaType.UpFrom: whereOp = new Gt(DbStr.Time, criteria.Ticks); asc = true; break; case CriteriaType.UpFromOrEqual: whereOp = new Ge(DbStr.Time, criteria.Ticks); asc = true; break; default: throw new NotSupportedException("CriteriaType " + criteriaType); } var columns = includeBytes ? _columns : _columnsWithoutBytes; var query = _npgQueryHelper.Select( _tableName, columns, whereOp, new[] { DbStr.Time }, asc, Math.Min(maxCount, MaxItemsToRetrieve)); var alarms = _npgHelper.ExecuteReader(connection, query, reader => { var i = new LogItem { Time = reader.GetDateTimeFormTicks(0), Text = reader.GetNullableString(1) }; if (includeBytes) { i.Bytes = reader.GetByteArray(2); } return i; }); return asc ? alarms.Reverse().ToArray() : alarms; }
public Tuple<DateTime, double?[]>[] GetPage(int[] trendTagIds, CriteriaType criteriaType, DateTime criteria, int maxCount) { IWhereOp whereOp; bool asc; switch (criteriaType) { case CriteriaType.DownFromInfinity: whereOp = null; asc = false; break; case CriteriaType.DownFrom: whereOp = new Lt(DbStr.Time, criteria.Ticks); asc = false; break; case CriteriaType.DownFromOrEqual: whereOp = new Le(DbStr.Time, criteria.Ticks); asc = false; break; case CriteriaType.UpFromInfinity: whereOp = null; asc = true; break; case CriteriaType.UpFrom: whereOp = new Gt(DbStr.Time, criteria.Ticks); asc = true; break; case CriteriaType.UpFromOrEqual: whereOp = new Ge(DbStr.Time, criteria.Ticks); asc = true; break; default: throw new NotSupportedException("CriteriaType " + criteriaType); } var columns = new List<string>(trendTagIds.Length + 1) { DbStr.Time }; columns.AddRange(trendTagIds.Select(GetColumnName)); var columnsArr = columns.ToArray(); var limit = Math.Min(maxCount, MaxSamplesToRetrieve); var parameters = new List<NpgsqlParameter>(); var queryTexts = new List<string>(); for (var i = 0; i < TrendTableSelector.TablesCount; i++) { var queryText = _npgQueryHelper.Select( parameters, _tableName + "_" + i, columnsArr, whereOp, ColumnsOfTime, asc, limit); queryTexts.Add(queryText); } var query = _npgQueryHelper.Union(parameters, queryTexts, ColumnsOfTime, asc, limit); var result = _npgHelper.ExecuteReader(_connection, query, reader => { var time = reader.GetDateTimeFormTicks(0); var values = new double?[columns.Count - 1]; for (var j = 1; j < columns.Count; j++) { values[j - 1] = reader.GetNullableDouble(j); } return new Tuple<DateTime, double?[]>(time, values); }); return asc ? result.Reverse().ToArray() : result; }