Skip to content

Commit

Permalink
Start loading composite types before ranges (#5651)
Browse files Browse the repository at this point in the history
Fixes #5650
  • Loading branch information
vonzshik authored and NinoFloris committed Apr 21, 2024
1 parent 4e5fb5a commit 58b9a1b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Npgsql/PostgresDatabaseInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ static string GenerateLoadTypesQuery(bool withRange, bool withMultirange, bool l
))
ORDER BY CASE
WHEN typtype IN ('b', 'e', 'p') THEN 0 -- First base types, enums, pseudo-types
WHEN typtype = 'r' THEN 1 -- Ranges after
WHEN typtype = 'm' THEN 2 -- Multiranges after
WHEN typtype = 'c' THEN 3 -- Composites after
WHEN typtype = 'c' THEN 1 -- Composites after (fields loaded later in 2nd pass)
WHEN typtype = 'r' THEN 2 -- Ranges after
WHEN typtype = 'm' THEN 3 -- Multiranges after
WHEN typtype = 'd' AND elemtyptype <> 'a' THEN 4 -- Domains over non-arrays after
WHEN typtype = 'a' THEN 5 -- Arrays after
WHEN typtype = 'd' AND elemtyptype = 'a' THEN 6 -- Domains over arrays last
Expand Down
36 changes: 36 additions & 0 deletions test/Npgsql.Tests/Types/CompositeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,42 @@ public async Task PartialConstructorWorks()
npgsqlDbType: null);
}

[Test]
public async Task CompositeOverRange()
{
await using var adminConnection = await OpenConnectionAsync();
var type = await GetTempTypeName(adminConnection);
var rangeType = await GetTempTypeName(adminConnection);

await adminConnection.ExecuteNonQueryAsync($"CREATE TYPE {type} AS (x int, some_text text); CREATE TYPE {rangeType} AS RANGE(subtype={type})");

var dataSourceBuilder = CreateDataSourceBuilder();
dataSourceBuilder.MapComposite<SomeComposite>(type);
dataSourceBuilder.EnableUnmappedTypes();
await using var dataSource = dataSourceBuilder.Build();
await using var connection = await dataSource.OpenConnectionAsync();

var composite1 = new SomeComposite
{
SomeText = "foo",
X = 8
};

var composite2 = new SomeComposite
{
SomeText = "bar",
X = 42
};

await AssertType(
connection,
new NpgsqlRange<SomeComposite>(composite1, composite2),
"[\"(8,foo)\",\"(42,bar)\"]",
rangeType,
npgsqlDbType: null,
isDefaultForWriting: false);
}

#region Test Types

readonly struct DuplicateOneLongOneBool
Expand Down

0 comments on commit 58b9a1b

Please sign in to comment.