Search Results for

    Show / Hide Table of Contents

    Class ArrayHandler<TElement>

    Base class for all type handlers which handle PostgreSQL arrays.

    Inheritance
    Object
    NpgsqlTypeHandler
    ArrayHandler
    ArrayHandler<TElement>
    BitStringArrayHandler
    Inherited Members
    ArrayHandler.CreateArrayHandler(PostgresArrayType)
    ArrayHandler.CreateRangeHandler(PostgresRangeType)
    NpgsqlTypeHandler.CreateConversionButNoParamException(Type)
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Object.ToString()
    Namespace: Npgsql.TypeHandlers
    Assembly: Npgsql.dll
    Syntax
    public class ArrayHandler<TElement> : ArrayHandler
    Type Parameters
    Name Description
    TElement
    Remarks

    http://www.postgresql.org/docs/current/static/arrays.html.

    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

    | Improve this Doc

    ArrayHandler(PostgresType, NpgsqlTypeHandler, Int32)

    Declaration
    public ArrayHandler(PostgresType arrayPostgresType, NpgsqlTypeHandler elementHandler, int lowerBound = 1)
    Parameters
    Type Name Description
    PostgresType arrayPostgresType
    NpgsqlTypeHandler elementHandler
    Int32 lowerBound

    Methods

    | Improve this Doc

    Read<TRequestedArray>(NpgsqlReadBuffer, Int32, FieldDescription)

    Reads a value of type TAny with the given length from the provided buffer, with the assumption that it is entirely present in the provided memory buffer and no I/O will be required. This can save the overhead of async functions and improves performance.

    Declaration
    public override TRequestedArray Read<TRequestedArray>(NpgsqlReadBuffer buf, int len, 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.

    FieldDescription fieldDescription

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

    Returns
    Type Description
    TRequestedArray

    The fully-read value.

    Type Parameters
    Name Description
    TRequestedArray
    Overrides
    NpgsqlTypeHandler.Read<TAny>(NpgsqlReadBuffer, Int32, FieldDescription)
    | Improve this Doc

    Read<TAny>(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)

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

    Declaration
    protected override async ValueTask<TAny> Read<TAny>(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<TAny>

    The fully-read value.

    Type Parameters
    Name Description
    TAny
    Overrides
    NpgsqlTypeHandler.Read<TAny>(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
    | Improve this Doc

    ReadArray<TAnyElement>(NpgsqlReadBuffer, Boolean, Int32)

    Reads an array of element type TAnyElement from the given buffer buf.

    Declaration
    protected async ValueTask<Array> ReadArray<TAnyElement>(NpgsqlReadBuffer buf, bool async, int expectedDimensions = 0)
    Parameters
    Type Name Description
    NpgsqlReadBuffer buf
    Boolean async
    Int32 expectedDimensions
    Returns
    Type Description
    ValueTask<Array>
    Type Parameters
    Name Description
    TAnyElement
    | Improve this Doc

    ReadList<TAnyElement>(NpgsqlReadBuffer, Boolean)

    Reads an array of element type TAnyElement from the given buffer buf.

    Declaration
    protected async ValueTask<List<TAnyElement>> ReadList<TAnyElement>(NpgsqlReadBuffer buf, bool async)
    Parameters
    Type Name Description
    NpgsqlReadBuffer buf
    Boolean async
    Returns
    Type Description
    ValueTask<List<TAnyElement>>
    Type Parameters
    Name Description
    TAnyElement
    | Improve this Doc

    ValidateAndGetLength<TAny>(TAny, ref NpgsqlLengthCache, NpgsqlParameter)

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

    Declaration
    protected override int ValidateAndGetLength<TAny>(TAny value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
    Parameters
    Type Name Description
    TAny value
    NpgsqlLengthCache lengthCache
    NpgsqlParameter parameter
    Returns
    Type Description
    Int32
    Type Parameters
    Name Description
    TAny
    Overrides
    Npgsql.TypeHandling.NpgsqlTypeHandler.ValidateAndGetLength<TAny>(TAny, Npgsql.NpgsqlLengthCache, Npgsql.NpgsqlParameter)
    | Improve this Doc

    ValidateObjectAndGetLength(Object, 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 shold be thrown. Also returns the byte length needed to write the value.

    Declaration
    protected override int ValidateObjectAndGetLength(object value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
    Parameters
    Type Name Description
    Object value

    The value to be written to PostgreSQL

    NpgsqlLengthCache lengthCache

    If the byte length calculation is costly (e.g. for UTF-8 strings), its result can be stored in the length cache to be reused in the writing process, preventing recalculation.

    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.

    Overrides
    NpgsqlTypeHandler.ValidateObjectAndGetLength(Object, ref NpgsqlLengthCache, NpgsqlParameter)
    | Improve this Doc

    WriteObjectWithLength(Object, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)

    Writes a value to the provided buffer, using either sync or async I/O.

    Declaration
    protected override Task WriteObjectWithLength(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
    Parameters
    Type Name Description
    Object value

    The value to write.

    NpgsqlWriteBuffer buf

    The buffer to which to write.

    NpgsqlLengthCache lengthCache
    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 is required to read the full length of the value, whether it should be performed synchronously or asynchronously.

    Returns
    Type Description
    Task
    Overrides
    NpgsqlTypeHandler.WriteObjectWithLength(Object, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)
    • Improve this Doc
    In This Article
    Back to top © Copyright 2021 The Npgsql Development Team