Skip to content

Commit 4f24c63

Browse files
feat: Added support for conversion from IN (?, ?, ?) to IN $list
1 parent 1c0e9f0 commit 4f24c63

File tree

6 files changed

+440
-114
lines changed

6 files changed

+440
-114
lines changed

src/Ydb.Sdk/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
- Fixed bug: SQL parser skips token after param.
2+
- ADO.NET: Added support for conversion from IN (?, ?, ?) to IN $list ([#447](https://github.com/ydb-platform/ydb-dotnet-sdk/issues/447)).
3+
14
## v0.19.0
25

36
- ADO.NET: session is now deactivated when cancelled.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Ydb.Sdk.Value;
2+
3+
namespace Ydb.Sdk.Ado.Internal;
4+
5+
internal interface ISqlParam
6+
{
7+
string Name { get; }
8+
9+
YdbValue YdbValueFetch(Dictionary<string, YdbValue> ydbParameters);
10+
}
11+
12+
internal record PrimitiveParam(string Name) : ISqlParam
13+
{
14+
public YdbValue YdbValueFetch(Dictionary<string, YdbValue> ydbParameters) =>
15+
ydbParameters.Get(Name);
16+
}
17+
18+
internal class ListPrimitiveParam : ISqlParam
19+
{
20+
private const string PrefixParamName = "$Gen_List_Primitive";
21+
22+
private readonly IReadOnlyList<string> _paramNames;
23+
24+
public ListPrimitiveParam(IReadOnlyList<string> paramNames, int globalNumber)
25+
{
26+
_paramNames = paramNames;
27+
Name = $"{PrefixParamName}_{globalNumber}";
28+
}
29+
30+
public string Name { get; }
31+
32+
public YdbValue YdbValueFetch(Dictionary<string, YdbValue> ydbParameters) => YdbValue
33+
.MakeList(_paramNames.Select(ydbParameters.Get).ToArray());
34+
}
35+
36+
internal static class YdbParametersExtension
37+
{
38+
internal static YdbValue Get(this Dictionary<string, YdbValue> ydbParameters, string name)
39+
=> ydbParameters.TryGetValue(name, out var ydbValue)
40+
? ydbValue
41+
: throw new YdbException($"Not found YDB parameter [name: {name}]");
42+
}

0 commit comments

Comments
 (0)