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

Giorgi / DuckDB.NET / 15378265673

01 Jun 2025 06:44PM UTC coverage: 89.952%. Remained the same
15378265673

push

github

Giorgi
Merge branch 'develop' of https://github.com/Giorgi/DuckDB.NET into develop

1088 of 1243 branches covered (87.53%)

Branch coverage included in aggregate %.

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

2 existing lines in 1 file now uncovered.

2090 of 2290 relevant lines covered (91.27%)

638511.8 hits per line

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

86.67
/DuckDB.NET.Bindings/DuckDBWrapperObjects.cs
1
using Microsoft.Win32.SafeHandles;
2
using System;
3
using System.Globalization;
4
using System.Runtime.CompilerServices;
5

6
namespace DuckDB.NET.Native;
7

8
public class DuckDBDatabase() : SafeHandleZeroOrMinusOneIsInvalid(true)
50,190✔
9
{
10
    protected override bool ReleaseHandle()
11
    {
12
        NativeMethods.Startup.DuckDBClose(ref handle);
50,186✔
13
        return true;
50,186✔
14
    }
15
}
16

17
public class DuckDBNativeConnection() : SafeHandleZeroOrMinusOneIsInvalid(true)
64,935✔
18
{
19
    protected override bool ReleaseHandle()
20
    {
21
        NativeMethods.Startup.DuckDBDisconnect(ref handle);
64,931✔
22
        return true;
64,931✔
23
    }
24

25
    public void Interrupt()
26
    {
27
        NativeMethods.Startup.DuckDBInterrupt(this);
12✔
28
    }
12✔
29
}
30

31
public class DuckDBPreparedStatement() : SafeHandleZeroOrMinusOneIsInvalid(true)
157,626✔
32
{
33
    protected override bool ReleaseHandle()
34
    {
35
        NativeMethods.PreparedStatements.DuckDBDestroyPrepare(ref handle);
157,623✔
36
        return true;
157,623✔
37
    }
38
}
39

40
public class DuckDBConfig() : SafeHandleZeroOrMinusOneIsInvalid(true)
50,187✔
41
{
42
    protected override bool ReleaseHandle()
43
    {
44
        NativeMethods.Configuration.DuckDBDestroyConfig(ref handle);
50,187✔
45
        return true;
50,187✔
46
    }
47
}
48

49
public class DuckDBAppender() : SafeHandleZeroOrMinusOneIsInvalid(true)
186✔
50
{
51
    protected override bool ReleaseHandle()
52
    {
53
        return NativeMethods.Appender.DuckDBDestroyAppender(ref handle).IsSuccess();
186✔
54
    }
55
}
56

57
public class DuckDBExtractedStatements() : SafeHandleZeroOrMinusOneIsInvalid(true)
157,518✔
58
{
59
    protected override bool ReleaseHandle()
60
    {
61
        NativeMethods.ExtractStatements.DuckDBDestroyExtracted(ref handle);
157,515✔
62

63
        return true;
157,515✔
64
    }
65
}
66

67
public class DuckDBLogicalType() : SafeHandleZeroOrMinusOneIsInvalid(true)
61,141✔
68
{
69
    protected override bool ReleaseHandle()
70
    {
71
        NativeMethods.LogicalType.DuckDBDestroyLogicalType(ref handle);
60,970✔
72
        return true;
60,970✔
73
    }
74
}
75

76
public class DuckDBDataChunk : SafeHandleZeroOrMinusOneIsInvalid
77
{
78
    public DuckDBDataChunk() : base(true)
40,032✔
79
    {
80
    }
40,032✔
81

82
    public DuckDBDataChunk(IntPtr chunk) : base(false)
135✔
83
    {
84
        SetHandle(chunk);
135✔
85
    }
135✔
86

87
    protected override bool ReleaseHandle()
88
    {
89
        NativeMethods.DataChunks.DuckDBDestroyDataChunk(ref handle);
39,570✔
90
        return true;
39,570✔
91
    }
92
}
93

