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

Giorgi / DuckDB.NET / 21786556530

07 Feb 2026 08:39PM UTC coverage: 89.155% (-0.07%) from 89.223%
21786556530

push

github

Giorgi
Added support for clearing in-progress adapter

Requires DuckDB 1.5

1199 of 1393 branches covered (86.07%)

Branch coverage included in aggregate %.

6 of 8 new or added lines in 1 file covered. (75.0%)

193 existing lines in 43 files now uncovered.

2336 of 2572 relevant lines covered (90.82%)

557295.56 hits per line

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

91.79
/DuckDB.NET.Bindings/DuckDBWrapperObjects.cs
1
using System.Runtime.CompilerServices;
2

3
namespace DuckDB.NET.Native;
4

5
public class DuckDBDatabase() : SafeHandleZeroOrMinusOneIsInvalid(true)
51,610✔
6
{
7
    protected override bool ReleaseHandle()
8
    {
9
        NativeMethods.Startup.DuckDBClose(ref handle);
51,606✔
10
        return true;
51,606✔
11
    }
12
}
13

14
public class DuckDBNativeConnection() : SafeHandleZeroOrMinusOneIsInvalid(true)
64,947✔
15
{
16
    protected override bool ReleaseHandle()
17
    {
18
        NativeMethods.Startup.DuckDBDisconnect(ref handle);
64,943✔
19
        return true;
64,943✔
20
    }
21

22
    public void Interrupt()
23
    {
24
        NativeMethods.Startup.DuckDBInterrupt(this);
12✔
25
    }
12✔
26
}
27

28
public class DuckDBPreparedStatement() : SafeHandleZeroOrMinusOneIsInvalid(true)
157,854✔
29
{
30
    protected override bool ReleaseHandle()
31
    {
32
        NativeMethods.PreparedStatements.DuckDBDestroyPrepare(ref handle);
157,850✔
33
        return true;
157,850✔
34
    }
35
}
36

37
public class DuckDBConfig() : SafeHandleZeroOrMinusOneIsInvalid(true)
51,607✔
38
{
39
    protected override bool ReleaseHandle()
40
    {
41
        NativeMethods.Configuration.DuckDBDestroyConfig(ref handle);
51,607✔
42
        return true;
51,607✔
43
    }
44
}
45

46
public class DuckDBAppender() : SafeHandleZeroOrMinusOneIsInvalid(true)
201✔
47
{
48
    protected override bool ReleaseHandle()
49
    {
50
        return NativeMethods.Appender.DuckDBDestroyAppender(ref handle).IsSuccess();
201✔
51
    }
52
}
53

54
public class DuckDBExtractedStatements() : SafeHandleZeroOrMinusOneIsInvalid(true)
157,746✔
55
{
56
    protected override bool ReleaseHandle()
57
    {
58
        NativeMethods.ExtractStatements.DuckDBDestroyExtracted(ref handle);
157,742✔
59

60
        return true;
157,742✔
61
    }
62
}
63

64
public class DuckDBLogicalType() : SafeHandleZeroOrMinusOneIsInvalid(true)
62,529✔
65
{
66
    protected override bool ReleaseHandle()
67
    {
68
        NativeMethods.LogicalType.DuckDBDestroyLogicalType(ref handle);
62,223✔
69
        return true;
62,223✔
70
    }
71
}
72

73
public class DuckDBDataChunk : SafeHandleZeroOrMinusOneIsInvalid
74
{
75
    public DuckDBDataChunk() : base(true)
40,245✔
76
    {
77
    }
40,245✔
78

79
    public DuckDBDataChunk(IntPtr chunk) : base(false)
147✔
80
    {
81
        SetHandle(chunk);
147✔
82
    }
147✔
83

84
    protected override bool ReleaseHandle()
85
    {
86
        NativeMethods.DataChunks.DuckDBDestroyDataChunk(ref handle);
39,777✔
87
        return true;
39,777✔
88
    }
89
}
90

