Skip to content

Commit 020d5e0

Browse files
feat: Added support for conversion from IN (?, ?, ?) to IN $list (#460)
1 parent 1c0e9f0 commit 020d5e0

File tree

6 files changed

+495
-109
lines changed

6 files changed

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

0 commit comments

Comments
 (0)