public void ProviderDateTimeSupportNpgsqlDbType() { ExecuteNonQuery(@"insert into data (field_timestamp) values ('2002-02-02 09:00:23.345')"); var command = new NpgsqlCommand("select field_timestamp from data", Conn); NpgsqlTimeStamp ts; using (var reader = command.ExecuteReader()) { reader.Read(); ts = reader.GetTimeStamp(0); } Assert.AreEqual("2002-02-02 09:00:23.345", ts.ToString()); var culture = new DateTimeFormatInfo(); culture.TimeSeparator = ":"; var ts1 = NpgsqlTimeStamp.Parse("2004-06-04 09:48:00"); command.CommandText = "insert into data(field_timestamp) values (:a);"; command.Parameters.Add(new NpgsqlParameter("a", NpgsqlDbType.Timestamp)); command.Parameters[0].Value = ts1; command.ExecuteScalar(); }
internal static object ToTimeStamp(NpgsqlBackendTypeInfo typeInfo, byte[] bBackendData, Int16 typeSize, Int32 typeModifier) { string backendData = BackendEncoding.UTF8Encoding.GetString(bBackendData); return(NpgsqlTimeStamp.Parse(backendData)); }
NpgsqlTimeStampTZ ISimpleTypeReader <NpgsqlTimeStampTZ> .Read(NpgsqlBuffer buf, FieldDescription fieldDescription, int len) { // The Int64 contains just the time in UTC, no time zone information var ts = NpgsqlTimeStamp.FromInt64(buf.ReadInt64()); return(new NpgsqlTimeStampTZ(ts.Date, new NpgsqlTimeTZ(ts.Time, NpgsqlTimeZone.UTC))); }
public void Timestamp() { // TODO: Decide on the DateTime kind (#346) var expectedNpgsqlTimeStamp = new NpgsqlTimeStamp(new NpgsqlDate(2002, 2, 2), new NpgsqlTime(9, 0, 23.345)); var expectedDateTime = new DateTime(expectedNpgsqlTimeStamp.Ticks, DateTimeKind.Utc); using (var cmd = new NpgsqlCommand("SELECT '2002-02-02 09:00:23.345'::TIMESTAMP", Conn)) using (var reader = cmd.ExecuteReader()) { reader.Read(); // Regular type (DateTime) Assert.That(reader.GetFieldType(0), Is.EqualTo(typeof(DateTime))); Assert.That(reader.GetDateTime(0), Is.EqualTo(expectedDateTime)); Assert.That(reader.GetFieldValue <DateTime>(0), Is.EqualTo(expectedDateTime)); Assert.That(reader[0], Is.EqualTo(expectedDateTime)); Assert.That(reader.GetValue(0), Is.EqualTo(expectedDateTime)); // Provider-specific type (NpgsqlTimeStamp) Assert.That(reader.GetTimeStamp(0), Is.EqualTo(expectedNpgsqlTimeStamp)); Assert.That(reader.GetProviderSpecificFieldType(0), Is.EqualTo(typeof(NpgsqlTimeStamp))); Assert.That(reader.GetProviderSpecificValue(0), Is.EqualTo(expectedNpgsqlTimeStamp)); Assert.That(reader.GetFieldValue <NpgsqlTimeStamp>(0), Is.EqualTo(expectedNpgsqlTimeStamp)); } }
public List <listmac> Checkmacaddress() { var list = new List <listmac>(); MyCnx = new NpgsqlConnection(BDDJEE); MyCnx.Open(); NpgsqlTimeStamp date = DateTime.Now.AddMinutes(-15).ToLocalTime(); string select = "SELECT \"macAddress\" FROM \"metrics\" WHERE (date > timestamp \'" + date + "\')"; // SELECT "macAddress" FROM devices; MyCmd = new NpgsqlCommand(select, MyCnx); var reader = MyCmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) //créer la liste des metrics { // s = String.Format("{0}\t{1}\t{2}\t{3}", reader.GetInt32(0), reader.GetInt32(1), reader.GetTimeStamp(2), reader.GetInt32(3)); list.Add(new listmac(reader.GetString(0))); } } else { Console.WriteLine("No rows found."); list = null; } reader.Close(); return(list); }
public List <Metric> SelectAllMetricsQuarter() { var MyMetrics = new List <Metric>(); MyCnx = new NpgsqlConnection(BDDJEE); MyCnx.Open(); NpgsqlTimeStamp date = DateTime.Now.AddMinutes(-15).ToLocalTime(); string select = "SELECT * FROM \"metrics\" WHERE (date > timestamp \'" + date + "\')"; MyCmd = new NpgsqlCommand(select, MyCnx); var reader = MyCmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) //créer la liste des metrics { // s = String.Format("{0}\t{1}\t{2}\t{3}", reader.GetInt32(0), reader.GetInt32(1), reader.GetTimeStamp(2), reader.GetInt32(3)); MyMetrics.Add(new Metric(reader.GetTimeStamp(1), reader.GetInt32(2), reader.GetString(3))); } } else { Console.WriteLine("No rows found."); MyMetrics = null; } reader.Close(); MyCnx.Close(); return(MyMetrics); }
public void InsertMoyen(NpgsqlTimeStamp date, string macadress, Double value) { MyCnx = new NpgsqlConnection(BDDWindowsServer); string insert = "INSERT INTO \"average\"(date,macaddress,value) values(:date,:macaddress,:value)"; MyCnx.Open(); MyCmd = new NpgsqlCommand(insert, MyCnx); MyCmd.Parameters.Add(new NpgsqlParameter("date", NpgsqlDbType.Timestamp)).Value = date; MyCmd.Parameters.Add(new NpgsqlParameter("macaddress", NpgsqlDbType.Varchar)).Value = macadress; MyCmd.Parameters.Add(new NpgsqlParameter("value", NpgsqlDbType.Double)).Value = value; MyCmd.ExecuteNonQuery(); MyCnx.Close(); }
internal static object ToTimeStamp(NpgsqlBackendTypeInfo typeInfo, String backendData, Int16 typeSize, Int32 typeModifier) { return(NpgsqlTimeStamp.Parse(backendData)); }
public void Timestamp() { // TODO: Decide on the DateTime kind (#346) var expectedNpgsqlTimeStamp = new NpgsqlTimeStamp(new NpgsqlDate(2002, 2, 2), new NpgsqlTime(9, 0, 23.345)); var expectedDateTime = new DateTime(expectedNpgsqlTimeStamp.Ticks, DateTimeKind.Utc); using (var cmd = new NpgsqlCommand("SELECT '2002-02-02 09:00:23.345'::TIMESTAMP", Conn)) using (var reader = cmd.ExecuteReader()) { reader.Read(); // Regular type (DateTime) Assert.That(reader.GetFieldType(0), Is.EqualTo(typeof(DateTime))); Assert.That(reader.GetDateTime(0), Is.EqualTo(expectedDateTime)); Assert.That(reader.GetFieldValue<DateTime>(0), Is.EqualTo(expectedDateTime)); Assert.That(reader[0], Is.EqualTo(expectedDateTime)); Assert.That(reader.GetValue(0), Is.EqualTo(expectedDateTime)); // Provider-specific type (NpgsqlTimeStamp) Assert.That(reader.GetTimeStamp(0), Is.EqualTo(expectedNpgsqlTimeStamp)); Assert.That(reader.GetProviderSpecificFieldType(0), Is.EqualTo(typeof(NpgsqlTimeStamp))); Assert.That(reader.GetProviderSpecificValue(0), Is.EqualTo(expectedNpgsqlTimeStamp)); Assert.That(reader.GetFieldValue<NpgsqlTimeStamp>(0), Is.EqualTo(expectedNpgsqlTimeStamp)); } }