Skip to content

Commit 79e1cd1

Browse files
authored
Fix support for Npgsql6 provider (#3064)
1 parent 457d767 commit 79e1cd1

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/NHibernate/Driver/NpgsqlDriver.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,33 @@ public override IResultSetsCommand GetResultSetsCommand(Engine.ISessionImplement
6565

6666
protected override void InitializeParameter(DbParameter dbParam, string name, SqlTypes.SqlType sqlType)
6767
{
68-
base.InitializeParameter(dbParam, name, sqlType);
68+
if (sqlType == null)
69+
throw new QueryException($"No type assigned to parameter '{name}'");
6970

70-
// Since the .NET currency type has 4 decimal places, we use a decimal type in PostgreSQL instead of its native 2 decimal currency type.
71+
dbParam.ParameterName = FormatNameForParameter(name);
7172
if (sqlType.DbType == DbType.Currency)
73+
{
74+
// Since the .NET currency type has 4 decimal places, we use a decimal type in PostgreSQL instead of its native 2 decimal currency type.
7275
dbParam.DbType = DbType.Decimal;
76+
}
77+
else if (DriverVersionMajor < 6 || sqlType.DbType != DbType.DateTime)
78+
{
79+
dbParam.DbType = sqlType.DbType;
80+
}
81+
else
82+
{
83+
// Let Npgsql 6 driver to decide parameter type
84+
}
7385
}
7486

7587
// Prior to v3, Npgsql was expecting DateTime for time.
7688
// https://github.com/npgsql/npgsql/issues/347
77-
public override bool RequiresTimeSpanForTime => (DriverVersion?.Major ?? 3) >= 3;
89+
public override bool RequiresTimeSpanForTime => DriverVersionMajor >= 3;
7890

7991
public override bool HasDelayedDistributedTransactionCompletion => true;
8092

8193
System.Type IEmbeddedBatcherFactoryProvider.BatcherFactoryClass => typeof(GenericBatchingBatcherFactory);
94+
95+
private int DriverVersionMajor => DriverVersion?.Major ?? 3;
8296
}
8397
}

0 commit comments

Comments
 (0)