Skip to content

Commit 8b99214

Browse files
authored
Fix schema validator for Npgsql 5 (#2992)
Fixes #2876
1 parent 095d5b3 commit 8b99214

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
6565
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
6666
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="6.6.0" />
67-
<PackageReference Include="Npgsql" Version="4.0.3" />
67+
<PackageReference Include="Npgsql" Version="5.0.11" />
6868
</ItemGroup>
6969
<ItemGroup Condition="$(NhNetFx)">
7070
<Reference Include="System.Configuration" />

src/NHibernate/Dialect/Schema/PostgreSQLMetadata.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,43 @@ public PostgreSQLColumnMetadata(DataRow rs)
138138
this.SetNumericalPrecision(rs["NUMERIC_PRECISION"]);
139139

140140
Nullable = Convert.ToString(rs["IS_NULLABLE"]);
141-
TypeName = Convert.ToString(rs["DATA_TYPE"]);
141+
TypeName = NormalizeTypeNames(Convert.ToString(rs["DATA_TYPE"]));
142+
}
143+
144+
private static string NormalizeTypeNames(string typeName)
145+
{
146+
switch (typeName)
147+
{
148+
case "double precision":
149+
return "float8";
150+
case "real":
151+
return "float4";
152+
case "smallint":
153+
return "int2";
154+
case "integer":
155+
return "int4";
156+
case "bigint":
157+
return "int8";
158+
}
159+
160+
if (typeName.StartsWith("character", StringComparison.Ordinal))
161+
{
162+
return typeName.Replace("character varying", "varchar").Replace("character", "char");
163+
}
164+
165+
if (typeName.EndsWith(" with time zone", StringComparison.Ordinal))
166+
{
167+
return typeName.StartsWith("timestamp", StringComparison.Ordinal)
168+
? typeName.Replace(" with time zone", string.Empty).Replace("timestamp", "timestamptz")
169+
: typeName.Replace(" with time zone", string.Empty).Replace("time", "timetz");
170+
}
171+
172+
if (typeName.EndsWith(" without time zone", StringComparison.Ordinal))
173+
{
174+
return typeName.Replace(" without time zone", string.Empty);
175+
}
176+
177+
return typeName;
142178
}
143179
}
144180

0 commit comments

Comments
 (0)