Skip to content

Commit be8a321

Browse files
get yet changes
1 parent e21da1c commit be8a321

File tree

4 files changed

+347
-72
lines changed

4 files changed

+347
-72
lines changed

src/Ydb.Sdk/src/Ado/YdbDataReader.cs

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,28 @@ public override byte GetByte(int ordinal) =>
122122
/// Gets the value of the specified column as a signed byte.
123123
/// </summary>
124124
/// <param name="ordinal">The zero-based column ordinal.</param>
125-
/// <returns>The value of the specified column.</returns>
125+
/// <returns>The value of the specified column as a signed byte.</returns>
126126
public sbyte GetSByte(int ordinal) => GetPrimitiveValue(Type.Types.PrimitiveTypeId.Int8, ordinal).GetInt8();
127127

128128
/// <summary>
129129
/// Gets the value of the specified column as a byte array.
130130
/// </summary>
131131
/// <param name="ordinal">The zero-based column ordinal.</param>
132-
/// <returns>The value of the specified column.</returns>
132+
/// <returns>The value of the specified column as a byte array.</returns>
133133
public byte[] GetBytes(int ordinal) => GetPrimitiveValue(Type.Types.PrimitiveTypeId.String, ordinal).GetBytes();
134134

135+
public byte[] GetYson(int ordinal) => GetPrimitiveValue(Type.Types.PrimitiveTypeId.Yson, ordinal).GetYson();
136+
135137
/// <summary>
136-
/// Gets the value of the specified column as a YSON byte array.
138+
/// Reads a stream of bytes from the specified column offset into the buffer as an array.
137139
/// </summary>
138140
/// <param name="ordinal">The zero-based column ordinal.</param>
139-
/// <returns>The value of the specified column as YSON bytes.</returns>
140-
public byte[] GetYson(int ordinal) => GetPrimitiveValue(Type.Types.PrimitiveTypeId.Yson, ordinal).GetYson();
141-
141+
/// <param name="dataOffset">The index within the field from which to start the read operation.</param>
142+
/// <param name="buffer">The buffer into which to read the stream of bytes.</param>
143+
/// <param name="bufferOffset">The index for buffer to start the read operation.</param>
144+
/// <param name="length">The maximum length to copy into the buffer.</param>
145+
/// <returns>The actual number of bytes read.</returns>
146+
/// <exception cref="IndexOutOfRangeException">Thrown when dataOffset, bufferOffset, or length are out of range.</exception>
142147
public override long GetBytes(int ordinal, long dataOffset, byte[]? buffer, int bufferOffset, int length)
143148
{
144149
var bytes = GetBytes(ordinal);
@@ -162,13 +167,31 @@ public override long GetBytes(int ordinal, long dataOffset, byte[]? buffer, int
162167
return copyCount;
163168
}
164169

170+
/// <summary>
171+
/// Gets the value of the specified column as a single character.
172+
/// </summary>
173+
/// <param name="ordinal">The zero-based column ordinal.</param>
174+
/// <returns>The value of the specified column as a character.</returns>
175+
/// <exception cref="System.InvalidCastException">
176+
/// Thrown when the string is empty or cannot be converted to a character.
177+
/// </exception>
165178
public override char GetChar(int ordinal)
166179
{
167180
var str = GetString(ordinal);
168181

169182
return str.Length == 0 ? throw new InvalidCastException("Could not read char - string was empty") : str[0];
170183
}
171184

185+
/// <summary>
186+
/// Reads a stream of characters from the specified column offset into the buffer as an array.
187+
/// </summary>
188+
/// <param name="ordinal">The zero-based column ordinal.</param>
189+
/// <param name="dataOffset">The index within the field from which to start the read operation.</param>
190+
/// <param name="buffer">The buffer into which to read the stream of characters.</param>
191+
/// <param name="bufferOffset">The index for buffer to start the read operation.</param>
192+
/// <param name="length">The maximum length to copy into the buffer.</param>
193+
/// <returns>The actual number of characters read.</returns>
194+
/// <exception cref="IndexOutOfRangeException">Thrown when dataOffset, bufferOffset, or length are out of range.</exception>
172195
public override long GetChars(int ordinal, long dataOffset, char[]? buffer, int bufferOffset, int length)
173196
{
174197
var chars = GetString(ordinal).ToCharArray();
@@ -441,6 +464,11 @@ public override int GetInt32(int ordinal)
441464
/// </summary>
442465
/// <param name="ordinal">The zero-based column ordinal.</param>
443466
/// <returns>The value of the specified column.</returns>
467+
/// <summary>
468+
/// Gets the value of the specified column as a 32-bit unsigned integer.
469+
/// </summary>
470+
/// <param name="ordinal">The zero-based column ordinal.</param>
471+
/// <returns>The value of the specified column as a 32-bit unsigned integer.</returns>
444472
public uint GetUint32(int ordinal)
445473
{
446474
var type = UnwrapColumnType(ordinal);
@@ -633,32 +661,32 @@ public override int GetValues(object[] values)
633661
/// Gets the number of columns in the current row.
634662
/// </summary>
635663
public override int FieldCount => ReaderMetadata.FieldCount;
636-
664+
637665
/// <summary>
638666
/// Gets the value of the specified column in its native format given the column ordinal.
639667
/// </summary>
640668
/// <param name="ordinal">The zero-based column ordinal.</param>
641669
/// <returns>The value of the specified column in its native format.</returns>
642670
public override object this[int ordinal] => GetValue(ordinal);
643-
671+
644672
/// <summary>
645673
/// Gets the value of the specified column in its native format given the column name.
646674
/// </summary>
647675
/// <param name="name">The name of the column.</param>
648676
/// <returns>The value of the specified column in its native format.</returns>
649677
public override object this[string name] => GetValue(GetOrdinal(name));
650-
678+
651679
/// <summary>
652680
/// Gets the number of rows changed, inserted, or deleted by execution of the SQL statement.
653681
/// </summary>
654682
/// <remarks>For YDB, this always returns -1 as the number of affected records is not available.</remarks>
655683
public override int RecordsAffected => -1;
656-
684+
657685
/// <summary>
658686
/// Gets a value that indicates whether the data reader contains one or more rows.
659687
/// </summary>
660688
public override bool HasRows => ReaderMetadata.RowsCount > 0;
661-
689+
662690
/// <summary>
663691
/// Gets a value that indicates whether the data reader is closed.
664692
/// </summary>
@@ -743,8 +771,22 @@ private void ThrowIfClosed()
743771
}
744772
}
745773

774+
/// <summary>
775+
/// Gets a value indicating the depth of nesting for the current row.
776+
/// </summary>
777+
/// <remarks>
778+
/// For YdbDataReader, this always returns 0 as YDB does not support nested result sets.
779+
/// </remarks>
746780
public override int Depth => 0;
747781

782+
/// <summary>
783+
/// Returns an enumerator that iterates through the <see cref="YdbDataReader"/>.
784+
/// </summary>
785+
/// <returns>An enumerator that can be used to iterate through the <see cref="YdbDataRecord"/> collection.</returns>
786+
/// <remarks>
787+
/// This method provides synchronous enumeration over the data reader records.
788+
/// Each iteration advances the reader to the next row.
789+
/// </remarks>
748790
public override IEnumerator<YdbDataRecord> GetEnumerator()
749791
{
750792
while (Read())
@@ -753,6 +795,14 @@ public override IEnumerator<YdbDataRecord> GetEnumerator()
753795
}
754796
}
755797