91
public class DuckDBValue() : SafeHandleZeroOrMinusOneIsInvalid(true), IDuckDBValueReader
11,120✔
92
{
93
    private DuckDBValue[] childValues = [];
11,120✔
94

95
    protected override bool ReleaseHandle()
96
    {
97
        foreach (var value in childValues)
42,164✔
98
        {
99
            value.Dispose();
9,962✔
100
        }
101

102
        NativeMethods.Value.DuckDBDestroyValue(ref handle);
11,120✔
103
        return true;
11,120✔
104
    }
105

106
    internal void SetChildValues(DuckDBValue[] values)
107
    {
108
        childValues = values;
396✔
109
    }
396✔
110

111
    public bool IsNull() => NativeMethods.Value.DuckDBIsNullValue(this);
3✔
112

113
    public T GetValue<T>()
114
    {
115
        var logicalType = NativeMethods.Value.DuckDBGetValueType(this);
75✔
116

117
        //Logical type is part of the duckdb_value object and it shouldn't be released separately
118
        //It will get released when the duckdb_value object is destroyed below.
119
        var add = false;
75✔
120
        logicalType.DangerousAddRef(ref add);
75✔
121

122
        var duckDBType = NativeMethods.LogicalType.DuckDBGetTypeId(logicalType);
75✔
123

124
        return duckDBType switch
75!
125
        {
75✔
126
            DuckDBType.Boolean => Cast(NativeMethods.Value.DuckDBGetBool(this)),
3✔
127

75✔
128
            DuckDBType.TinyInt => Cast(NativeMethods.Value.DuckDBGetInt8(this)),
3✔
129
            DuckDBType.SmallInt => Cast(NativeMethods.Value.DuckDBGetInt16(this)),
3✔
130
            DuckDBType.Integer => Cast(NativeMethods.Value.DuckDBGetInt32(this)),
3✔
131
            DuckDBType.BigInt => Cast(NativeMethods.Value.DuckDBGetInt64(this)),
3✔
132

75✔
133
            DuckDBType.UnsignedTinyInt => Cast(NativeMethods.Value.DuckDBGetUInt8(this)),
3✔
134
            DuckDBType.UnsignedSmallInt => Cast(NativeMethods.Value.DuckDBGetUInt16(this)),
3✔
135
            DuckDBType.UnsignedInteger => Cast(NativeMethods.Value.DuckDBGetUInt32(this)),
3✔
136
            DuckDBType.UnsignedBigInt => Cast(NativeMethods.Value.DuckDBGetUInt64(this)),
3✔
137

75✔
138
            DuckDBType.Float => Cast(NativeMethods.Value.DuckDBGetFloat(this)),
3✔
139
            DuckDBType.Double => Cast(NativeMethods.Value.DuckDBGetDouble(this)),
3✔
140

75✔
141
            DuckDBType.Decimal => Cast(decimal.Parse(NativeMethods.Value.DuckDBGetVarchar(this), NumberStyles.Any, CultureInfo.InvariantCulture)),
6✔
142

75✔
143
            DuckDBType.Uuid => Cast(new Guid(NativeMethods.Value.DuckDBGetVarchar(this))),
3✔
144

75✔
145
            DuckDBType.HugeInt => Cast(NativeMethods.Value.DuckDBGetHugeInt(this).ToBigInteger()),
3✔
UNCOV
146
            DuckDBType.UnsignedHugeInt => Cast(NativeMethods.Value.DuckDBGetUHugeInt(this).ToBigInteger()),
×
147

75✔
148
            DuckDBType.Varchar => Cast(NativeMethods.Value.DuckDBGetVarchar(this)),
3✔
149

75✔
150
            DuckDBType.Date => Cast((DateOnly)DuckDBDateOnly.FromDuckDBDate(NativeMethods.Value.DuckDBGetDate(this))),
3✔
151
            DuckDBType.Time => Cast((TimeOnly)NativeMethods.DateTimeHelpers.DuckDBFromTime(NativeMethods.Value.DuckDBGetTime(this))),
3✔
152
            DuckDBType.TimeTz => Cast(GetTimeTzValue()),
3✔
153
            DuckDBType.Interval => Cast((TimeSpan)NativeMethods.Value.DuckDBGetInterval(this)),
3✔
154
            DuckDBType.Timestamp => Cast(GetTimestampValue(NativeMethods.Value.DuckDBGetTimestamp(this),DuckDBType.Timestamp)),
3✔
155
            DuckDBType.TimestampS => Cast(GetTimestampValue(NativeMethods.Value.DuckDBGetTimestampS(this), DuckDBType.TimestampS)),
3✔
156
            DuckDBType.TimestampMs => Cast(GetTimestampValue(NativeMethods.Value.DuckDBGetTimestampMs(this), DuckDBType.TimestampMs)),
3✔
157
            DuckDBType.TimestampNs => Cast(GetTimestampValue(NativeMethods.Value.DuckDBGetTimestampNs(this), DuckDBType.TimestampNs)),
3✔
158
            DuckDBType.TimestampTz => Cast(GetTimestampValue(NativeMethods.Value.DuckDBGetTimestamp(this), DuckDBType.TimestampTz)),
3✔
UNCOV
159
            _ => throw new NotImplementedException($"Cannot read value of type {typeof(T).FullName}")
×
160
        };
75✔
161

162
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
163
        static T Cast<TSource>(TSource value) => Unsafe.As<TSource, T>(ref value);
75✔
164
    }
165

166
    private DateTime GetTimestampValue(DuckDBTimestampStruct timestampStruct, DuckDBType duckDBType)
167
    {
168
        var additionalTicks = 0;
15✔
169

170
        // The type-specific getters return values in their native units:
171
        // - TimestampS: seconds
172
        // - TimestampMs: milliseconds
173
        // - TimestampNs: nanoseconds
174
        // We need to convert to microseconds for DuckDBTimestamp.FromDuckDBTimestampStruct()
175
        if (duckDBType == DuckDBType.TimestampNs)
15✔
176
        {
177
            additionalTicks = (int)(timestampStruct.Micros % 1000 / 100);
3✔
178
            timestampStruct.Micros /= 1000;
3✔
179
        }
180
        if (duckDBType == DuckDBType.TimestampMs)
15✔
181
        {
182
            timestampStruct.Micros *= 1000;
3✔
183
        }
184
        if (duckDBType == DuckDBType.TimestampS)
15✔
185
        {
186
            timestampStruct.Micros *= 1000000;
3✔
187
        }
188

189
        var timestamp = DuckDBTimestamp.FromDuckDBTimestampStruct(timestampStruct);
15✔
190
        return timestamp.ToDateTime().AddTicks(additionalTicks);
15✔
191
    }
192

193
    private DateTimeOffset GetTimeTzValue()
194
    {
195
        var timeTzStruct = NativeMethods.Value.DuckDBGetTimeTz(this);
3✔
196
        var timeTz = NativeMethods.DateTimeHelpers.DuckDBFromTimeTz(timeTzStruct);
3✔
197
        return new DateTimeOffset(timeTz.Time.ToDateTime(), TimeSpan.FromSeconds(timeTz.Offset));
3✔
198
    }
199
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc