Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 33 additions & 38 deletions src/Npgsql/Internal/Converters/ArrayConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,45 +619,40 @@ protected override PgConverter<T> CreateConverter(PgConverterResolution effectiv
protected override PgConverterResolution? GetEffectiveResolution(T? values, PgTypeId? expectedEffectivePgTypeId)
{
PgConverterResolution? resolution = null;
if (values is null)
switch (values)
{
resolution = EffectiveTypeInfo.GetDefaultResolution(expectedEffectivePgTypeId);
}
else
{
switch (values)
{
case TElement[] array:
foreach (var value in array)
{
var result = EffectiveTypeInfo.GetResolution(value, resolution?.PgTypeId ?? expectedEffectivePgTypeId);
resolution ??= result;
}
break;
case List<TElement> list:
foreach (var value in list)
{
var result = EffectiveTypeInfo.GetResolution(value, resolution?.PgTypeId ?? expectedEffectivePgTypeId);
resolution ??= result;
}
break;
case IList<TElement> list:
foreach (var value in list)
{
var result = EffectiveTypeInfo.GetResolution(value, resolution?.PgTypeId ?? expectedEffectivePgTypeId);
resolution ??= result;
}
break;
case Array array:
foreach (var value in array)
{
var result = EffectiveTypeInfo.GetResolutionAsObject(value, resolution?.PgTypeId ?? expectedEffectivePgTypeId);
resolution ??= result;
}
break;
default:
throw new NotSupportedException();
}
case TElement[] array:
foreach (var value in array)
{
var result = EffectiveTypeInfo.GetResolution(value, resolution?.PgTypeId ?? expectedEffectivePgTypeId);
resolution ??= result;
}
break;
case List<TElement> list:
foreach (var value in list)
{
var result = EffectiveTypeInfo.GetResolution(value, resolution?.PgTypeId ?? expectedEffectivePgTypeId);
resolution ??= result;
}
break;
case IList<TElement> list:
foreach (var value in list)
{
var result = EffectiveTypeInfo.GetResolution(value, resolution?.PgTypeId ?? expectedEffectivePgTypeId);
resolution ??= result;
}
break;
case Array array:
foreach (var value in array)
{
var result = EffectiveTypeInfo.GetResolutionAsObject(value, resolution?.PgTypeId ?? expectedEffectivePgTypeId);
resolution ??= result;
}
break;
case null:
break;
default:
throw new NotSupportedException();
}

return resolution;
Comment thread
NinoFloris marked this conversation as resolved.
Expand Down
6 changes: 3 additions & 3 deletions src/Npgsql/Internal/Converters/NullableConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ sealed class NullableConverterResolver<T>(PgResolverTypeInfo effectiveTypeInfo)
=> new NullableConverter<T>(effectiveResolution.GetConverter<T>());

protected override PgConverterResolution? GetEffectiveResolution(T? value, PgTypeId? expectedEffectivePgTypeId)
=> value is null
? EffectiveTypeInfo.GetDefaultResolution(expectedEffectivePgTypeId)
: EffectiveTypeInfo.GetResolution(value.GetValueOrDefault(), expectedEffectivePgTypeId);
=> value is { } inner
? EffectiveTypeInfo.GetResolution(inner, expectedEffectivePgTypeId)
: null;
}
12 changes: 12 additions & 0 deletions test/Npgsql.Tests/Types/DateTimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,18 @@ await AssertType(datasource,
@"{""1998-04-12 15:26:38+02"",NULL}",
"timestamp with time zone[]");

// Make sure delayed converter resolution works when null precedes a non-null value.
// We expect the resolution of null values to not lock in the default type timestamp.
// This would cause the subsequent non-null value to fail to convert, as it requires timestamptz.
await AssertType(datasource,
new DateTime?[]
{
null,
new DateTime(1998, 4, 12, 13, 26, 38, DateTimeKind.Utc)
},
@"{NULL,""1998-04-12 15:26:38+02""}",
"timestamp with time zone[]");

await AssertType(datasource,
new DateTime?[]
{
Expand Down