Skip to content

Commit b51be83

Browse files
author
mw
committed
BugFix npgsql#198 NpgsqlParameter with Type NpgsqlTimeStampTZ is not inserted with TimeZone prefix (e.g. +00)
1 parent 79a2c7e commit b51be83

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

Npgsql/Npgsql/NpgsqlCommand.Rewrite.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ private void AppendParameterValues(Stream dest)
610610

611611
private void AppendParameterValue(Stream dest, NpgsqlParameter parameter)
612612
{
613-
byte[] serialised = parameter.TypeInfo.ConvertToBackend(parameter.Value, false, Connector.NativeToBackendTypeConverterOptions);
613+
byte[] serialised = parameter.TypeInfo.ConvertToBackend(parameter.NpgsqlValue, false, Connector.NativeToBackendTypeConverterOptions);
614614

615615
// Add parentheses wrapping parameter value before the type cast to avoid problems with Int16.MinValue, Int32.MinValue and Int64.MinValue
616616
// See bug #1010543

tests/CommandTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,36 @@ public void ProviderDateTimeSupportTimezone3()
12481248
}
12491249
}
12501250

1251+
[Test]
1252+
public void ProviderDateTimeSupportTimezone4()
1253+
{
1254+
ExecuteNonQuery("SET TIME ZONE 5"); //Should not be equal to your local time zone !
1255+
1256+
NpgsqlTimeStampTZ tsInsert = new NpgsqlTimeStampTZ(2014, 3, 28, 10, 0, 0, NpgsqlTimeZone.UTC);
1257+
1258+
using (var command = new NpgsqlCommand("INSERT INTO data(field_timestamp_with_timezone) VALUES (:p1)", Conn))
1259+
{
1260+
var p1 = command.Parameters.Add("p1", NpgsqlDbType.TimestampTZ);
1261+
p1.Direction = ParameterDirection.Input;
1262+
p1.Value = tsInsert;
1263+
1264+
command.ExecuteNonQuery();
1265+
}
1266+
1267+
1268+
using (var command = new NpgsqlCommand("SELECT field_timestamp_with_timezone FROM data", Conn))
1269+
{
1270+
NpgsqlTimeStampTZ tsSelect;
1271+
using (var reader = command.ExecuteReader())
1272+
{
1273+
reader.Read();
1274+
tsSelect = reader.GetTimeStampTZ(0);
1275+
}
1276+
1277+
Assert.AreEqual(tsInsert.AtTimeZone(NpgsqlTimeZone.UTC), tsSelect.AtTimeZone(NpgsqlTimeZone.UTC));
1278+
}
1279+
}
1280+
12511281
[Test]
12521282
public void DoubleValueSupportWithExtendedQuery()
12531283
{

0 commit comments

Comments
 (0)