Skip to content

Commit 0aff2af

Browse files
committed
Revert "Adjust DateTime parameters"
This reverts commit cb2dad6.
1 parent c0516cc commit 0aff2af

File tree

3 files changed

+4
-28
lines changed

3 files changed

+4
-28
lines changed

src/NHibernate.Test/TypesTest/AbstractDateTimeTypeFixture.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ protected DateTimeKind GetTypeKind()
548548
}
549549
}
550550

551-
public class ClientDriverWithParamsStats : IDriver, IParameterAdjuster
551+
public class ClientDriverWithParamsStats : IDriver
552552
{
553553
private readonly Dictionary<SqlType, int> _usedSqlTypes = new Dictionary<SqlType, int>();
554554
private readonly Dictionary<DbType, int> _usedDbTypes = new Dictionary<DbType, int>();
@@ -679,11 +679,5 @@ void IDriver.AdjustCommand(DbCommand command)
679679
DateTime IDriver.MinDate => _driverImplementation.MinDate;
680680

681681
#endregion
682-
683-
public void AdjustParameterForValue(DbParameter parameter, SqlType sqlType, object value)
684-
{
685-
var adjustingDriver = _driverImplementation as IParameterAdjuster;
686-
adjustingDriver?.AdjustParameterForValue(parameter, sqlType, value);
687-
}
688682
}
689683
}

src/NHibernate/Driver/NpgsqlDriver.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
using System;
21
using System.Data;
32
using System.Data.Common;
43
using NHibernate.AdoNet;
5-
using NHibernate.SqlTypes;
64

75
namespace NHibernate.Driver
86
{
@@ -27,7 +25,7 @@ namespace NHibernate.Driver
2725
/// <a href="http://pgfoundry.org/projects/npgsql">http://pgfoundry.org/projects/npgsql</a>.
2826
/// </p>
2927
/// </remarks>
30-
public class NpgsqlDriver : ReflectionBasedDriver, IEmbeddedBatcherFactoryProvider, IParameterAdjuster
28+
public class NpgsqlDriver : ReflectionBasedDriver, IEmbeddedBatcherFactoryProvider
3129
{
3230
/// <summary>
3331
/// Initializes a new instance of the <see cref="NpgsqlDriver"/> class.
@@ -84,19 +82,10 @@ protected override void InitializeParameter(DbParameter dbParam, string name, Sq
8482

8583
// Prior to v3, Npgsql was expecting DateTime for time.
8684
// https://github.com/npgsql/npgsql/issues/347
87-
public override bool RequiresTimeSpanForTime => DriverVersionMajor >= 3;
88-
89-
private int DriverVersionMajor => DriverVersion?.Major ?? 3;
85+
public override bool RequiresTimeSpanForTime => (DriverVersion?.Major ?? 3) >= 3;
9086

9187
public override bool HasDelayedDistributedTransactionCompletion => true;
9288

9389
System.Type IEmbeddedBatcherFactoryProvider.BatcherFactoryClass => typeof(GenericBatchingBatcherFactory);
94-
public void AdjustParameterForValue(DbParameter parameter, SqlType sqlType, object value)
95-
{
96-
if (DriverVersionMajor >= 6 && sqlType.DbType == DbType.DateTime && value is DateTime time && time.Kind != DateTimeKind.Utc)
97-
{
98-
parameter.DbType = DbType.DateTime2;
99-
}
100-
}
10190
}
10291
}

src/NHibernate/Type/AbstractDateTimeType.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Collections.Generic;
44
using System.Data.Common;
55
using System.Globalization;
6-
using NHibernate.Driver;
76
using NHibernate.Engine;
87
using NHibernate.SqlTypes;
98

@@ -91,13 +90,7 @@ public override void Set(DbCommand st, object value, int index, ISessionImplemen
9190
// hour with daylight shift to be always wrongly converted. So better just fail.
9291
if (Kind != DateTimeKind.Unspecified && dateValue.Kind != Kind)
9392
throw new ArgumentException($"{Name} expect date kind {Kind} but it is {dateValue.Kind}", nameof(value));
94-
95-
var parameter = st.Parameters[index];
96-
97-
//Allow the driver to adjust the parameter for the value
98-
var adjustedValue = AdjustDateTime(dateValue);
99-
session.Factory.ConnectionProvider.Driver.AdjustParameterForValue(parameter, SqlType, adjustedValue);
100-
parameter.Value = adjustedValue;
93+
st.Parameters[index].Value = AdjustDateTime(dateValue);
10194
}
10295

10396
#region IVersionType Members

0 commit comments

Comments
 (0)