Class BitStringHandler
A type handler for the PostgreSQL bit string data type.
Implements
Inherited Members
Namespace: Npgsql.TypeHandlers
Assembly: Npgsql.dll
Syntax
public class BitStringHandler : NpgsqlTypeHandler<BitArray>, INpgsqlTypeHandler<BitArray>, INpgsqlTypeHandler<BitVector32>, INpgsqlTypeHandler<bool>, INpgsqlTypeHandler<string>
Remarks
See http://www.postgresql.org/docs/current/static/datatype-bit.html.
Note that for BIT(1), this handler will return a bool by default, to align with SQLClient (see discussion https://github.com/npgsql/npgsql/pull/362#issuecomment-59622101).
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
BitStringHandler(PostgresType)
Declaration
public BitStringHandler(PostgresType postgresType)
Parameters
Type | Name | Description |
---|---|---|
PostgresType | postgresType |
Methods
CreateArrayHandler(PostgresArrayType)
Creates a type handler for arrays of this handler's type.
Declaration
public override ArrayHandler CreateArrayHandler(PostgresArrayType backendType)
Parameters
Type | Name | Description |
---|---|---|
PostgresArrayType | backendType |
Returns
Type | Description |
---|---|
ArrayHandler |
Overrides
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<BitArray> 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<System.Collections.BitArray> | The fully-read value. |
Overrides
ValidateAndGetLength(Boolean, 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(bool value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | 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(BitArray, ref NpgsqlLengthCache, NpgsqlParameter)
Called to validate and get the length of a value of a generic NpgsqlParameter<T>.
Declaration
public override int ValidateAndGetLength(BitArray value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.BitArray | value | |
NpgsqlLengthCache | lengthCache | |
NpgsqlParameter | parameter |
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
ValidateAndGetLength(BitVector32, 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(BitVector32 value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Specialized.BitVector32 | 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)
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(string value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type | Name | Description |
---|---|---|
System.String | 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. |
Write(Boolean, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)
Writes a value to the provided buffer.
Declaration
public Task Write(bool value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | 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(BitArray, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)
Called to write the value of a generic NpgsqlParameter<T>.
Declaration
public override Task Write(BitArray value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.BitArray | value | |
NpgsqlWriteBuffer | buf | |
NpgsqlLengthCache | lengthCache | |
NpgsqlParameter | parameter | |
System.Boolean | async |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Overrides
Write(BitVector32, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)
Writes a value to the provided buffer.
Declaration
public Task Write(BitVector32 value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Specialized.BitVector32 | 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)
Writes a value to the provided buffer.
Declaration
public Task Write(string value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
Type | Name | Description |
---|---|---|
System.String | 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 |
Explicit Interface Implementations
INpgsqlTypeHandler<Boolean>.Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
Declaration
ValueTask<bool> INpgsqlTypeHandler<bool>.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.Boolean> |
INpgsqlTypeHandler<BitVector32>.Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
Declaration
ValueTask<BitVector32> INpgsqlTypeHandler<BitVector32>.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.Collections.Specialized.BitVector32> |
INpgsqlTypeHandler<String>.Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
Declaration
ValueTask<string> INpgsqlTypeHandler<string>.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.String> |