Show / Hide Table of Contents

Class TextHandler

A type handler for PostgreSQL character data types (text, char, varchar, xml...).

Inheritance
System.Object
NpgsqlTypeHandler
NpgsqlTypeHandler<System.String>
TextHandler
Implements
INpgsqlTypeHandler<System.String>
INpgsqlTypeHandler<System.Char[]>
INpgsqlTypeHandler<System.ArraySegment<System.Char>>
INpgsqlTypeHandler<System.Char>
INpgsqlTypeHandler<System.Byte[]>
Inherited Members
NpgsqlTypeHandler<String>.Read<TAny>(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
NpgsqlTypeHandler<String>.Read<TAny>(NpgsqlReadBuffer, Int32, FieldDescription)
NpgsqlTypeHandler<String>.ValidateAndGetLength<TAny>(TAny, NpgsqlLengthCache, NpgsqlParameter)
NpgsqlTypeHandler<String>.WriteWithLength<TAny>(TAny, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)
NpgsqlTypeHandler<String>.ValidateObjectAndGetLength(Object, NpgsqlLengthCache, NpgsqlParameter)
NpgsqlTypeHandler<String>.WriteObjectWithLength(Object, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)
NpgsqlTypeHandler<String>.CreateArrayHandler(PostgresArrayType)
NpgsqlTypeHandler<String>.CreateRangeHandler(PostgresRangeType)
NpgsqlTypeHandler.CreateConversionButNoParamException(Type)
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Npgsql.TypeHandlers
Assembly: Npgsql.dll
Syntax
public class TextHandler : NpgsqlTypeHandler<string>, INpgsqlTypeHandler<string>, INpgsqlTypeHandler<char[]>, INpgsqlTypeHandler<ArraySegment<char>>, INpgsqlTypeHandler<char>, INpgsqlTypeHandler<byte[]>, ITextReaderHandler
Remarks

See https://www.postgresql.org/docs/current/datatype-character.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

TextHandler(PostgresType, NpgsqlConnection)

Declaration
protected TextHandler(PostgresType postgresType, NpgsqlConnection connection)
Parameters
Type Name Description
PostgresType postgresType
NpgsqlConnection connection

TextHandler(PostgresType, Encoding)

Declaration
protected TextHandler(PostgresType postgresType, Encoding encoding)
Parameters
Type Name Description
PostgresType postgresType
System.Text.Encoding encoding

Methods

GetTextReader(Stream)

Declaration
public virtual TextReader GetTextReader(Stream stream)
Parameters
Type Name Description
System.IO.Stream stream
Returns
Type Description
System.IO.TextReader

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 ValueTask<string> Read(NpgsqlReadBuffer buf, int byteLen, bool async, FieldDescription fieldDescription = null)
Parameters
Type Name Description
NpgsqlReadBuffer buf

The buffer from which to read.

System.Int32 byteLen
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<System.String>

The fully-read value.

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

ValidateAndGetLength(ArraySegment<Char>, 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 virtual int ValidateAndGetLength(ArraySegment<char> value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type Name Description
System.ArraySegment<System.Char> 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
System.Int32

The number of bytes required to write the value.

ValidateAndGetLength(Byte[], 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(byte[] value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type Name Description
System.Byte[] 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
System.Int32

The number of bytes required to write the value.

ValidateAndGetLength(Char, 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(char value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type Name Description
System.Char 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
System.Int32

The number of bytes required to write the value.

ValidateAndGetLength(Char[], 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 virtual int ValidateAndGetLength(char[] value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type Name Description
System.Char[] 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
System.Int32

The number of bytes required to write the value.

ValidateAndGetLength(String, ref NpgsqlLengthCache, NpgsqlParameter)

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

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

Write(ArraySegment<Char>, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)

Writes a value to the provided buffer.

Declaration
public virtual Task Write(ArraySegment<char> value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
Type Name Description
System.ArraySegment<System.Char> 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).

System.Boolean async

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

Returns
Type Description
System.Threading.Tasks.Task

Write(Byte[], NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)

Writes a value to the provided buffer.

Declaration
public Task Write(byte[] value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
Type Name Description
System.Byte[] 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).

System.Boolean async

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

Returns
Type Description
System.Threading.Tasks.Task

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

Writes a value to the provided buffer.

Declaration
public Task Write(char value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
Type Name Description
System.Char 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).

System.Boolean async

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

Returns
Type Description
System.Threading.Tasks.Task

Write(Char[], NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)

Writes a value to the provided buffer.

Declaration
public virtual Task Write(char[] value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
Type Name Description
System.Char[] 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).

System.Boolean async

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

Returns
Type Description
System.Threading.Tasks.Task

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

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

Declaration
public override Task Write(string value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
Type Name Description
System.String value
NpgsqlWriteBuffer buf
NpgsqlLengthCache lengthCache
NpgsqlParameter parameter
System.Boolean async
Returns
Type Description
System.Threading.Tasks.Task
Overrides
Npgsql.TypeHandling.NpgsqlTypeHandler<System.String>.Write(System.String, Npgsql.NpgsqlWriteBuffer, Npgsql.NpgsqlLengthCache, Npgsql.NpgsqlParameter, System.Boolean)

Explicit Interface Implementations

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

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

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

Declaration
ValueTask<byte[]> INpgsqlTypeHandler<byte[]>.Read(NpgsqlReadBuffer buf, int byteLen, bool async, FieldDescription fieldDescription)
Parameters
Type Name Description
NpgsqlReadBuffer buf
System.Int32 byteLen
System.Boolean async
FieldDescription fieldDescription
Returns
Type Description
ValueTask<System.Byte[]>

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

Declaration
ValueTask<char[]> INpgsqlTypeHandler<char[]>.Read(NpgsqlReadBuffer buf, int byteLen, bool async, FieldDescription fieldDescription)
Parameters
Type Name Description
NpgsqlReadBuffer buf
System.Int32 byteLen
System.Boolean async
FieldDescription fieldDescription
Returns
Type Description
ValueTask<System.Char[]>

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

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

Implements

INpgsqlTypeHandler<T>
INpgsqlTypeHandler<T>
INpgsqlTypeHandler<T>
INpgsqlTypeHandler<T>
INpgsqlTypeHandler<T>
In This Article
Back to top Generated by DocFX