//-----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation.
//
//-----------------------------------------------------------------------
namespace Microsoft.Isam.Esent.Interop
{
using System;
using System.Diagnostics;
///
/// A column value.
///
public class BoolColumnValue : ColumnValueOfStruct
{
///
/// A boxed true value that can be used by ValueAsObject.
///
private static readonly object BoxedTrue = true;
///
/// A boxed false value that can be used by ValueAsObject.
///
private static readonly object BoxedFalse = false;
///
/// Gets the last set or retrieved value of the column. The
/// value is returned as a generic object.
///
public override object ValueAsObject
{
get
{
if (!this.Value.HasValue)
{
return null;
}
return this.Value.Value ? BoxedTrue : BoxedFalse;
}
}
///
/// Gets the size of the value in the column. This returns 0 for
/// variable sized columns (i.e. binary and string).
///
protected override int Size
{
[DebuggerStepThrough]
get { return sizeof(bool); }
}
///
/// Recursive SetColumns method for data pinning. This populates the buffer and
/// calls the inherited SetColumns method.
///
/// The session to use.
///
/// The table to set the columns in. An update should be prepared.
///
///
/// Column values to set.
///
///
/// Structures to put the pinned data in.
///
/// Offset of this object in the array.
/// An error code.
internal override unsafe int SetColumns(JET_SESID sesid, JET_TABLEID tableid, ColumnValue[] columnValues, NATIVE_SETCOLUMN* nativeColumns, int i)
{
byte data = this.Value.GetValueOrDefault() ? (byte)0xFF : (byte)0x00;
return this.SetColumns(sesid, tableid, columnValues, nativeColumns, i, &data, sizeof(byte), this.Value.HasValue);
}
///
/// Given data retrieved from ESENT, decode the data and set the value in the ColumnValue object.
///
/// An array of bytes.
/// The starting position within the bytes.
/// The number of bytes to decode.
/// The error returned from ESENT.
protected override void GetValueFromBytes(byte[] value, int startIndex, int count, int err)
{
if (JET_wrn.ColumnNull == (JET_wrn)err)
{
this.Value = null;
}
else
{
this.CheckDataCount(count);
this.Value = BitConverter.ToBoolean(value, startIndex);
}
}
}
}