• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Giorgi / DuckDB.NET / 37283336965

05 Oct 2026 08:23AM UTC coverage: 91.585% (+0.5%) from 91.097%
37283336965

push

github

Giorgi
Report a missing parameter name the same way through the base type

Looking up a parameter by name through DbParameterCollection threw
ArgumentOutOfRangeException ("Index was out of range") when the name did
not exist, because GetParameter(string) used the index -1. The typed
indexer, the setter and RemoveAt already threw IndexOutOfRangeException
with "Parameter '<name>' not found"; the getter now does too.

New tests use the collection as DbParameterCollection, the way generic
data code does: AddRange(Array), Insert, Contains, IndexOf, both
indexers, CopyTo, enumeration and Remove.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CzLKjBGAwccxYB6ny5bpmY

1625 of 1849 branches covered (87.89%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

2 existing lines in 2 files now uncovered.

3338 of 3570 relevant lines covered (93.5%)

421021.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.0
/DuckDB.NET.Data/Extensions/TypeExtensions.cs
1
using System.Diagnostics.CodeAnalysis;
2
using System.Runtime.CompilerServices;
3

4
namespace DuckDB.NET.Data.Extensions;
5

6
internal static class TypeExtensions
7
{
8
    private static readonly HashSet<Type> FloatingNumericTypes = [typeof(decimal), typeof(float), typeof(double)];
3 ✔
9

10
    private static readonly HashSet<Type> IntegralNumericTypes =
3 ✔
11
    [
3 ✔
12
        typeof(byte), typeof(sbyte),
3 ✔
13
        typeof(short), typeof(ushort),
3 ✔
14
        typeof(int), typeof(uint),
3 ✔
15
        typeof(long), typeof(ulong),
3 ✔
16
        typeof(BigInteger)
3 ✔
17
    ];
3 ✔
18

19
    private static readonly Dictionary<Type, DuckDBType> ClrToDuckDBTypeMap = new()
3 ✔
20
    {
3 ✔
21
        { typeof(bool), DuckDBType.Boolean },
3 ✔
22
        { typeof(sbyte), DuckDBType.TinyInt },
3 ✔
23
        { typeof(short), DuckDBType.SmallInt },
3 ✔
24
        { typeof(int), DuckDBType.Integer },
3 ✔
25
        { typeof(long), DuckDBType.BigInt },
3 ✔
26
        { typeof(byte), DuckDBType.UnsignedTinyInt },
3 ✔
27
        { typeof(ushort), DuckDBType.UnsignedSmallInt },
3 ✔
28
        { typeof(uint), DuckDBType.UnsignedInteger },
3 ✔
29
        { typeof(ulong), DuckDBType.UnsignedBigInt },
3 ✔
30
        { typeof(float), DuckDBType.Float },
3 ✔
31
        { typeof(double), DuckDBType.Double},
3 ✔
32
        { typeof(Guid), DuckDBType.Uuid},
3 ✔
33
        { typeof(DateTime), DuckDBType.Timestamp},
3 ✔
34
        { typeof(TimeSpan), DuckDBType.Interval},
3 ✔
35
        { typeof(DateOnly), DuckDBType.Date},
3 ✔
36
        { typeof(TimeOnly), DuckDBType.Time},
3 ✔
37
        { typeof(DuckDBDateOnly), DuckDBType.Date},
3 ✔
38
        { typeof(DuckDBTimeOnly), DuckDBType.Time},
3 ✔
39
        { typeof(DateTimeOffset), DuckDBType.TimestampTz},
3 ✔
40
        { typeof(BigInteger), DuckDBType.HugeInt},
3 ✔
41
        { typeof(string), DuckDBType.Varchar},
3 ✔
42
        { typeof(byte[]), DuckDBType.Blob},
3 ✔
43
        { typeof(decimal), DuckDBType.Decimal},
3 ✔
44
        { typeof(object), DuckDBType.Any},
3 ✔
45
    };
3 ✔
46

47
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
48
    public static bool IsNull([NotNullWhen(false)] this object? value) => value is null or DBNull;
11,871 ✔
49

50
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
51
    public static Type UnderlyingTypeOrSelf(this Type type) => Nullable.GetUnderlyingType(type) ?? type;
1,587 ✔
52

53
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
54
    public static bool IsFloatingNumericType<T>()
55
    {
56
        return typeof(T) == typeof(decimal) || typeof(T) == typeof(float) || typeof(T) == typeof(double);
5,760,162 ✔
57
    }
58

59
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
60
    public static bool IsIntegralNumericType<T>()
61
    {
62
        return typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte) ||
5,760,162 ✔
63
               typeof(T) == typeof(short) || typeof(T) == typeof(ushort) ||
5,760,162 ✔
64
               typeof(T) == typeof(int) || typeof(T) == typeof(uint) ||
5,760,162 ✔
65
               typeof(T) == typeof(long) || typeof(T) == typeof(ulong) ||
5,760,162 ✔
66
               typeof(T) == typeof(BigInteger);
5,760,162 ✔
67
    }
68

69
    public static bool IsNumeric(this Type type)
70
    {
71
        return IntegralNumericTypes.Contains(type) || FloatingNumericTypes.Contains(type);
18,935 ✔
72
    }
73

74
    public static bool AllowsNullValue(this Type type, out bool isNullableValueType, out Type? underlyingType)
75
    {
76
        underlyingType = Nullable.GetUnderlyingType(type);
1,205,025 ✔
77
        isNullableValueType = underlyingType != null;
1,205,025 ✔
78

79
        var isNullable = isNullableValueType || !type.IsValueType;
1,205,025 ✔
80

81
        return isNullable;
408,569 ✔
82
    }
83

84
    public static DuckDBLogicalType GetLogicalType<T>() => typeof(T).GetLogicalType();
264 ✔
85

86
    public static DuckDBLogicalType GetLogicalType(this Type type)
87
    {
88
        type = type.UnderlyingTypeOrSelf();
1,488 ✔
89

90
        if (type == typeof(decimal))
1,488 ✔
91
        {
92
            return NativeMethods.LogicalType.DuckDBCreateDecimalType(38, 18);
93 ✔
93
        }
94

95
        if (type.IsAssignableTo(typeof(IList)) && type.IsGenericType)
1,395 ✔
96
        {
97
            var genericTypeParameter = type.GetGenericArguments()[0];
42 ✔
98
            using var nestedType = genericTypeParameter.GetLogicalType();
42 ✔
99
            return NativeMethods.LogicalType.DuckDBCreateListType(nestedType);
42 ✔
100
        }
101

102
        if (ClrToDuckDBTypeMap.TryGetValue(type, out var duckDBType))
1,353 !
103
        {
104
            return NativeMethods.LogicalType.DuckDBCreateLogicalType(duckDBType);
1,353 ✔
105
        }
106

UNCOV
107
        throw new InvalidOperationException($"Cannot map type {type.FullName} to DuckDBType.");
×
108
    }
42 ✔
109

110
    public static DuckDBType GetDuckDBType(this Type type) => ClrToDuckDBTypeMap.GetValueOrDefault(type, DuckDBType.Invalid);
99 ✔
111
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc