18 using System.Globalization;
24 namespace Deveel.Data.Types {
28 : base(
"BOOLEAN", typeCode) {
29 AssertIsBoolean(typeCode);
37 if (!IsBooleanType(sqlType))
38 throw new ArgumentException(
String.Format(
"The SQL type {0} is not BOOLEAN.", sqlType));
46 public override bool IsStorable {
64 throw new ArgumentException();
70 b = ((SqlNumber) y) == SqlNumber.One ? SqlBoolean.
True : ((SqlNumber) y) == SqlNumber.Zero ? SqlBoolean.
False : SqlBoolean.
Null;
71 }
else if (y is SqlBoolean) {
74 throw new ArgumentException();
77 return a.CompareTo(b);
94 var s = Convert.ToString(bValue);
111 var bytes = (byte[]) Convert.ChangeType(bValue, typeof (byte[]), CultureInfo.InvariantCulture);
117 return base.
CastTo(value, destType);
126 var writer =
new BinaryWriter(stream);
129 writer.Write((byte)0);
134 writer.Write((byte)0);
137 writer.Write((byte)1);
138 writer.Write((byte)(value ? 1 : 0));
141 throw new ArgumentException(
"Cannot serialize an object that is not a BOOLEAN using a boolean type.");
146 var reader =
new BinaryReader(stream);
148 var type = reader.ReadByte();
152 var value = reader.ReadByte();
157 return obj.
IsNull ? 1 : 1 + 1;
161 return Negate(value);
static readonly SqlBoolean True
Represents the materialization of a true boolean.
override Type GetRuntimeType()
static bool IsBooleanType(SqlTypeCode sqlType)
A long string in the system.
BooleanType(SqlTypeCode typeCode)
DataObject CastTo(SqlType destType)
Converts this object to the given SqlType.
override int Compare(ISqlObject x, ISqlObject y)
Implements a BINARY object that handles a limited number of bytes, not exceding MaxLength.
BooleanType(ObjectData data)
override ISqlObject XOr(ISqlObject a, ISqlObject b)
override bool IsComparable(SqlType type)
Verifies if a given SqlType is comparable to this data-type.
static readonly SqlBoolean False
Represents the materialization of a false boolean.
ISqlObject Value
Gets the underlined value that is handled.
override ISqlObject And(ISqlObject a, ISqlObject b)
bool IsNull
Gets a boolean value indicating if the object is NULL.
static readonly SqlBoolean Null
Defines a null boolean.
Defines the contract for a valid SQL Object
override ISqlObject Reverse(ISqlObject value)
override void SerializeObject(Stream stream, ISqlObject obj)
static readonly SqlNumber Zero
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
override Type GetObjectType()
static void AssertIsBoolean(SqlTypeCode sqlType)
Defines the properties of a specific SQL Type and handles the values compatible.
override ISqlObject Negate(ISqlObject value)
static readonly SqlNumber Null
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
static readonly SqlNumber One
override bool IsCacheable(ISqlObject value)
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
override int ColumnSizeOf(ISqlObject obj)
override ISqlObject Or(ISqlObject a, ISqlObject b)
override bool CanCastTo(SqlType destType)
Verifies if this type can cast any value to the given SqlType.
override DataObject CastTo(DataObject value, SqlType destType)
Converts the given object value to a SqlType specified.
Deveel.Data.Sql.Objects.SqlString SqlString
override ISqlObject DeserializeObject(Stream stream)