/// <summary> /// Retrieves batch values. /// The query append should start with " " or ";". /// </summary> /// <param name="append"></param> /// <returns></returns> public BatchValueCollection RetrieveBatchValues(string append) { BatchValueCollection values = new BatchValueCollection(); string[] queries = new string[3]; for (int i = 0; i < 3; i++) { queries[i] = "SELECT " + VALUE_TABLES[i] + ".value, " + VALUE_TABLES[i] + ".timestamp FROM " + VALUE_TABLES[i] + append; } lock (CONN_LOCK) { try { for (int i = 0; i < 3; i++) { CONN.Open(); NpgsqlCommand command = new NpgsqlCommand(queries[i], CONN); NpgsqlDataReader dr = command.ExecuteReader(); while (dr.Read()) { KeyValuePair <string, double> value = new KeyValuePair <string, double>(dr[1].ToString().Trim(), (double)dr[0]); if (i == 0) { values.TemperatureValues.Add(value); } else if (i == 1) { values.HumidityValues.Add(value); } else if (i == 2) { values.VibrationValues.Add(value); } } CONN.Close(); } } catch (NpgsqlException ex) { throw ex; } finally { CONN.Close(); } } return(values); }
public void RetrieveBatchValues() { BatchValueCollection values = dbManager.RetrieveBatchValues(1); Assert.IsNotNull(values); IList <KeyValuePair <string, double> >[] array = values.ToArray(); for (int i = 0; i < 3; i++) { if (array[i].Count != 0) { foreach (KeyValuePair <string, double> element in array[i]) { Assert.IsNotNull(element); } } else { Assert.IsNotNull(null); } } }