Skip to content

Commit

Permalink
More tests for decimal type inference (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkWanderer authored Mar 20, 2024
1 parent 0306072 commit f609d8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions ClickHouse.Client.Tests/ORM/DapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,14 @@ public async Task ShouldExecuteSelectReturningDecimal()
}

[Test]
public async Task ShouldInsertParameterizedFloat64Array()
[TestCase(100)]
[TestCase(1000000000)]
[TestCase(123.456)]
[TestCase(0.0001)]
public async Task ShouldWriteDecimalWithTypeInference(decimal expected)
{
const decimal expected = 123.456m;

await connection.ExecuteStatementAsync("TRUNCATE TABLE IF EXISTS test.dapper_decimal");
await connection.ExecuteStatementAsync("CREATE TABLE IF NOT EXISTS test.dapper_decimal (balance Decimal128(4)) ENGINE Memory");
await connection.ExecuteStatementAsync("CREATE TABLE IF NOT EXISTS test.dapper_decimal (balance Decimal64(4)) ENGINE Memory");


var sql = @"INSERT INTO test.dapper_decimal (balance) VALUES (@balance)";
Expand Down
2 changes: 1 addition & 1 deletion ClickHouse.Client/ADO/Parameters/ClickHouseDbParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public string QueryForm
{
var parts = decimal.GetBits(d);
int scale = (parts[3] >> 16) & 0x7F;
return $"{{{ParameterName}:Decimal(22,{scale})}}";
return $"{{{ParameterName}:Decimal128({scale})}}";
}

var chType = TypeConverter.ToClickHouseType(Value?.GetType() ?? typeof(DBNull)).ToString();
Expand Down

0 comments on commit f609d8f

Please sign in to comment.