When I run this test without debugging, it works fine. When I enable debugging, it gives null reference exceptions trying to read the parameters.
Am I doing something wrong?
using System.Text;
using DuckDB.NET.Data;
namespace MyApp.Data.Tests;
public class Tests
{
private DuckDBConnection _connection;
[SetUp]
public void Setup()
{
_connection = new DuckDBConnection(DuckDBConnectionStringBuilder.InMemorySharedConnectionString);
_connection.Open();
}
[TearDown]
public void TearDown()
{
_connection.Close();
}
[Test]
public void ParamsWorkByNameForSelect()
{
using var cmd = _connection.CreateCommand();
cmd.CommandText = "select column_name from information_schema.columns where table_name = $table_name";
cmd.Parameters.Add(new DuckDBParameter("table_name", "does_not_exist"));
var results = new StringBuilder();
var reader = cmd.ExecuteReader();
while (reader.Read())
{
results.Append(reader.GetString(0) + ",");
}
Assert.That(results.ToString(), Is.EqualTo(string.Empty));
}
[Test]
public void ParamsWorkByNameForInsert()
{
using (var tran = _connection.BeginTransaction())
{
using var cmd = _connection.CreateCommand();
cmd.CommandText = "CREATE TABLE test (id INTEGER, name VARCHAR)";
cmd.ExecuteNonQuery();
tran.Commit();
}
using (var tran2 = _connection.BeginTransaction())
{
using var cmd2 = _connection.CreateCommand();
cmd2.CommandText = "INSERT INTO test (id, name) VALUES ($id, $name)";
cmd2.Parameters.Add(new DuckDBParameter("id", 1));
cmd2.Parameters.Add(new DuckDBParameter("name", "fred"));
var affectedRows = cmd2.ExecuteNonQuery();
tran2.Commit();
Assert.That(affectedRows, Is.EqualTo(1));
}
}
}
When I run this test without debugging, it works fine. When I enable debugging, it gives null reference exceptions trying to read the parameters.
Am I doing something wrong?
My csproj for my test project
Editor environment: JetBrains Rider 2024.2.7 Build #RD-242.23726.100, built on October 22, 2024 macOS: 14.6.1 (23G93) (Sonoma)
Run on host without any docker or other runtimes.