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

Giorgi / DuckDB.NET / 22921736195

10 Mar 2026 07:24PM UTC coverage: 89.526% (+0.08%) from 89.45%
22921736195

push

github

Giorgi
Update global.json

1255 of 1463 branches covered (85.78%)

Branch coverage included in aggregate %.

2651 of 2900 relevant lines covered (91.41%)

447643.55 hits per line

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

91.67
/DuckDB.NET.Data/DuckDBCommand.cs
1
using System.ComponentModel;
2
using System.Diagnostics.CodeAnalysis;
3
using System.Runtime.CompilerServices;
4

5
namespace DuckDB.NET.Data;
6

7
public class DuckDBCommand : DbCommand
8
{
9
    private DuckDBConnection? connection;
10
    private readonly DuckDBParameterCollection parameters = new();
81,090✔
11

12
    protected override DbTransaction? DbTransaction { get; set; }
81,084✔
13
    protected override DbParameterCollection DbParameterCollection => parameters;
549✔
14

15
    public new virtual DuckDBParameterCollection Parameters => parameters;
1,242✔
16

17
    public override int CommandTimeout { get; set; }
×
18
    public override CommandType CommandType { get; set; }
60,600✔
19
    public override bool DesignTimeVisible { get; set; }
×
20
    public override UpdateRowSource UpdatedRowSource { get; set; }
×
21

22
    /// <summary>
23
    /// A flag to determine whether to use streaming mode or not when executing a query. Defaults to false.
24
    /// In streaming mode DuckDB will use less RAM but query execution might be slower. Applies only to queries that return a result-set.
25
    /// </summary>
26
    /// <remarks>
27
    /// Streaming mode uses `duckdb_execute_prepared_streaming` and `duckdb_stream_fetch_chunk`, non-streaming (materialized) mode uses `duckdb_execute_prepared` and `duckdb_result_get_chunk`.
28
    /// </remarks>
29
    public bool UseStreamingMode { get; set; } = false;
158,097✔
30

31
    [AllowNull]
32
    [DefaultValue("")]
33
    public override string CommandText
34
    {
35
        get;
158,085✔
36
        set
37
        {
38
            // TODO: We shouldn't be able to change the CommandText when the command is in execution (requires CommandState implementation)
39
            field = value ?? string.Empty;
138,975!
40
        }
138,975✔
41
    } = string.Empty;
81,090✔
42

43
    protected override DbConnection? DbConnection
44
    {
45
        get => connection;
355,203✔
46
        set => connection = (DuckDBConnection?)value;
81,087✔
47
    }
48

49
    public DuckDBCommand()
81,084✔
50
    { }
81,084✔
51

52
    public DuckDBCommand(string commandText)
6✔
53
    {
54
        CommandText = commandText;
6✔
55
    }
6✔
56

57
    public DuckDBCommand(string commandText, DuckDBConnection connection)
58
        : this(commandText)
3✔
59
    {
60
        Connection = connection;
3✔
61
    }
3✔
62

63
    public override void Cancel() => connection?.NativeConnection.Interrupt();
12!
64

65
    public override int ExecuteNonQuery()
66
    {
67
        EnsureConnectionOpen();
118,269✔
68

69
        var results = PreparedStatement.PreparedStatement.PrepareMultiple(connection!.NativeConnection, CommandText, parameters, UseStreamingMode);
118,269✔
70

71
        var count = 0;
118,269✔
72

73
        foreach (var result in results)
473,178✔
74
        {
75
            var current = result;
118,320✔
76
            count += (int)NativeMethods.Query.DuckDBRowsChanged(ref current);
118,320✔
77
            result.Close();
118,320✔
78
        }
79

80
        return count;
118,224✔
81
    }
82

83
    public override object? ExecuteScalar()
84
    {
85
        EnsureConnectionOpen();
19,521✔
86

87
        using var reader = ExecuteReader();
19,518✔
88
        return reader.Read() ? reader.GetValue(0) : null;
19,506✔
89
    }
19,506✔
90

91
    public new DuckDBDataReader ExecuteReader()
92
    {
93
        return (DuckDBDataReader)base.ExecuteReader();
39,474✔
94
    }
95

96
    public new DuckDBDataReader ExecuteReader(CommandBehavior behavior)
97
    {
98
        return (DuckDBDataReader)base.ExecuteReader(behavior);
9✔
99
    }
100

101
    protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
102
    {
103
        EnsureConnectionOpen();
39,807✔
104

105
        var results = PreparedStatement.PreparedStatement.PrepareMultiple(connection!.NativeConnection, CommandText, parameters, UseStreamingMode);
39,807✔
106

107
        var reader = new DuckDBDataReader(this, results, behavior);
39,807✔
108

109
        return reader;
39,759✔
110
    }
111

112
    public override void Prepare() { }
3✔
113

114
    protected override DbParameter CreateDbParameter() => new DuckDBParameter();
69✔
115

116
    internal void CloseConnection() => Connection!.Close();
6✔
117

118
    private void EnsureConnectionOpen([CallerMemberName] string operation = "")
119
    {
120
        if (Connection is null || Connection.State != ConnectionState.Open)
177,597✔
121
        {
122
            throw new InvalidOperationException($"{operation} requires an open connection");
3✔
123
        }
124
    }
177,594✔
125
}
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