Search Results for

    Show / Hide Table of Contents

    Class BitStringHandler

    A type handler for the PostgreSQL bit string data type.

    Inheritance
    Object
    NpgsqlTypeHandler
    NpgsqlTypeHandler<BitArray>
    BitStringHandler
    Implements
    INpgsqlTypeHandler<BitArray>
    INpgsqlTypeHandler<BitVector32>
    INpgsqlTypeHandler<Boolean>
    INpgsqlTypeHandler<String>
    Inherited Members
    NpgsqlTypeHandler<BitArray>.CreateRangeHandler(PostgresType)
    NpgsqlTypeHandler<BitArray>.CreateMultirangeHandler(PostgresMultirangeType)
    NpgsqlTypeHandler.PostgresType
    NpgsqlTypeHandler.Read<TAny>(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
    NpgsqlTypeHandler.Read<TAny>(NpgsqlReadBuffer, Int32, FieldDescription)
    NpgsqlTypeHandler.ReadCustom<TAny>(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
    NpgsqlTypeHandler.ValidateAndGetLength<TAny>(TAny, NpgsqlLengthCache, NpgsqlParameter)
    NpgsqlTypeHandler.ValidateAndGetLengthCustom<TAny>(TAny, NpgsqlLengthCache, NpgsqlParameter)
    NpgsqlTypeHandler.WriteWithLength<TAny>(TAny, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)
    NpgsqlTypeHandler.WriteWithLengthCustom<TAny>(TAny, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)
    NpgsqlTypeHandler.ValidateObjectAndGetLength(Object, NpgsqlLengthCache, NpgsqlParameter)
    NpgsqlTypeHandler.WriteObjectWithLength(Object, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)
    NpgsqlTypeHandler.CreateConversionButNoParamException(Type)
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Object.ToString()
    Namespace: Npgsql.Internal.TypeHandlers
    Assembly: Npgsql.dll
    Syntax
    public class BitStringHandler : NpgsqlTypeHandler<BitArray>, INpgsqlTypeHandler<BitArray>, INpgsqlTypeHandler<BitVector32>, INpgsqlTypeHandler<bool>, INpgsqlTypeHandler<string>
    Remarks

    See https://www.postgresql.org/docs/current/static/datatype-bit.html.

    Note that for BIT(1), this handler will return a bool by default, to align with SQLClient (see discussion https://github.com/npgsql/npgsql/pull/362#issuecomment-59622101).

    The type handler API allows customizing Npgsql's behavior in powerful ways. However, although it is public, it should be considered somewhat unstable, and may change in breaking ways, including in non-major releases. Use it at your own risk.

    Constructors

    BitStringHandler(PostgresType)

    Declaration
    public BitStringHandler(PostgresType pgType)
    Parameters
    Type Name Description
    PostgresType pgType

    Methods

    CreateArrayHandler(PostgresArrayType, ArrayNullabilityMode)

    Creates a type handler for arrays of this handler's type.

    Declaration
    public override NpgsqlTypeHandler CreateArrayHandler(PostgresArrayType pgArrayType, ArrayNullabilityMode arrayNullabilityMode)
    Parameters
    Type Name Description
    PostgresArrayType pgArrayType
    ArrayNullabilityMode arrayNullabilityMode
    Returns
    Type Description
    NpgsqlTypeHandler
    Overrides
    Npgsql.Internal.TypeHandling.NpgsqlTypeHandler<System.Collections.BitArray>.CreateArrayHandler(Npgsql.PostgresTypes.PostgresArrayType, Npgsql.ArrayNullabilityMode)

    GetFieldType(FieldDescription)

    Declaration
    public override Type GetFieldType(FieldDescription fieldDescription = null)
    Parameters
    Type Name Description
    FieldDescription fieldDescription
    Returns
    Type Description
    Type
    Overrides
    Npgsql.Internal.TypeHandling.NpgsqlTypeHandler<System.Collections.BitArray>.GetFieldType(Npgsql.BackendMessages.FieldDescription)

    GetProviderSpecificFieldType(FieldDescription)

    Declaration
    public override Type GetProviderSpecificFieldType(FieldDescription fieldDescription = null)
    Parameters
    Type Name Description
    FieldDescription fieldDescription
    Returns
    Type Description
    Type
    Overrides
    Npgsql.Internal.TypeHandling.NpgsqlTypeHandler<System.Collections.BitArray>.GetProviderSpecificFieldType(Npgsql.BackendMessages.FieldDescription)

    Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)

    Reads a value of type TDefault with the given length from the provided buffer, using either sync or async I/O.

    Declaration
    public override async ValueTask<BitArray> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
    Parameters
    Type Name Description
    NpgsqlReadBuffer buf

    The buffer from which to read.

    Int32 len

    The byte length of the value. The buffer might not contain the full length, requiring I/O to be performed.

    Boolean async

    If I/O is required to read the full length of the value, whether it should be performed synchronously or asynchronously.

    FieldDescription fieldDescription

    Additional PostgreSQL information about the type, such as the length in varchar(30).

    Returns
    Type Description
    ValueTask<BitArray>

    The fully-read value.

    Overrides
    Npgsql.Internal.TypeHandling.NpgsqlTypeHandler<System.Collections.BitArray>.Read(Npgsql.Internal.NpgsqlReadBuffer, System.Int32, System.Boolean, Npgsql.BackendMessages.FieldDescription)

    ReadAsObject(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)

    Declaration
    public override async ValueTask<object> ReadAsObject(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
    Parameters
    Type Name Description
    NpgsqlReadBuffer buf
    Int32 len
    Boolean async
    FieldDescription fieldDescription
    Returns
    Type Description
    ValueTask<Object>
    Overrides
    Npgsql.Internal.TypeHandling.NpgsqlTypeHandler<System.Collections.BitArray>.ReadAsObject(Npgsql.Internal.NpgsqlReadBuffer, System.Int32, System.Boolean, Npgsql.BackendMessages.FieldDescription)

    ValidateAndGetLength(Boolean, ref NpgsqlLengthCache, NpgsqlParameter)

    Responsible for validating that a value represents a value of the correct and which can be written for PostgreSQL - if the value cannot be written for any reason, an exception should be thrown. Also returns the byte length needed to write the value.

    Declaration
    public int ValidateAndGetLength(bool value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
    Parameters
    Type Name Description
    Boolean value
    NpgsqlLengthCache lengthCache

    A cache where the length calculated during the validation phase can be stored for use at the writing phase.

    NpgsqlParameter parameter

    The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).

    Returns
    Type Description
    Int32

    The number of bytes required to write the value.

    ValidateAndGetLength(BitArray, ref NpgsqlLengthCache, NpgsqlParameter)

    Called to validate and get the length of a value of a generic NpgsqlParameter<T>.

    Declaration
    public override int ValidateAndGetLength(BitArray value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
    Parameters
    Type Name Description
    BitArray value
    NpgsqlLengthCache lengthCache
    NpgsqlParameter parameter
    Returns
    Type Description
    Int32
    Overrides
    Npgsql.Internal.TypeHandling.NpgsqlTypeHandler<System.Collections.BitArray>.ValidateAndGetLength(System.Collections.BitArray, Npgsql.Internal.TypeHandling.NpgsqlLengthCache, Npgsql.NpgsqlParameter)

    ValidateAndGetLength(BitVector32, ref NpgsqlLengthCache, NpgsqlParameter)

    Responsible for validating that a value represents a value of the correct and which can be written for PostgreSQL - if the value cannot be written for any reason, an exception should be thrown. Also returns the byte length needed to write the value.

    Declaration
    public int ValidateAndGetLength(BitVector32 value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
    Parameters
    Type Name Description
    BitVector32 value
    NpgsqlLengthCache lengthCache

    A cache where the length calculated during the validation phase can be stored for use at the writing phase.

    NpgsqlParameter parameter

    The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).

    Returns
    Type Description
    Int32

    The number of bytes required to write the value.

    ValidateAndGetLength(String, ref NpgsqlLengthCache, NpgsqlParameter)

    Responsible for validating that a value represents a value of the correct and which can be written for PostgreSQL - if the value cannot be written for any reason, an exception should be thrown. Also returns the byte length needed to write the value.

    Declaration
    public int ValidateAndGetLength(string value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
    Parameters
    Type Name Description
    String value
    NpgsqlLengthCache lengthCache

    A cache where the length calculated during the validation phase can be stored for use at the writing phase.

    NpgsqlParameter parameter

    The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).

    Returns
    Type Description
    Int32

    The number of bytes required to write the value.

    Write(Boolean, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)

    Writes a value to the provided buffer.

    Declaration
    public async Task Write(bool value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async, CancellationToken cancellationToken = default(CancellationToken))
    Parameters
    Type Name Description
    Boolean value
    NpgsqlWriteBuffer buf

    The buffer to which to write.

    NpgsqlLengthCache lengthCache

    A cache where the length calculated during the validation phase can be stored for use at the writing phase.

    NpgsqlParameter parameter

    The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).

    Boolean async

    If I/O will be necessary (i.e. the buffer is full), determines whether it will be done synchronously or asynchronously.

    CancellationToken cancellationToken

    An optional token to cancel the asynchronous operation. The default value is None.

    Returns
    Type Description
    Task

    Write(BitArray, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)

    Called to write the value of a generic NpgsqlParameter<T>.

    Declaration
    public override async Task Write(BitArray value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async, CancellationToken cancellationToken = default(CancellationToken))
    Parameters
    Type Name Description
    BitArray value
    NpgsqlWriteBuffer buf
    NpgsqlLengthCache lengthCache
    NpgsqlParameter parameter
    Boolean async
    CancellationToken cancellationToken
    Returns
    Type Description
    Task
    Overrides
    Npgsql.Internal.TypeHandling.NpgsqlTypeHandler<System.Collections.BitArray>.Write(System.Collections.BitArray, Npgsql.Internal.NpgsqlWriteBuffer, Npgsql.Internal.TypeHandling.NpgsqlLengthCache, Npgsql.NpgsqlParameter, System.Boolean, System.Threading.CancellationToken)

    Write(BitVector32, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)

    Writes a value to the provided buffer.

    Declaration
    public async Task Write(BitVector32 value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async, CancellationToken cancellationToken = default(CancellationToken))
    Parameters
    Type Name Description
    BitVector32 value
    NpgsqlWriteBuffer buf

    The buffer to which to write.

    NpgsqlLengthCache lengthCache

    A cache where the length calculated during the validation phase can be stored for use at the writing phase.

    NpgsqlParameter parameter

    The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).

    Boolean async

    If I/O will be necessary (i.e. the buffer is full), determines whether it will be done synchronously or asynchronously.

    CancellationToken cancellationToken

    An optional token to cancel the asynchronous operation. The default value is None.

    Returns
    Type Description
    Task

    Write(String, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)

    Writes a value to the provided buffer.

    Declaration
    public async Task Write(string value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async, CancellationToken cancellationToken = default(CancellationToken))
    Parameters
    Type Name Description
    String value
    NpgsqlWriteBuffer buf

    The buffer to which to write.

    NpgsqlLengthCache lengthCache

    A cache where the length calculated during the validation phase can be stored for use at the writing phase.

    NpgsqlParameter parameter

    The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).

    Boolean async

    If I/O will be necessary (i.e. the buffer is full), determines whether it will be done synchronously or asynchronously.

    CancellationToken cancellationToken

    An optional token to cancel the asynchronous operation. The default value is None.

    Returns
    Type Description
    Task

    Explicit Interface Implementations

    INpgsqlTypeHandler<Boolean>.Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)

    Declaration
    async ValueTask<bool> INpgsqlTypeHandler<bool>.Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription)
    Parameters
    Type Name Description
    NpgsqlReadBuffer buf
    Int32 len
    Boolean async
    FieldDescription fieldDescription
    Returns
    Type Description
    ValueTask<Boolean>

    INpgsqlTypeHandler<BitVector32>.Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)

    Declaration
    async ValueTask<BitVector32> INpgsqlTypeHandler<BitVector32>.Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription)
    Parameters
    Type Name Description
    NpgsqlReadBuffer buf
    Int32 len
    Boolean async
    FieldDescription fieldDescription
    Returns
    Type Description
    ValueTask<BitVector32>

    INpgsqlTypeHandler<String>.Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)

    Declaration
    ValueTask<string> INpgsqlTypeHandler<string>.Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription)
    Parameters
    Type Name Description
    NpgsqlReadBuffer buf
    Int32 len
    Boolean async
    FieldDescription fieldDescription
    Returns
    Type Description
    ValueTask<String>

    Implements

    INpgsqlTypeHandler<T>
    INpgsqlTypeHandler<T>
    INpgsqlTypeHandler<T>
    INpgsqlTypeHandler<T>
    In This Article
    Back to top © Copyright 2022 The Npgsql Development Team