Skip to content

Commit fa978cf

Browse files
authored
Improve support of Npgsql 4
- Integer types (Int32Type, Int64Type, etc) now convert argument to an expected type before setting the parameter value. - Since Npgsql 3.2.5, system transactions support has regressed. Disable some of the tests that started failing with.
1 parent 0c3c49b commit fa978cf

File tree

12 files changed

+32
-22
lines changed

12 files changed

+32
-22
lines changed

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
5757
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
5858
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="6.3.0" />
59-
<PackageReference Include="Npgsql" Version="3.2.4.1" />
59+
<PackageReference Include="Npgsql" Version="4.0.3" />
6060
</ItemGroup>
6161
<ItemGroup Condition="'$(TargetFramework)'=='net461'">
6262
<Reference Include="System.Configuration" />

src/NHibernate.Test/TestDialects/PostgreSQL83TestDialect.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
{
33
public class PostgreSQL83TestDialect : TestDialect
44
{
5-
public PostgreSQL83TestDialect(Dialect.Dialect dialect)
6-
: base(dialect)
7-
{
8-
}
5+
public PostgreSQL83TestDialect(Dialect.Dialect dialect)
6+
: base(dialect)
7+
{
8+
}
99

10-
public override bool SupportsSelectForUpdateOnOuterJoin
11-
{
12-
get { return false; }
13-
}
10+
public override bool SupportsSelectForUpdateOnOuterJoin => false;
1411

15-
public override bool SupportsNullCharactersInUtfStrings
16-
{
17-
get { return false; }
18-
}
12+
public override bool SupportsNullCharactersInUtfStrings => false;
13+
14+
/// <summary>
15+
/// Npgsql since its 3.2.5 version fails some tests requiring this feature. The trouble was not occuring with
16+
/// Npgsql 3.2.4.1.
17+
/// </summary>
18+
public override bool SupportsUsingConnectionOnSystemTransactionPrepare => false;
1919
}
2020
}

src/NHibernate/Dialect/PostgreSQLDialect.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,16 @@ public override string CurrentTimestampSelectString
329329

330330
public override string QuerySequencesString => "SELECT c.relname FROM pg_class c WHERE c.relkind = 'S'";
331331

332+
/// <summary>
333+
/// Does this dialect supports distributed transaction? <c>false</c>.
334+
/// </summary>
335+
/// <remarks>
336+
/// Npgsql since its version 3.2.5 version has race conditions: it fails handling the threading involved with
337+
/// distributed transactions. This causes a bunch of distributed tests to be flaky with Npgsql. Individually,
338+
/// they usually succeed, but run together, some of them fail. The trouble was not occuring with Npgsql 3.2.4.1.
339+
/// </remarks>
340+
public override bool SupportsDistributedTransactions => false;
341+
332342
#endregion
333343

334344
[Serializable]

src/NHibernate/Type/DecimalType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public override System.Type ReturnedClass
3939

4040
public override void Set(DbCommand st, object value, int index, ISessionImplementor session)
4141
{
42-
st.Parameters[index].Value = value;
42+
st.Parameters[index].Value = Convert.ToDecimal(value);
4343
}
4444

4545
public override string Name

src/NHibernate/Type/DoubleType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public override System.Type ReturnedClass
3838

3939
public override void Set(DbCommand st, object value, int index, ISessionImplementor session)
4040
{
41-
st.Parameters[index].Value = value;
41+
st.Parameters[index].Value = Convert.ToDouble(value);
4242
}
4343

4444
/// <summary></summary>

src/NHibernate/Type/Int16Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override System.Type ReturnedClass
5858

5959
public override void Set(DbCommand rs, object value, int index, ISessionImplementor session)
6060
{
61-
rs.Parameters[index].Value = value;
61+
rs.Parameters[index].Value = Convert.ToInt16(value);
6262
}
6363

6464
// 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml

src/NHibernate/Type/Int32Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override System.Type ReturnedClass
5858

5959
public override void Set(DbCommand rs, object value, int index, ISessionImplementor session)
6060
{
61-
rs.Parameters[index].Value = value;
61+
rs.Parameters[index].Value = Convert.ToInt32(value);
6262
}
6363

6464
// 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml

src/NHibernate/Type/Int64Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override System.Type ReturnedClass
5858

5959
public override void Set(DbCommand rs, object value, int index, ISessionImplementor session)
6060
{
61-
rs.Parameters[index].Value = value;
61+
rs.Parameters[index].Value = Convert.ToInt64(value);
6262
}
6363

6464
// 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml

src/NHibernate/Type/SByteType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override System.Type ReturnedClass
5858

5959
public override void Set(DbCommand rs, object value, int index, ISessionImplementor session)
6060
{
61-
rs.Parameters[index].Value = value;
61+
rs.Parameters[index].Value = Convert.ToSByte(value);
6262
}
6363

6464
// 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml

src/NHibernate/Type/UInt16Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override System.Type ReturnedClass
5858

5959
public override void Set(DbCommand rs, object value, int index, ISessionImplementor session)
6060
{
61-
rs.Parameters[index].Value = value;
61+
rs.Parameters[index].Value = Convert.ToUInt16(value);
6262
}
6363

6464
// 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml

src/NHibernate/Type/UInt32Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override System.Type ReturnedClass
5858

5959
public override void Set(DbCommand rs, object value, int index, ISessionImplementor session)
6060
{
61-
rs.Parameters[index].Value = value;
61+
rs.Parameters[index].Value = Convert.ToUInt32(value);
6262
}
6363

6464
// 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml

src/NHibernate/Type/UInt64Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public override System.Type ReturnedClass
5757

5858
public override void Set(DbCommand rs, object value, int index, ISessionImplementor session)
5959
{
60-
rs.Parameters[index].Value = value;
60+
rs.Parameters[index].Value = Convert.ToUInt64(value);
6161
}
6262

6363
// 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml

0 commit comments

Comments
 (0)