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
6 changes: 5 additions & 1 deletion DuckDB.NET.Data/DuckDBCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ public async IAsyncEnumerable<RecordBatch> ExecuteArrowBatchesAsync([EnumeratorC
}
}

public override void Prepare() { }
/// <summary>
/// Statements are prepared when the command executes, so this only checks what IDbCommand.Prepare documents:
/// InvalidOperationException when "The Connection is not set. -or- The Connection is not Open()."
/// </summary>
public override void Prepare() => EnsureConnectionOpen();

protected override DbParameter CreateDbParameter() => new DuckDBParameter();

Expand Down
13 changes: 13 additions & 0 deletions DuckDB.NET.Test/DuckDBCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,17 @@ public void CommandTypeDefaultsToText()
{
new DuckDBCommand().CommandType.Should().Be(CommandType.Text);
}

// https://learn.microsoft.com/dotnet/api/system.data.idbcommand.prepare, Exceptions: InvalidOperationException,
// "The Connection is not set. -or- The Connection is not Open()."
[Fact]
public void PrepareThrowsWithoutAnOpenConnection()
{
new DuckDBCommand("SELECT 1").Invoking(c => c.Prepare()).Should().Throw<InvalidOperationException>();

using var closed = new DuckDBConnection(DuckDBConnectionStringBuilder.InMemoryConnectionString);
new DuckDBCommand("SELECT 1", closed).Invoking(c => c.Prepare()).Should().Throw<InvalidOperationException>();

new DuckDBCommand("SELECT 1", Connection).Invoking(c => c.Prepare()).Should().NotThrow();
}
}
Loading