Table of Contents

Class NpgsqlSimpleTypeHandler<TDefault>

Namespace
Npgsql.TypeHandling
Assembly
Npgsql.dll

Base class for all simple type handlers, which read and write short, non-arbitrary lengthed values to PostgreSQL. Provides a simpler API to implement when compared to NpgsqlTypeHandler - Npgsql takes care of all I/O before calling into this type, so no I/O needs to be performed by it.

public abstract class NpgsqlSimpleTypeHandler<TDefault> : NpgsqlTypeHandler<TDefault>, INpgsqlTypeHandler<TDefault>, INpgsqlSimpleTypeHandler<TDefault>

Type Parameters

TDefault

The default CLR type that this handler will read and write. For example, calling GetValue(int) on a column with this handler will return a value with type TDefault. Type handlers can support additional types by implementing INpgsqlTypeHandler<T>.

Inheritance
NpgsqlSimpleTypeHandler<TDefault>
Implements
Derived
Inherited Members

Constructors

NpgsqlSimpleTypeHandler()

protected NpgsqlSimpleTypeHandler()

Methods

Read(NpgsqlReadBuffer, int, FieldDescription)

Reads a value of type TDefault 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.

public abstract TDefault Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null)

Parameters

buf NpgsqlReadBuffer

The buffer from which to read.

len int

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

TDefault

The fully-read value.

Read(NpgsqlReadBuffer, int, bool, FieldDescription)

Reads a value of type TDefault with the given length from the provided buffer, using either sync or async I/O. This method is sealed for NpgsqlSimpleTypeHandler<TDefault>, override Read(NpgsqlReadBuffer, int, FieldDescription).

public override sealed ValueTask<TDefault> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)

Parameters

buf NpgsqlReadBuffer

The buffer from which to read.

len int

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

async bool

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

ValueTask<TDefault>

The fully-read value.

Read<TAny>(NpgsqlReadBuffer, int, bool, FieldDescription)

Reads a value of type TDefault with the given length from the provided buffer, using either sync or async I/O. This method is sealed for NpgsqlSimpleTypeHandler<TDefault>.

protected override sealed ValueTask<TAny> Read<TAny>(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)

Parameters

buf NpgsqlReadBuffer

The buffer from which to read.

len int

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

async bool

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

ValueTask<TAny>

The fully-read value.

Type Parameters

TAny

ValidateAndGetLength(TDefault, ref NpgsqlLengthCache, NpgsqlParameter)

Simple type handlers override ValidateAndGetLength(TDefault, NpgsqlParameter) instead of this.

public override sealed int ValidateAndGetLength(TDefault value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)

Parameters

value TDefault
lengthCache NpgsqlLengthCache
parameter NpgsqlParameter

Returns

int

ValidateAndGetLength(TDefault, 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 abstract int ValidateAndGetLength(TDefault value, NpgsqlParameter parameter)

Parameters

value TDefault

The value to be written to PostgreSQL

parameter NpgsqlParameter

The 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)

This method is sealed, override ValidateAndGetLength(TDefault, NpgsqlParameter).

protected override int ValidateAndGetLength<TAny>(TAny value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)

Parameters

value TAny
lengthCache NpgsqlLengthCache
parameter NpgsqlParameter

Returns

int

Type Parameters

TAny

ValidateObjectAndGetLength(object, ref NpgsqlLengthCache, NpgsqlParameter)

Called to validate and get the length of a value of a non-generic NpgsqlParameter. Type handlers generally don't need to override this.

protected override int ValidateObjectAndGetLength(object value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)

Parameters

value object
lengthCache NpgsqlLengthCache
parameter NpgsqlParameter

Returns

int

Write(TDefault, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, bool)

Simple type handlers override Write(TDefault, NpgsqlWriteBuffer, NpgsqlParameter) instead of this.

public override sealed Task Write(TDefault value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)

Parameters

value TDefault
buf NpgsqlWriteBuffer
lengthCache NpgsqlLengthCache
parameter NpgsqlParameter
async bool

Returns

Task

Write(TDefault, NpgsqlWriteBuffer, NpgsqlParameter)

Writes a value to the provided buffer, with the assumption that there is enough space in the buffer (no I/O will occur). The Npgsql core will have taken care of that.

public abstract void Write(TDefault value, NpgsqlWriteBuffer buf, NpgsqlParameter parameter)

Parameters

value TDefault

The value to write.

buf NpgsqlWriteBuffer

The buffer to which to write.

parameter NpgsqlParameter

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

WriteObjectWithLength(object, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, bool)

Called to write the value of a non-generic NpgsqlParameter. Type handlers generally don't need to override this.

protected override Task WriteObjectWithLength(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)

Parameters

value object
buf NpgsqlWriteBuffer
lengthCache NpgsqlLengthCache
parameter NpgsqlParameter
async bool

Returns

Task