Class NpgsqlSimpleTypeHandler<TDefault>
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.
Inherited Members
Namespace: Npgsql.TypeHandling
Assembly: Npgsql.dll
Syntax
public abstract class NpgsqlSimpleTypeHandler<TDefault> : NpgsqlTypeHandler<TDefault>, INpgsqlTypeHandler<TDefault>, INpgsqlSimpleTypeHandler<TDefault>
Type Parameters
Name | Description |
---|---|
TDefault | The default CLR type that this handler will read and write. For example, calling System.Data.Common.DbDataReader.GetValue(System.Int32)
on a column with this handler will return a value with type |
Constructors
NpgsqlSimpleTypeHandler(PostgresType)
Constructs an NpgsqlSimpleTypeHandler<TDefault>.
Declaration
protected NpgsqlSimpleTypeHandler(PostgresType postgresType)
Parameters
Type | Name | Description |
---|---|---|
PostgresType | postgresType |
Methods
Read(NpgsqlReadBuffer, Int32, 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.
Declaration
public abstract TDefault Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null)
Parameters
Type | Name | Description |
---|---|---|
NpgsqlReadBuffer | buf | The buffer from which to read. |
System.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 |
---|---|
TDefault | The fully-read value. |
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. This method is sealed for NpgsqlSimpleTypeHandler<TDefault>,
override Read(NpgsqlReadBuffer, Int32, FieldDescription).
Declaration
public override sealed ValueTask<TDefault> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
Parameters
Type | Name | Description |
---|---|---|
NpgsqlReadBuffer | buf | The buffer from which to read. |
System.Int32 | len | The byte length of the value. The buffer might not contain the full length, requiring I/O to be performed. |
System.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<TDefault> | The fully-read value. |
Overrides
Read<TAny>(NpgsqlReadBuffer, Int32, 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. Type handlers typically don't need to override this - override
Read(NpgsqlReadBuffer, Int32, FieldDescription) - but may do
so in exceptional cases where reading of arbitrary types is required.
Declaration
public override TAny Read<TAny>(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null)
Parameters
Type | Name | Description |
---|---|---|
NpgsqlReadBuffer | buf | The buffer from which to read. |
System.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 |
---|---|
TAny | The fully-read value. |
Type Parameters
Name | Description |
---|---|
TAny |
Overrides
Read<TAny>(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. This method is sealed for NpgsqlSimpleTypeHandler<TDefault>.
Declaration
protected override sealed 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. |
System.Int32 | len | The byte length of the value. The buffer might not contain the full length, requiring I/O to be performed. |
System.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
ValidateAndGetLength(TDefault, ref NpgsqlLengthCache, NpgsqlParameter)
Simple type handlers override ValidateAndGetLength(TDefault, NpgsqlParameter) instead of this.
Declaration
public override sealed int ValidateAndGetLength(TDefault value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type | Name | Description |
---|---|---|
TDefault | value | |
NpgsqlLengthCache | lengthCache | |
NpgsqlParameter | parameter |
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
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.
Declaration
public abstract int ValidateAndGetLength(TDefault value, NpgsqlParameter parameter)
Parameters
Type | Name | Description |
---|---|---|
TDefault | value | The value to be written to PostgreSQL |
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 |
---|---|
System.Int32 | The number of bytes required to write the value. |
ValidateAndGetLength<TAny>(TAny, ref NpgsqlLengthCache, NpgsqlParameter)
This method is sealed, override ValidateAndGetLength(TDefault, NpgsqlParameter).
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 |
---|---|
System.Int32 |
Type Parameters
Name | Description |
---|---|
TAny |
Overrides
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.
Declaration
protected override int ValidateObjectAndGetLength(object value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | |
NpgsqlLengthCache | lengthCache | |
NpgsqlParameter | parameter |
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
Write(TDefault, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)
Simple type handlers override Write(TDefault, NpgsqlWriteBuffer, NpgsqlParameter) instead of this.
Declaration
public override sealed Task Write(TDefault value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
Type | Name | Description |
---|---|---|
TDefault | value | |
NpgsqlWriteBuffer | buf | |
NpgsqlLengthCache | lengthCache | |
NpgsqlParameter | parameter | |
System.Boolean | async |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Overrides
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.
Declaration
public abstract void Write(TDefault value, NpgsqlWriteBuffer buf, NpgsqlParameter parameter)
Parameters
Type | Name | Description |
---|---|---|
TDefault | value | The value to write. |
NpgsqlWriteBuffer | buf | The buffer to which to write. |
NpgsqlParameter | parameter | 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, Boolean)
Called to write the value of a non-generic NpgsqlParameter. Type handlers generally don't need to override this.
Declaration
protected override Task WriteObjectWithLength(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | |
NpgsqlWriteBuffer | buf | |
NpgsqlLengthCache | lengthCache | |
NpgsqlParameter | parameter | |
System.Boolean | async |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |