Skip to content

Commit 92f7125

Browse files
committed
Add ValueTuple sql parameter tests
1 parent cc0c936 commit 92f7125

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

ClickHouse.Driver.Tests/SQL/SqlParameterizedSelectTests.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ SELECT 1
115115
FROM (SELECT tuple(1, 'a', NULL) AS res)
116116
WHERE res.1 = tupleElement({var:Tuple(Int32, String, Nullable(Int32))}, 1)
117117
AND res.2 = tupleElement({var:Tuple(Int32, String, Nullable(Int32))}, 2)
118-
AND res.3 is NULL
118+
AND res.3 is NULL
119119
AND tupleElement({var:Tuple(Int32, String, Nullable(Int32))}, 3) is NULL";
120120
using var command = connection.CreateCommand();
121121
command.CommandText = sql;
@@ -145,5 +145,43 @@ SELECT 1
145145
result.GetEnsureSingleRow();
146146
}
147147

148+
[Test]
149+
public async Task ShouldExecuteSelectWithValueTupleParameter()
150+
{
151+
var sql = @"
152+
SELECT 1
153+
FROM (SELECT tuple(1, 'a', NULL) AS res)
154+
WHERE res.1 = tupleElement({var:Tuple(Int32, String, Nullable(Int32))}, 1)
155+
AND res.2 = tupleElement({var:Tuple(Int32, String, Nullable(Int32))}, 2)
156+
AND res.3 is NULL
157+
AND tupleElement({var:Tuple(Int32, String, Nullable(Int32))}, 3) is NULL";
158+
using var command = connection.CreateCommand();
159+
command.CommandText = sql;
160+
161+
command.AddParameter("var", ValueTuple.Create<int, string, int?>(1, "a", null));
162+
163+
var result = await command.ExecuteReaderAsync();
164+
result.GetEnsureSingleRow();
165+
}
166+
167+
[Test]
168+
public async Task ShouldExecuteSelectWithUnderlyingValueTupleParameter()
169+
{
170+
var sql = @"
171+
SELECT 1
172+
FROM (SELECT tuple(123, tuple(5, 'a', 7)) AS res)
173+
WHERE res.1 = tupleElement({var:Tuple(Int32, Tuple(UInt8, String, Nullable(Int32)))}, 1)
174+
AND res.2.1 = tupleElement(tupleElement({var:Tuple(Int32, Tuple(UInt8, String, Nullable(Int32)))}, 2), 1)
175+
AND res.2.2 = tupleElement(tupleElement({var:Tuple(Int32, Tuple(UInt8, String, Nullable(Int32)))}, 2), 2)
176+
AND res.2.3 = tupleElement(tupleElement({var:Tuple(Int32, Tuple(UInt8, String, Nullable(Int32)))}, 2), 3)";
177+
using var command = connection.CreateCommand();
178+
command.CommandText = sql;
179+
180+
command.AddParameter("var", ValueTuple.Create(123, ValueTuple.Create((byte)5, "a", 7)));
181+
182+
var result = await command.ExecuteReaderAsync();
183+
result.GetEnsureSingleRow();
184+
}
185+
148186
public void Dispose() => connection?.Dispose();
149187
}

ClickHouse.Driver.Tests/Types/TypeMappingTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public class TypeMappingTests
8383
[TestCase(typeof(DateOnly), ExpectedResult = "Date")]
8484
#endif
8585
[TestCase(typeof(Tuple<int, byte, float?, string[]>), ExpectedResult = "Tuple(Int32,UInt8,Nullable(Float32),Array(String))")]
86+
[TestCase(typeof(ValueTuple<int, byte, float?, string[]>), ExpectedResult = "Tuple(Int32,UInt8,Nullable(Float32),Array(String))")]
8687
public string ShouldConvertToClickHouseType(Type type) => TypeConverter.ToClickHouseType(type).ToString();
8788

8889
[Test, Explicit]

0 commit comments

Comments
 (0)