Class RangeHandler<TElement>
- Namespace
- Npgsql.TypeHandlers
- Assembly
- Npgsql.dll
Type handler for PostgreSQL range types
public class RangeHandler<TElement> : RangeHandler, INpgsqlTypeHandler<NpgsqlRange<TElement>>
Type Parameters
TElement
the range subtype
- Inheritance
-
RangeHandler<TElement>
- Implements
-
INpgsqlTypeHandler<NpgsqlRange<TElement>>
- Inherited Members
Remarks
Introduced in PostgreSQL 9.2. http://www.postgresql.org/docs/current/static/rangetypes.html
Constructors
RangeHandler(NpgsqlTypeHandler)
public RangeHandler(NpgsqlTypeHandler elementHandler)
Parameters
elementHandler
NpgsqlTypeHandler
Methods
CreateArrayHandler(PostgresType)
Creates a type handler for arrays of this handler's type.
public override ArrayHandler CreateArrayHandler(PostgresType arrayBackendType)
Parameters
arrayBackendType
PostgresType
Returns
Read(NpgsqlReadBuffer, int, bool, FieldDescription)
Reads a value of type NpgsqlTypes.NpgsqlRange{`0} with the given length from the provided buffer, using either sync or async I/O.
public ValueTask<NpgsqlRange<TElement>> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription)
Parameters
buf
NpgsqlReadBufferThe buffer from which to read.
len
intThe byte length of the value. The buffer might not contain the full length, requiring I/O to be performed.
async
boolIf I/O is required to read the full length of the value, whether it should be performed synchronously or asynchronously.
fieldDescription
FieldDescriptionAdditional PostgreSQL information about the type, such as the length in varchar(30).
Returns
- ValueTask<NpgsqlRange<TElement>>
The fully-read value.
Read<TAny>(NpgsqlReadBuffer, int, bool, FieldDescription)
Reads a value of type TAny
with the given length from the provided buffer,
using either sync or async I/O.
protected override ValueTask<TAny> Read<TAny>(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
Parameters
buf
NpgsqlReadBufferThe buffer from which to read.
len
intThe byte length of the value. The buffer might not contain the full length, requiring I/O to be performed.
async
boolIf I/O is required to read the full length of the value, whether it should be performed synchronously or asynchronously.
fieldDescription
FieldDescriptionAdditional PostgreSQL information about the type, such as the length in varchar(30).
Returns
- ValueTask<TAny>
The fully-read value.
Type Parameters
TAny
ValidateAndGetLength(NpgsqlRange<TElement>, 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.
public int ValidateAndGetLength(NpgsqlRange<TElement> value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
value
NpgsqlRange<TElement>The value to be written to PostgreSQL
lengthCache
NpgsqlLengthCacheA cache where the length calculated during the validation phase can be stored for use at the writing phase.
parameter
NpgsqlParameterThe NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).
Returns
- int
The number of bytes required to write the value.
ValidateAndGetLength<TAny>(TAny, ref NpgsqlLengthCache, NpgsqlParameter)
Called to validate and get the length of a value of a generic NpgsqlParameter<T>.
protected override int ValidateAndGetLength<TAny>(TAny value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
value
TAnylengthCache
NpgsqlLengthCacheparameter
NpgsqlParameter
Returns
Type Parameters
TAny
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.
protected override int ValidateObjectAndGetLength(object value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter = null)
Parameters
value
objectThe value to be written to PostgreSQL
lengthCache
NpgsqlLengthCacheIf 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.
parameter
NpgsqlParameterThe NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).
Returns
- int
The number of bytes required to write the value.
Write(NpgsqlRange<TElement>, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, bool)
Writes a value to the provided buffer.
public Task Write(NpgsqlRange<TElement> value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
value
NpgsqlRange<TElement>The value to write.
buf
NpgsqlWriteBufferThe buffer to which to write.
lengthCache
NpgsqlLengthCacheA cache where the length calculated during the validation phase can be stored for use at the writing phase.
parameter
NpgsqlParameterThe NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).
async
boolIf I/O will be necessary (i.e. the buffer is full), determines whether it will be done synchronously or asynchronously.
Returns
WriteObjectWithLength(object, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, bool)
Writes a value to the provided buffer, using either sync or async I/O.
protected override Task WriteObjectWithLength(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
value
objectThe value to write.
buf
NpgsqlWriteBufferThe buffer to which to write.
lengthCache
NpgsqlLengthCacheparameter
NpgsqlParameterThe NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).
async
boolIf I/O is required to read the full length of the value, whether it should be performed synchronously or asynchronously.