| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Text; |
| | 4 | | using System.IO; |
| | 5 | | using System.Linq; |
| | 6 | | using System.Threading; |
| | 7 | | using UtilPack; |
| | 8 | | using System.Threading.Tasks; |
| | 9 | | using CBAM.SQL.Implementation; |
| | 10 | | using CBAM.Abstractions.Implementation; |
| | 11 | | using UtilPack.TabularData; |
| | 12 | | using CBAM.Abstractions.Implementation.Tabular; |
| | 13 | |
|
| | 14 | | namespace CBAM.SQL.PostgreSQL.Implementation |
| | 15 | | { |
| | 16 | | internal sealed class PgSQLDataRowColumn : DataColumnSUKSWithConnectionFunctionality<PostgreSQLProtocol> |
| | 17 | | { |
| | 18 | | private readonly DataFormat _dataFormat; |
| | 19 | | private DataRowObject _backendMessage; |
| | 20 | |
|
| | 21 | | public PgSQLDataRowColumn( |
| | 22 | | PgSQLDataColumnMetaDataImpl metadata, |
| | 23 | | Int32 thisStreamIndex, |
| | 24 | | PgSQLDataRowColumn previousColumn, |
| | 25 | | PostgreSQLProtocol protocol, |
| | 26 | | ReservedForStatement reservedForStatement, |
| | 27 | | RowDescription.FieldData fieldData |
| | 28 | | ) : base( metadata, thisStreamIndex, previousColumn, protocol, reservedForStatement ) |
| | 29 | | { |
| | 30 | | this._dataFormat = ArgumentValidator.ValidateNotNull( nameof( fieldData ), fieldData ).DataFormat; |
| | 31 | | } |
| | 32 | |
|
| | 33 | | protected override ValueTask<Object> ReadValueWhileReservedAsync( Int32 byteCount ) |
| | 34 | | { |
| | 35 | | return this.ConnectionFunctionality.ConvertFromBytes( ( (PgSQLDataColumnMetaDataImpl) this.MetaData ).SQLTypeID |
| | 36 | | } |
| | 37 | |
|
| | 38 | | protected override async ValueTask<Int32> ReadByteCountAsync() |
| | 39 | | { |
| | 40 | | return await this._backendMessage.ReadColumnByteCount( this.ConnectionFunctionality.MessageIOArgs, this.Connect |
| | 41 | | } |
| | 42 | |
|
| | 43 | | protected override async ValueTask<Int32> ReadFromStreamWhileReservedAsync( Byte[] array, Int32 offset, Int32 coun |
| | 44 | | { |
| | 45 | | return await this.ConnectionFunctionality.Stream.ReadAsync( array, offset, count, this.ConnectionFunctionality. |
| | 46 | | } |
| | 47 | |
|
| | 48 | | public void Reset( DataRowObject nextRow ) |
| | 49 | | { |
| | 50 | | this.Reset(); |
| | 51 | | Interlocked.Exchange( ref this._backendMessage, nextRow ); |
| | 52 | | } |
| | 53 | | } |
| | 54 | |
|
| | 55 | | internal sealed class PgSQLDataRowMetaDataImpl : DataRowMetaDataImpl<AsyncDataColumnMetaData> //, PgSQLDataRowMetaDat |
| | 56 | | { |
| | 57 | |
|
| | 58 | | public PgSQLDataRowMetaDataImpl( |
| | 59 | | PgSQLDataColumnMetaDataImpl[] columnMetaDatas |
| | 60 | | ) |
| | 61 | | : base( columnMetaDatas ) |
| | 62 | | { |
| | 63 | | } |
| | 64 | | } |
| | 65 | |
|
| | 66 | | internal sealed class PgSQLDataColumnMetaDataImpl : AbstractAsyncDataColumnMetaData, PgSQLDataColumnMetaData |
| | 67 | | { |
| | 68 | |
|
| | 69 | | private readonly PostgreSQLProtocol _connectionFunctionality; |
| | 70 | | private readonly DataFormat _dataFormat; |
| | 71 | |
|
| | 72 | | public PgSQLDataColumnMetaDataImpl( |
| | 73 | | PostgreSQLProtocol connectionFunctionality, |
| | 74 | | DataFormat dataFormat, |
| | 75 | | Int32 typeID, |
| | 76 | | TypeFunctionalityInformation typeInfo, |
| | 77 | | String label |
| 107 | 78 | | ) : base( typeInfo?.CLRType ?? typeof( String ), label ) |
| | 79 | | { |
| 107 | 80 | | this._connectionFunctionality = ArgumentValidator.ValidateNotNull( nameof( connectionFunctionality ), connectio |
| 107 | 81 | | this._dataFormat = dataFormat; |
| 107 | 82 | | this.SQLTypeID = typeID; |
| 107 | 83 | | this.TypeInfo = typeInfo; |
| 107 | 84 | | } |
| | 85 | |
|
| | 86 | | public override Object ChangeType( Object value, Type targetType ) |
| | 87 | | { |
| 25 | 88 | | var typeInfo = this.TypeInfo; |
| 25 | 89 | | return typeInfo.Functionality.ChangeTypePgSQLToFramework( typeInfo.DatabaseData, value, targetType ); |
| | 90 | | } |
| | 91 | |
|
| | 92 | | public override ValueTask<Object> ConvertFromBytesAsync( Stream stream, Int32 byteCount ) |
| | 93 | | { |
| 0 | 94 | | return this._connectionFunctionality.ConvertFromBytes( this.SQLTypeID, this._dataFormat, stream, byteCount ); |
| | 95 | | } |
| | 96 | |
|
| 329 | 97 | | public Int32 SQLTypeID { get; } |
| | 98 | |
|
| 25 | 99 | | private TypeFunctionalityInformation TypeInfo { get; } |
| | 100 | | } |
| | 101 | | } |