Skip to content

Commit 3d2a0af

Browse files
authored
Obsolete the provider-specific date/time types (#4019)
Allow reading timestamps as long, dates as int, and intervals as the newly-introduced NpgsqlInterval. All these are raw PostgreSQL representations. Closes #2009
1 parent 8f5b01b commit 3d2a0af

25 files changed

+355
-49
lines changed

src/Npgsql.NodaTime/Internal/DateHandler.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
using NpgsqlTypes;
88
using BclDateHandler = Npgsql.Internal.TypeHandlers.DateTimeHandlers.DateHandler;
99

10+
#pragma warning disable 618 // NpgsqlDate is obsolete, remove in 7.0
11+
1012
namespace Npgsql.NodaTime.Internal
1113
{
12-
sealed partial class DateHandler : NpgsqlSimpleTypeHandler<LocalDate>, INpgsqlSimpleTypeHandler<DateTime>, INpgsqlSimpleTypeHandler<NpgsqlDate>
14+
sealed partial class DateHandler : NpgsqlSimpleTypeHandler<LocalDate>,
15+
INpgsqlSimpleTypeHandler<DateTime>, INpgsqlSimpleTypeHandler<NpgsqlDate>, INpgsqlSimpleTypeHandler<int>
1316
#if NET6_0_OR_GREATER
1417
, INpgsqlSimpleTypeHandler<DateOnly>
1518
#endif
@@ -82,6 +85,15 @@ int INpgsqlSimpleTypeHandler<DateTime>.ValidateAndGetLength(DateTime value, Npgs
8285
void INpgsqlSimpleTypeHandler<DateTime>.Write(DateTime value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
8386
=> _bclHandler.Write(value, buf, parameter);
8487

88+
int INpgsqlSimpleTypeHandler<int>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
89+
=> _bclHandler.Read<int>(buf, len, fieldDescription);
90+
91+
int INpgsqlSimpleTypeHandler<int>.ValidateAndGetLength(int value, NpgsqlParameter? parameter)
92+
=> _bclHandler.ValidateAndGetLength(value, parameter);
93+
94+
void INpgsqlSimpleTypeHandler<int>.Write(int value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
95+
=> _bclHandler.Write(value, buf, parameter);
96+
8597
#if NET6_0_OR_GREATER
8698
DateOnly INpgsqlSimpleTypeHandler<DateOnly>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
8799
=> _bclHandler.Read<DateOnly>(buf, len, fieldDescription);

src/Npgsql.NodaTime/Internal/IntervalHandler.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
using NpgsqlTypes;
88
using BclIntervalHandler = Npgsql.Internal.TypeHandlers.DateTimeHandlers.IntervalHandler;
99

10+
#pragma warning disable 618 // NpgsqlTimeSpan is obsolete, remove in 7.0
11+
1012
namespace Npgsql.NodaTime.Internal
1113
{
1214
sealed partial class IntervalHandler :
1315
NpgsqlSimpleTypeHandler<Period>,
1416
INpgsqlSimpleTypeHandler<Duration>,
1517
INpgsqlSimpleTypeHandler<NpgsqlTimeSpan>,
16-
INpgsqlSimpleTypeHandler<TimeSpan>
18+
INpgsqlSimpleTypeHandler<TimeSpan>,
19+
INpgsqlSimpleTypeHandler<NpgsqlInterval>
1720
{
1821
readonly BclIntervalHandler _bclHandler;
1922

@@ -103,5 +106,14 @@ int INpgsqlSimpleTypeHandler<TimeSpan>.ValidateAndGetLength(TimeSpan value, Npgs
103106

104107
void INpgsqlSimpleTypeHandler<TimeSpan>.Write(TimeSpan value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
105108
=> ((INpgsqlSimpleTypeHandler<TimeSpan>)_bclHandler).Write(value, buf, parameter);
109+
110+
NpgsqlInterval INpgsqlSimpleTypeHandler<NpgsqlInterval>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
111+
=> _bclHandler.Read<NpgsqlInterval>(buf, len, fieldDescription);
112+
113+
int INpgsqlSimpleTypeHandler<NpgsqlInterval>.ValidateAndGetLength(NpgsqlInterval value, NpgsqlParameter? parameter)
114+
=> ((INpgsqlSimpleTypeHandler<NpgsqlInterval>)_bclHandler).ValidateAndGetLength(value, parameter);
115+
116+
void INpgsqlSimpleTypeHandler<NpgsqlInterval>.Write(NpgsqlInterval value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
117+
=> ((INpgsqlSimpleTypeHandler<NpgsqlInterval>)_bclHandler).Write(value, buf, parameter);
106118
}
107119
}

src/Npgsql.NodaTime/Internal/LegacyTimestampHandler.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Npgsql.NodaTime.Internal
1111
{
1212
sealed partial class LegacyTimestampHandler : NpgsqlSimpleTypeHandler<Instant>,
13-
INpgsqlSimpleTypeHandler<LocalDateTime>, INpgsqlSimpleTypeHandler<DateTime>
13+
INpgsqlSimpleTypeHandler<LocalDateTime>, INpgsqlSimpleTypeHandler<DateTime>, INpgsqlSimpleTypeHandler<long>
1414
{
1515
readonly bool _convertInfinityDateTime;
1616
readonly BclTimestampHandler _bclHandler;
@@ -33,6 +33,9 @@ LocalDateTime INpgsqlSimpleTypeHandler<LocalDateTime>.Read(NpgsqlReadBuffer buf,
3333
DateTime INpgsqlSimpleTypeHandler<DateTime>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
3434
=> _bclHandler.Read(buf, len, fieldDescription);
3535

36+
long INpgsqlSimpleTypeHandler<long>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
37+
=> ((INpgsqlSimpleTypeHandler<long>)_bclHandler).Read(buf, len, fieldDescription);
38+
3639
#endregion Read
3740

3841
#region Write
@@ -52,9 +55,15 @@ void INpgsqlSimpleTypeHandler<LocalDateTime>.Write(LocalDateTime value, NpgsqlWr
5255
int INpgsqlSimpleTypeHandler<DateTime>.ValidateAndGetLength(DateTime value, NpgsqlParameter? parameter)
5356
=> ((INpgsqlSimpleTypeHandler<DateTime>)_bclHandler).ValidateAndGetLength(value, parameter);
5457

58+
public int ValidateAndGetLength(long value, NpgsqlParameter? parameter)
59+
=> ((INpgsqlSimpleTypeHandler<long>)_bclHandler).ValidateAndGetLength(value, parameter);
60+
5561
void INpgsqlSimpleTypeHandler<DateTime>.Write(DateTime value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
5662
=> ((INpgsqlSimpleTypeHandler<DateTime>)_bclHandler).Write(value, buf, parameter);
5763

64+
void INpgsqlSimpleTypeHandler<long>.Write(long value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
65+
=> ((INpgsqlSimpleTypeHandler<long>)_bclHandler).Write(value, buf, parameter);
66+
5867
#endregion Write
5968
}
6069
}

src/Npgsql.NodaTime/Internal/LegacyTimestampTzHandler.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Npgsql.NodaTime.Internal
1111
{
1212
sealed partial class LegacyTimestampTzHandler : NpgsqlSimpleTypeHandler<Instant>, INpgsqlSimpleTypeHandler<ZonedDateTime>,
1313
INpgsqlSimpleTypeHandler<OffsetDateTime>, INpgsqlSimpleTypeHandler<DateTimeOffset>,
14-
INpgsqlSimpleTypeHandler<DateTime>
14+
INpgsqlSimpleTypeHandler<DateTime>, INpgsqlSimpleTypeHandler<long>
1515
{
1616
readonly IDateTimeZoneProvider _dateTimeZoneProvider;
1717
readonly TimestampTzHandler _wrappedHandler;
@@ -59,6 +59,9 @@ DateTimeOffset INpgsqlSimpleTypeHandler<DateTimeOffset>.Read(NpgsqlReadBuffer bu
5959
DateTime INpgsqlSimpleTypeHandler<DateTime>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
6060
=> _wrappedHandler.Read<DateTime>(buf, len, fieldDescription);
6161

62+
long INpgsqlSimpleTypeHandler<long>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
63+
=> _wrappedHandler.Read<long>(buf, len, fieldDescription);
64+
6265
#endregion Read
6366

6467
#region Write
@@ -93,6 +96,12 @@ int INpgsqlSimpleTypeHandler<DateTime>.ValidateAndGetLength(DateTime value, Npgs
9396
void INpgsqlSimpleTypeHandler<DateTime>.Write(DateTime value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
9497
=> ((INpgsqlSimpleTypeHandler<DateTime>)_wrappedHandler).Write(value, buf, parameter);
9598

99+
int INpgsqlSimpleTypeHandler<long>.ValidateAndGetLength(long value, NpgsqlParameter? parameter)
100+
=> ((INpgsqlSimpleTypeHandler<long>)_wrappedHandler).ValidateAndGetLength(value, parameter);
101+
102+
void INpgsqlSimpleTypeHandler<long>.Write(long value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
103+
=> ((INpgsqlSimpleTypeHandler<long>)_wrappedHandler).Write(value, buf, parameter);
104+
96105
#endregion Write
97106
}
98107
}

src/Npgsql.NodaTime/Internal/TimestampHandler.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
namespace Npgsql.NodaTime.Internal
1111
{
12-
sealed partial class TimestampHandler : NpgsqlSimpleTypeHandler<LocalDateTime>, INpgsqlSimpleTypeHandler<DateTime>
12+
sealed partial class TimestampHandler : NpgsqlSimpleTypeHandler<LocalDateTime>,
13+
INpgsqlSimpleTypeHandler<DateTime>, INpgsqlSimpleTypeHandler<long>
1314
{
1415
readonly BclTimestampHandler _bclHandler;
1516

@@ -35,6 +36,9 @@ internal static LocalDateTime ReadLocalDateTime(NpgsqlReadBuffer buf)
3536
DateTime INpgsqlSimpleTypeHandler<DateTime>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
3637
=> _bclHandler.Read(buf, len, fieldDescription);
3738

39+
long INpgsqlSimpleTypeHandler<long>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
40+
=> ((INpgsqlSimpleTypeHandler<long>)_bclHandler).Read(buf, len, fieldDescription);
41+
3842
#endregion Read
3943

4044
#region Write
@@ -48,12 +52,18 @@ public override void Write(LocalDateTime value, NpgsqlWriteBuffer buf, NpgsqlPar
4852
internal static void WriteLocalDateTime(LocalDateTime value, NpgsqlWriteBuffer buf)
4953
=> buf.WriteInt64(EncodeInstant(value.InUtc().ToInstant()));
5054

51-
int INpgsqlSimpleTypeHandler<DateTime>.ValidateAndGetLength(DateTime value, NpgsqlParameter? parameter)
55+
public int ValidateAndGetLength(DateTime value, NpgsqlParameter? parameter)
5256
=> ((INpgsqlSimpleTypeHandler<DateTime>)_bclHandler).ValidateAndGetLength(value, parameter);
5357

58+
public int ValidateAndGetLength(long value, NpgsqlParameter? parameter)
59+
=> ((INpgsqlSimpleTypeHandler<long>)_bclHandler).ValidateAndGetLength(value, parameter);
60+
5461
void INpgsqlSimpleTypeHandler<DateTime>.Write(DateTime value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
5562
=> ((INpgsqlSimpleTypeHandler<DateTime>)_bclHandler).Write(value, buf, parameter);
5663

64+
void INpgsqlSimpleTypeHandler<long>.Write(long value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
65+
=> ((INpgsqlSimpleTypeHandler<long>)_bclHandler).Write(value, buf, parameter);
66+
5767
#endregion Write
5868
}
5969
}

src/Npgsql.NodaTime/Internal/TimestampTzHandler.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Npgsql.NodaTime.Internal
1111
{
1212
sealed partial class TimestampTzHandler : NpgsqlSimpleTypeHandler<Instant>, INpgsqlSimpleTypeHandler<ZonedDateTime>,
1313
INpgsqlSimpleTypeHandler<OffsetDateTime>, INpgsqlSimpleTypeHandler<DateTimeOffset>,
14-
INpgsqlSimpleTypeHandler<DateTime>
14+
INpgsqlSimpleTypeHandler<DateTime>, INpgsqlSimpleTypeHandler<long>
1515
{
1616
readonly BclTimestampTzHandler _bclHandler;
1717
readonly bool _convertInfinityDateTime;
@@ -48,6 +48,9 @@ DateTimeOffset INpgsqlSimpleTypeHandler<DateTimeOffset>.Read(NpgsqlReadBuffer bu
4848
DateTime INpgsqlSimpleTypeHandler<DateTime>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
4949
=> _bclHandler.Read<DateTime>(buf, len, fieldDescription);
5050

51+
long INpgsqlSimpleTypeHandler<long>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
52+
=> ((INpgsqlSimpleTypeHandler<long>)_bclHandler).Read(buf, len, fieldDescription);
53+
5154
#endregion Read
5255

5356
#region Write
@@ -117,9 +120,15 @@ void INpgsqlSimpleTypeHandler<DateTimeOffset>.Write(DateTimeOffset value, Npgsql
117120
int INpgsqlSimpleTypeHandler<DateTime>.ValidateAndGetLength(DateTime value, NpgsqlParameter? parameter)
118121
=> ((INpgsqlSimpleTypeHandler<DateTime>)_bclHandler).ValidateAndGetLength(value, parameter);
119122

123+
public int ValidateAndGetLength(long value, NpgsqlParameter? parameter)
124+
=> ((INpgsqlSimpleTypeHandler<long>)_bclHandler).ValidateAndGetLength(value, parameter);
125+
120126
void INpgsqlSimpleTypeHandler<DateTime>.Write(DateTime value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
121127
=> _bclHandler.Write(value, buf, parameter);
122128

129+
void INpgsqlSimpleTypeHandler<long>.Write(long value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
130+
=> ((INpgsqlSimpleTypeHandler<long>)_bclHandler).Write(value, buf, parameter);
131+
123132
#endregion Write
124133
}
125134
}

src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/DateHandler.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using Npgsql.PostgresTypes;
77
using NpgsqlTypes;
88

9+
#pragma warning disable 618 // NpgsqlDate is obsolete, remove in 7.0
10+
911
namespace Npgsql.Internal.TypeHandlers.DateTimeHandlers
1012
{
1113
/// <summary>
@@ -18,7 +20,8 @@ namespace Npgsql.Internal.TypeHandlers.DateTimeHandlers
1820
/// should be considered somewhat unstable, and may change in breaking ways, including in non-major releases.
1921
/// Use it at your own risk.
2022
/// </remarks>
21-
public partial class DateHandler : NpgsqlSimpleTypeHandlerWithPsv<DateTime, NpgsqlDate>
23+
public partial class DateHandler : NpgsqlSimpleTypeHandlerWithPsv<DateTime, NpgsqlDate>,
24+
INpgsqlSimpleTypeHandler<int>
2225
#if NET6_0_OR_GREATER
2326
, INpgsqlSimpleTypeHandler<DateOnly>
2427
#endif
@@ -67,6 +70,9 @@ protected override NpgsqlDate ReadPsv(NpgsqlReadBuffer buf, int len, FieldDescri
6770
};
6871
}
6972

73+
int INpgsqlSimpleTypeHandler<int>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
74+
=> buf.ReadInt32();
75+
7076
#endregion Read
7177

7278
#region Write
@@ -77,6 +83,9 @@ protected override NpgsqlDate ReadPsv(NpgsqlReadBuffer buf, int len, FieldDescri
7783
/// <inheritdoc />
7884
public override int ValidateAndGetLength(NpgsqlDate value, NpgsqlParameter? parameter) => 4;
7985

86+
/// <inheritdoc />
87+
public int ValidateAndGetLength(int value, NpgsqlParameter? parameter) => 4;
88+
8089
/// <inheritdoc />
8190
public override void Write(DateTime value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
8291
{
@@ -107,6 +116,10 @@ public override void Write(NpgsqlDate value, NpgsqlWriteBuffer buf, NpgsqlParame
107116
buf.WriteInt32(value.DaysSinceEra - 730119);
108117
}
109118

119+
/// <inheritdoc />
120+
public void Write(int value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
121+
=> buf.WriteInt32(value);
122+
110123
#endregion Write
111124

112125
#if NET6_0_OR_GREATER

src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/DateTimeUtils.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ internal static DateTime ReadDateTime(NpgsqlReadBuffer buf, bool convertInfinity
3737
}
3838
}
3939

40+
#pragma warning disable 618 // NpgsqlDateTime is obsolete, remove in 7.0
4041
internal static NpgsqlDateTime ReadNpgsqlDateTime(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null)
4142
{
4243
var value = buf.ReadInt64();
@@ -71,6 +72,7 @@ internal static NpgsqlDateTime ReadNpgsqlDateTime(NpgsqlReadBuffer buf, int len,
7172
return new NpgsqlDateTime(new NpgsqlDate(date), new TimeSpan(time));
7273
}
7374
}
75+
#pragma warning restore 618
7476

7577
internal static void WriteTimestamp(DateTime value, NpgsqlWriteBuffer buf, bool convertInfinityDateTime)
7678
{
@@ -90,6 +92,7 @@ internal static void WriteTimestamp(DateTime value, NpgsqlWriteBuffer buf, bool
9092
buf.WriteInt64(postgresTimestamp);
9193
}
9294

95+
#pragma warning disable 618 // NpgsqlDateTime is obsolete, remove in 7.0
9396
internal static void WriteTimestamp(NpgsqlDateTime value, NpgsqlWriteBuffer buf, bool convertInfinityDateTime)
9497
{
9598
if (value.IsInfinity)
@@ -117,5 +120,6 @@ internal static void WriteTimestamp(NpgsqlDateTime value, NpgsqlWriteBuffer buf,
117120
buf.WriteInt64(uSecsTime - uSecsDate);
118121
}
119122
}
123+
#pragma warning restore 618
120124
}
121125
}

src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/IntervalHandler.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
using Npgsql.BackendMessages;
33
using Npgsql.Internal.TypeHandling;
44
using Npgsql.PostgresTypes;
5-
using Npgsql.TypeMapping;
65
using NpgsqlTypes;
76

7+
#pragma warning disable 618 // NpgsqlTimeSpan is obsolete, remove in 7.0
8+
89
namespace Npgsql.Internal.TypeHandlers.DateTimeHandlers
910
{
1011
/// <summary>
@@ -17,7 +18,8 @@ namespace Npgsql.Internal.TypeHandlers.DateTimeHandlers
1718
/// should be considered somewhat unstable, and may change in breaking ways, including in non-major releases.
1819
/// Use it at your own risk.
1920
/// </remarks>
20-
public partial class IntervalHandler : NpgsqlSimpleTypeHandlerWithPsv<TimeSpan, NpgsqlTimeSpan>
21+
public partial class IntervalHandler : NpgsqlSimpleTypeHandlerWithPsv<TimeSpan, NpgsqlTimeSpan>,
22+
INpgsqlSimpleTypeHandler<NpgsqlInterval>
2123
{
2224
/// <summary>
2325
/// Constructs an <see cref="IntervalHandler"/>
@@ -37,12 +39,23 @@ protected override NpgsqlTimeSpan ReadPsv(NpgsqlReadBuffer buf, int len, FieldDe
3739
return new NpgsqlTimeSpan(month, day, ticks * 10);
3840
}
3941

42+
NpgsqlInterval INpgsqlSimpleTypeHandler<NpgsqlInterval>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
43+
{
44+
var ticks = buf.ReadInt64();
45+
var day = buf.ReadInt32();
46+
var month = buf.ReadInt32();
47+
return new NpgsqlInterval(month, day, ticks);
48+
}
49+
4050
/// <inheritdoc />
4151
public override int ValidateAndGetLength(TimeSpan value, NpgsqlParameter? parameter) => 16;
4252

4353
/// <inheritdoc />
4454
public override int ValidateAndGetLength(NpgsqlTimeSpan value, NpgsqlParameter? parameter) => 16;
4555

56+
/// <inheritdoc />
57+
public int ValidateAndGetLength(NpgsqlInterval value, NpgsqlParameter? parameter) => 16;
58+
4659
/// <inheritdoc />
4760
public override void Write(NpgsqlTimeSpan value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
4861
{
@@ -55,5 +68,12 @@ public override void Write(NpgsqlTimeSpan value, NpgsqlWriteBuffer buf, NpgsqlPa
5568
/// <inheritdoc />
5669
public override void Write(TimeSpan value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
5770
=> Write(value, buf, parameter);
71+
72+
public void Write(NpgsqlInterval value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
73+
{
74+
buf.WriteInt64(value.Time);
75+
buf.WriteInt32(value.Days);
76+
buf.WriteInt32(value.Months);
77+
}
5878
}
5979
}

src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/TimestampHandler.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using static Npgsql.Util.Statics;
77
using static Npgsql.Internal.TypeHandlers.DateTimeHandlers.DateTimeUtils;
88

9+
#pragma warning disable 618 // NpgsqlDateTime is obsolete, remove in 7.0
10+
911
namespace Npgsql.Internal.TypeHandlers.DateTimeHandlers
1012
{
1113
/// <summary>
@@ -18,7 +20,7 @@ namespace Npgsql.Internal.TypeHandlers.DateTimeHandlers
1820
/// should be considered somewhat unstable, and may change in breaking ways, including in non-major releases.
1921
/// Use it at your own risk.
2022
/// </remarks>
21-
public partial class TimestampHandler : NpgsqlSimpleTypeHandlerWithPsv<DateTime, NpgsqlDateTime>
23+
public partial class TimestampHandler : NpgsqlSimpleTypeHandlerWithPsv<DateTime, NpgsqlDateTime>, INpgsqlSimpleTypeHandler<long>
2224
{
2325
/// <summary>
2426
/// Whether to convert positive and negative infinity values to DateTime.{Max,Min}Value when
@@ -43,6 +45,9 @@ public override DateTime Read(NpgsqlReadBuffer buf, int len, FieldDescription? f
4345
protected override NpgsqlDateTime ReadPsv(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null)
4446
=> ReadNpgsqlDateTime(buf, len, fieldDescription);
4547

48+
long INpgsqlSimpleTypeHandler<long>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
49+
=> buf.ReadInt64();
50+
4651
#endregion Read
4752

4853
#region Write
@@ -75,6 +80,9 @@ public override int ValidateAndGetLength(NpgsqlDateTime value, NpgsqlParameter?
7580
return 8;
7681
}
7782

83+
/// <inheritdoc />
84+
public int ValidateAndGetLength(long value, NpgsqlParameter? parameter) => 8;
85+
7886
/// <inheritdoc />
7987
public override void Write(DateTime value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
8088
=> WriteTimestamp(value, buf, ConvertInfinityDateTime);
@@ -83,6 +91,10 @@ public override void Write(DateTime value, NpgsqlWriteBuffer buf, NpgsqlParamete
8391
public override void Write(NpgsqlDateTime value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
8492
=> WriteTimestamp(value, buf, ConvertInfinityDateTime);
8593

94+
/// <inheritdoc />
95+
public void Write(long value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
96+
=> buf.WriteInt64(value);
97+
8698
#endregion Write
8799
}
88100
}

0 commit comments

Comments
 (0)