Skip to content

Commit 21f9e4d

Browse files
Fixed bug: 'System.DateOnly' is not supported by YdbParameter (#453)
1 parent f41b6b7 commit 21f9e4d

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/Ydb.Sdk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- Fixed bug: 'System.DateOnly' is not supported by YdbParameter ([#449](https://github.com/ydb-platform/ydb-dotnet-sdk/issues/449)).
12
- Fixed bug: Unhandled exception.
23
System.Net.Http.HttpIOException ([#452](https://github.com/ydb-platform/ydb-dotnet-sdk/issues/451)).
34
- dev: LogLevel `Warning` -> `Debug` on AttachStream has been cancelled.

src/Ydb.Sdk/src/Ado/YdbParameter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ string valueString when DbType is DbType.String or DbType.AnsiString or DbType.A
109109
},
110110
DateTimeOffset dateTimeOffset when DbType is DbType.DateTimeOffset or DbType.Object =>
111111
YdbValue.MakeTimestamp(dateTimeOffset.UtcDateTime),
112+
DateOnly dateOnlyValue when DbType is DbType.Date or DbType.Object =>
113+
YdbValue.MakeDate(dateOnlyValue.ToDateTime(TimeOnly.MinValue)),
112114
float floatValue => DbType switch
113115
{
114116
DbType.Single or DbType.Object => YdbValue.MakeFloat(floatValue),

src/Ydb.Sdk/tests/Ado/YdbCommandTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,4 +463,18 @@ public async Task Guid_WhenSetUuid_ReturnThisUtf8Uuid(string guid)
463463

464464
Assert.Equal(guid.ToLower(), actualGuidText); // Guid.ToString() method represents lowercase
465465
}
466+
467+
[Fact]
468+
public async Task Date_WhenSetDateOnly_ReturnDateTime()
469+
{
470+
await using var ydbConnection = await CreateOpenConnectionAsync();
471+
var ydbCommand = new YdbCommand(ydbConnection) { CommandText = "SELECT @dateOnly;" };
472+
ydbCommand.Parameters.AddWithValue("dateOnly", new DateOnly(2002, 2, 24));
473+
474+
Assert.Equal(new DateTime(2002, 2, 24), await ydbCommand.ExecuteScalarAsync());
475+
476+
ydbCommand.Parameters.Clear();
477+
ydbCommand.Parameters.AddWithValue("dateOnly", DbType.Date, new DateOnly(2102, 2, 24));
478+
Assert.Equal(new DateTime(2102, 2, 24), await ydbCommand.ExecuteScalarAsync());
479+
}
466480
}

0 commit comments

Comments
 (0)