This repository was archived by the owner on Jun 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed
ClickHouse.Client/ADO/Parameters Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -175,4 +175,20 @@ public async Task ShouldExecuteSelectReturningDecimal()
175
175
Assert . IsInstanceOf < decimal > ( result ) ;
176
176
Assert . AreEqual ( 0.0001m , result ) ;
177
177
}
178
+
179
+ [ Test ]
180
+ public async Task ShouldInsertParameterizedFloat64Array ( )
181
+ {
182
+ const decimal expected = 123.456m ;
183
+
184
+ await connection . ExecuteStatementAsync ( "TRUNCATE TABLE IF EXISTS test.dapper_decimal" ) ;
185
+ await connection . ExecuteStatementAsync ( "CREATE TABLE IF NOT EXISTS test.dapper_decimal (balance Decimal128(4)) ENGINE Memory" ) ;
186
+
187
+
188
+ var sql = @"INSERT INTO test.dapper_decimal (balance) VALUES (@balance)" ;
189
+ await connection . ExecuteAsync ( sql , new { balance = expected } ) ;
190
+
191
+ var actual = ( ClickHouseDecimal ) await connection . ExecuteScalarAsync ( "SELECT * FROM test.dapper_decimal" ) ;
192
+ Assert . AreEqual ( expected , actual . ToDecimal ( CultureInfo . InvariantCulture ) ) ;
193
+ }
178
194
}
Original file line number Diff line number Diff line change @@ -67,7 +67,6 @@ public class TypeMappingTests
67
67
68
68
[ TestCase ( typeof ( float ) , ExpectedResult = "Float32" ) ]
69
69
[ TestCase ( typeof ( double ) , ExpectedResult = "Float64" ) ]
70
- [ TestCase ( typeof ( decimal ) , ExpectedResult = "Decimal128(0)" ) ]
71
70
72
71
[ TestCase ( typeof ( string ) , ExpectedResult = "String" ) ]
73
72
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Data ;
3
3
using System . Data . Common ;
4
+ using ClickHouse . Client . Numerics ;
4
5
using ClickHouse . Client . Types ;
5
6
6
7
namespace ClickHouse . Client . ADO . Parameters ;
@@ -33,7 +34,17 @@ public string QueryForm
33
34
{
34
35
get
35
36
{
36
- var chType = ClickHouseType ?? TypeConverter . ToClickHouseType ( Value ? . GetType ( ) ?? typeof ( DBNull ) ) . ToString ( ) ;
37
+ if ( ClickHouseType != null )
38
+ return $ "{{{ParameterName}:{ ClickHouseType } }}";
39
+
40
+ if ( Value is decimal d )
41
+ {
42
+ var parts = decimal . GetBits ( d ) ;
43
+ int scale = ( parts [ 3 ] >> 16 ) & 0x7F ;
44
+ return $ "{{{ParameterName}:Decimal(22,{ scale } )}}";
45
+ }
46
+
47
+ var chType = TypeConverter . ToClickHouseType ( Value ? . GetType ( ) ?? typeof ( DBNull ) ) . ToString ( ) ;
37
48
return $ "{{{ParameterName}:{ chType } }}";
38
49
}
39
50
}
You can’t perform that action at this time.
0 commit comments