Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion DuckDB.NET.Data/PreparedStatement/ClrToDuckDBConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private static DuckDBValue DecimalToDuckDBValue(decimal value)

result += new BigInteger(decimal.Multiply(fractionalPart, (decimal)power));

int width = result.IsZero ? 1 : (int)Math.Floor(BigInteger.Log10(BigInteger.Abs(result))) + 1;
int width = Math.Max(scale, result.IsZero ? 1 : (int)Math.Floor(BigInteger.Log10(BigInteger.Abs(result))) + 1);

return NativeMethods.Value.DuckDBCreateDecimal(new DuckDBDecimal((byte)width, scale, new DuckDBHugeInt(result)));
}
Expand Down
20 changes: 19 additions & 1 deletion DuckDB.NET.Test/Parameters/DecimalParameterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,22 @@ public void BindParameterWithoutTable()
result.Should().BeOfType<decimal>().Subject.Should().Be(value);
}
}
}

[Fact]
public void BindParameterInComparison()
{
decimal[] values = [decimal.Zero, 0.00m, 123456789.987654321m, -123456789.987654321m, 1.230m, -1.23m,
0.000000001m, -0.000000001m, 1000000.000000001m, -1000000.000000001m, 1.123456789012345678901m];

foreach (var value in values)
{
Command.CommandText = "SELECT 0.1 > ?;";
Command.Parameters.Clear();
Command.Parameters.Add(new DuckDBParameter(value));

var result = Command.ExecuteScalar();

result.Should().BeOfType<bool>();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add an array that holds the comparison result and validate that we get the expected result? Just to be sure that the decimal is bound correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

}
}
}
Loading