forked from Emill/Npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoolHandler.cs
More file actions
executable file
·34 lines (30 loc) · 971 Bytes
/
BoolHandler.cs
File metadata and controls
executable file
·34 lines (30 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Npgsql.BackendMessages;
using NpgsqlTypes;
using System.Data;
namespace Npgsql.TypeHandlers
{
/// <remarks>
/// http://www.postgresql.org/docs/current/static/datatype-boolean.html
/// </remarks>
[TypeMapping("bool", NpgsqlDbType.Boolean, DbType.Boolean, typeof(bool))]
internal class BoolHandler : TypeHandler<bool>,
ISimpleTypeReader<bool>, ISimpleTypeWriter
{
const byte T = (byte)'T';
const byte t = (byte)'t';
public bool Read(NpgsqlBuffer buf, int len, FieldDescription fieldDescription)
{
return buf.ReadByte() != 0;
}
public int ValidateAndGetLength(object value) { return 1; }
public void Write(object value, NpgsqlBuffer buf)
{
var v = ((IConvertible)value).ToBoolean(null);
buf.WriteByte(v ? (byte)1 : (byte)0);
}
}
}