94
public class DuckDBValue() : SafeHandleZeroOrMinusOneIsInvalid(true), IDuckDBValueReader
10,565✔
95
{
96
    private DuckDBValue[] childValues = [];
10,565✔
97

98
    protected override bool ReleaseHandle()
99
    {
100
        foreach (var value in childValues)
40,322✔
101
        {
102
            value.Dispose();
9,596✔
103
        }
104
        
105
        NativeMethods.Value.DuckDBDestroyValue(ref handle);
10,565✔
106
        return true;
10,565✔
107
    }
108

109
    internal void SetChildValues(DuckDBValue[] values)
110
    {
111
        childValues = values;
396✔
112
    }
396✔
113

114
    public bool IsNull() => NativeMethods.Value.DuckDBIsNullValue(this);
3✔
115

116
    public T GetValue<T>()
117
    {
118
        var logicalType = NativeMethods.Value.DuckDBGetValueType(this);
60✔
119

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

125
        var duckDBType = NativeMethods.LogicalType.DuckDBGetTypeId(logicalType);
60✔
126

127
        return duckDBType switch
60!
128
        {
60✔
129
            DuckDBType.Boolean => Cast(NativeMethods.Value.DuckDBGetBool(this)),
3✔
130

60✔
131
            DuckDBType.TinyInt => Cast(NativeMethods.Value.DuckDBGetInt8(this)),
3✔
132
            DuckDBType.SmallInt => Cast(NativeMethods.Value.DuckDBGetInt16(this)),
3✔
133
            DuckDBType.Integer => Cast(NativeMethods.Value.DuckDBGetInt32(this)),
3✔
134
            DuckDBType.BigInt => Cast(NativeMethods.Value.DuckDBGetInt64(this)),
3✔
135

60✔
136
            DuckDBType.UnsignedTinyInt => Cast(NativeMethods.Value.DuckDBGetUInt8(this)),
3✔
137
            DuckDBType.UnsignedSmallInt => Cast(NativeMethods.Value.DuckDBGetUInt16(this)),
3✔
138
            DuckDBType.UnsignedInteger => Cast(NativeMethods.Value.DuckDBGetUInt32(this)),
3✔
139
            DuckDBType.UnsignedBigInt => Cast(NativeMethods.Value.DuckDBGetUInt64(this)),
3✔
140

60✔
141
            DuckDBType.Float => Cast(NativeMethods.Value.DuckDBGetFloat(this)),
3✔
142
            DuckDBType.Double => Cast(NativeMethods.Value.DuckDBGetDouble(this)),
3✔
143
            
60✔
144
            DuckDBType.Decimal => Cast(decimal.Parse(NativeMethods.Value.DuckDBGetVarchar(this), NumberStyles.Any, CultureInfo.InvariantCulture)),
6✔
145
            
60✔
146
            DuckDBType.Uuid => Cast(new Guid(NativeMethods.Value.DuckDBGetVarchar(this))),
3✔
147
            
60✔
148
            DuckDBType.HugeInt => Cast(NativeMethods.Value.DuckDBGetHugeInt(this).ToBigInteger()),
3✔
UNCOV
149
            DuckDBType.UnsignedHugeInt => Cast(NativeMethods.Value.DuckDBGetUHugeInt(this).ToBigInteger()),
×
150
            
60✔
151
            DuckDBType.Varchar => Cast(NativeMethods.Value.DuckDBGetVarchar(this)),
3✔
152

60✔
153
#if NET6_0_OR_GREATER
60✔
154
            DuckDBType.Date => Cast((DateOnly)NativeMethods.DateTimeHelpers.DuckDBFromDate(NativeMethods.Value.DuckDBGetDate(this))),
3✔
155
            DuckDBType.Time => Cast((TimeOnly)NativeMethods.DateTimeHelpers.DuckDBFromTime(NativeMethods.Value.DuckDBGetTime(this))),
3✔
156
#else
60✔
157
            DuckDBType.Date => Cast(NativeMethods.DateTimeHelpers.DuckDBFromDate(NativeMethods.Value.DuckDBGetDate(this)).ToDateTime()),
60✔
158
            DuckDBType.Time => Cast(NativeMethods.DateTimeHelpers.DuckDBFromTime(NativeMethods.Value.DuckDBGetTime(this)).ToDateTime()),
60✔
159
#endif
60✔
160
            //DuckDBType.TimeTz => expr,
60✔
161
            DuckDBType.Interval => Cast((TimeSpan)NativeMethods.Value.DuckDBGetInterval(this)),
3✔
162
            DuckDBType.Timestamp => Cast(NativeMethods.DateTimeHelpers.DuckDBFromTimestamp(NativeMethods.Value.DuckDBGetTimestamp(this)).ToDateTime()),
3✔
163
            //DuckDBType.TimestampS => expr,
60✔
164
            //DuckDBType.TimestampMs => expr,
60✔
165
            //DuckDBType.TimestampNs => expr,
60✔
166
            //DuckDBType.TimestampTz => expr,
60✔
UNCOV
167
            _ => throw new NotImplementedException($"Cannot read value of type {typeof(T).FullName}")
×
168
        };
60✔
169

170
        T Cast<TSource>(TSource value) => Unsafe.As<TSource, T>(ref value);
60✔
171
    }
172
}
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