798+
/// <summary>
799+
/// Asynchronously closes the <see cref="YdbDataReader"/> object.
800+
/// </summary>
801+
/// <returns>A task representing the asynchronous operation.</returns>
802+
/// <remarks>
803+
/// This method closes the reader and releases any resources associated with it.
804+
/// If the reader is closed during a transaction, the transaction will be marked as failed.
805+
/// </remarks>
756806
public override async Task CloseAsync()
757807
{
758808
if (ReaderState == State.Close)
@@ -780,6 +830,13 @@ public override async Task CloseAsync()
780830
}
781831
}
782832

833+
/// <summary>
834+
/// Closes the <see cref="YdbDataReader"/> object.
835+
/// </summary>
836+
/// <remarks>
837+
/// This method closes the reader and releases any resources associated with it.
838+
/// If the reader is closed during a transaction, the transaction will be marked as failed.
839+
/// </remarks>
783840
public override void Close() => CloseAsync().GetAwaiter().GetResult();
784841

785842
private Type UnwrapColumnType(int ordinal)
@@ -864,8 +921,24 @@ private void OnFailReadStream()
864921
}
865922
}
866923

924+
/// <summary>
925+
/// Asynchronously releases the unmanaged resources used by the YdbDataReader.
926+
/// </summary>
927+
/// <returns>A ValueTask representing the asynchronous disposal operation.</returns>
928+
/// <remarks>
929+
/// This method closes the reader and releases any resources associated with it.
930+
/// </remarks>
867931
public override async ValueTask DisposeAsync() => await CloseAsync();
868932

933+
/// <summary>
934+
/// Returns an async enumerator that iterates through the YdbDataReader asynchronously.
935+
/// </summary>
936+
/// <param name="cancellationToken">A token to cancel the enumeration.</param>
937+
/// <returns>An async enumerator that can be used to iterate through the YdbDataRecord collection.</returns>
938+
/// <remarks>
939+
/// This method provides asynchronous enumeration over the data reader records.
940+
/// Each iteration advances the reader to the next row asynchronously.
941+
/// </remarks>
869942
public async IAsyncEnumerator<YdbDataRecord> GetAsyncEnumerator(CancellationToken cancellationToken = new())
870943
{
871944
while (await ReadAsync(cancellationToken))

0 commit comments

Comments
 (0)