@@ -5,28 +5,41 @@ namespace ChDb;
55/// <summary>
66/// The query result.
77/// </summary>
8- /// <param name="Buf">Result buffer.</param>
9- /// <param name="ErrorMessage">Error message if occured.</param>
10- /// <param name="RowsRead">Number of rows read</param>
11- /// <param name="BytesRead">Number of bytes read</param>
12- /// <param name="Elapsed">Query time elapsed, in seconds.</param>
13- public record LocalResult ( byte [ ] ? Buf , string ? ErrorMessage , ulong RowsRead , ulong BytesRead , TimeSpan Elapsed )
8+ public record LocalResult
149{
10+ public byte [ ] ? Buf { get ; }
11+ public string ? ErrorMessage { get ; }
1512 /// <summary>
1613 /// By text formats contains a result text.
1714 /// </summary>
1815 public string ? Text => Buf == null ? null : System . Text . Encoding . UTF8 . GetString ( Buf ) ;
16+ public ulong RowsRead { get ; }
17+ public ulong BytesRead { get ; }
18+ public TimeSpan Elapsed { get ; }
19+
20+ /// <param name="Buf">Result buffer.</param>
21+ /// <param name="ErrorMessage">Error message if occured.</param>
22+ /// <param name="RowsRead">Number of rows read</param>
23+ /// <param name="BytesRead">Number of bytes read</param>
24+ /// <param name="Elapsed">Query time elapsed, in seconds.</param>
25+ public LocalResult ( byte [ ] ? Buf , string ? ErrorMessage , ulong RowsRead , ulong BytesRead , TimeSpan Elapsed )
26+ {
27+ this . Buf = Buf ;
28+ this . ErrorMessage = ErrorMessage ;
29+ this . RowsRead = RowsRead ;
30+ this . BytesRead = BytesRead ;
31+ this . Elapsed = Elapsed ;
32+ }
1933
2034 internal static LocalResult ? FromPtr ( nint ptr )
2135 {
22- Handle ? h = null ;
2336 if ( ptr == IntPtr . Zero )
2437 return null ;
25- h = Marshal . PtrToStructure < Handle > ( ptr ) ;
38+ var h = Marshal . PtrToStructure < Handle > ( ptr ) ;
2639 if ( h == null )
2740 return null ;
2841
29- var errorMessage = h . error_message == IntPtr . Zero ? null : Marshal . PtrToStringUTF8 ( h . error_message ) ;
42+ var errorMessage = h . error_message == IntPtr . Zero ? null : MarshalPtrToStringUTF8 ( h . error_message ) ;
3043 if ( errorMessage != null )
3144 return new LocalResult ( null , errorMessage , 0 , 0 , TimeSpan . Zero ) ;
3245
@@ -38,6 +51,18 @@ public record LocalResult(byte[]? Buf, string? ErrorMessage, ulong RowsRead, ulo
3851 return new LocalResult ( buf , errorMessage , h . rows_read , h . bytes_read , elapsed ) ;
3952 }
4053
54+ private static string MarshalPtrToStringUTF8 ( nint ptr )
55+ {
56+ unsafe
57+ {
58+ var str = ( byte * ) ptr ;
59+ var length = 0 ;
60+ for ( var i = str ; * i != 0 ; i ++ , length ++ ) ;
61+ var clrString = System . Text . Encoding . UTF8 . GetString ( str , length ) ;
62+ return clrString ;
63+ }
64+ }
65+
4166 [ StructLayout ( LayoutKind . Sequential ) ]
4267 internal class Handle
4368 {
0 commit comments