//-----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation.
//
//-----------------------------------------------------------------------
namespace Microsoft.Isam.Esent.Interop
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
///
/// The native version of the structure.
///
[StructLayout(LayoutKind.Sequential)]
[SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules",
"SA1305:FieldNamesMustNotUseHungarianNotation",
Justification = "This should match the unmanaged API, which isn't capitalized.")]
[SuppressMessage(
"Microsoft.StyleCop.CSharp.NamingRules",
"SA1307:AccessibleFieldsMustBeginWithUpperCaseLetter",
Justification = "This should match the unmanaged API, which isn't capitalized.")]
internal struct NATIVE_RETRIEVECOLUMN
{
///
/// The column identifier for the column to retrieve.
///
public uint columnid;
///
/// A pointer to begin storing data that is retrieved from the
/// column value.
///
public IntPtr pvData;
///
/// The size of allocation beginning at pvData, in bytes. The
/// retrieve column operation will not store more data at pvData
/// than cbData.
///
public uint cbData;
///
/// The size, in bytes, of data that is retrieved by a retrieve
/// column operation.
///
public uint cbActual;
///
/// A group of bits that contain the options for column retrieval.
///
public uint grbit;
///
/// The offset to the first byte to be retrieved from a column of
/// type or
/// .
///
public uint ibLongValue;
///
/// The sequence number of the values that are contained in a
/// multi-valued column. If the itagSequence is 0 then the number
/// of instances of a multi-valued column are returned instead of
/// any column data.
///
public uint itagSequence;
///
/// The columnid of the tagged, multi-valued, or sparse column
/// when all tagged columns are retrieved by passing 0 as the
/// columnid.
///
public uint columnidNextTagged;
///
/// Error codes and warnings returned from the retrieval of the column.
///
public int err;
}
///
/// Contains input and output parameters for .
/// Fields in the structure describe what column value to retrieve, how to
/// retrieve it, and where to save results.
///
[SuppressMessage(
"Microsoft.StyleCop.CSharp.NamingRules",
"SA1300:ElementMustBeginWithUpperCaseLetter",
Justification = "This should match the unmanaged API, which isn't capitalized.")]
public class JET_RETRIEVECOLUMN
{
///
/// Gets or sets the column identifier for the column to retrieve.
///
public JET_COLUMNID columnid { get; set; }
///
/// Gets or sets the buffer that will store data that is retrieved from the
/// column.
///
public byte[] pvData { get; set; }
///
/// Gets or sets the offset in the buffer that data will be stored in.
///
public int ibData { get; set; }
///
/// Gets or sets the size of the buffer, in bytes. The
/// retrieve column operation will not store more data in pvData
/// than cbData.
///
public int cbData { get; set; }
///
/// Gets the size, in bytes, of data that is retrieved by a retrieve
/// column operation.
///
public int cbActual { get; private set; }
///
/// Gets or sets the options for column retrieval.
///
public RetrieveColumnGrbit grbit { get; set; }
///
/// Gets or sets the offset to the first byte to be retrieved from a column of
/// type or
/// .
///
public int ibLongValue { get; set; }
///
/// Gets or sets the sequence number of the values that are contained in a
/// multi-valued column. If the itagSequence is 0 then the number
/// of instances of a multi-valued column are returned instead of
/// any column data.
///
public int itagSequence { get; set; }
///
/// Gets the columnid of the tagged, multi-valued, or sparse column
/// when all tagged columns are retrieved by passing 0 as the
/// columnid.
///
public JET_COLUMNID columnidNextTagged { get; private set; }
///
/// Gets the warning returned from the retrieval of the column.
///
public JET_wrn err { get; private set; }
///
/// Returns a that represents the current .
///
///
/// A that represents the current .
///
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "JET_RETRIEVECOLUMN(0x{0:x})", this.columnid);
}
///
/// Check to see if cbData is negative or greater than cbData.
///
internal void CheckDataSize()
{
if (this.cbData < 0)
{
throw new ArgumentOutOfRangeException("cbData", this.cbData, "data length cannot be negative");
}
if (this.ibData < 0)
{
throw new ArgumentOutOfRangeException("ibData", this.cbData, "data offset cannot be negative");
}
if (0 != this.ibData && (null == this.pvData || this.ibData >= this.pvData.Length))
{
throw new ArgumentOutOfRangeException(
"ibData",
this.ibData,
"cannot be greater than the length of the pvData buffer");
}
if ((null == this.pvData && 0 != this.cbData) || (null != this.pvData && this.cbData > (this.pvData.Length - this.ibData)))
{
throw new ArgumentOutOfRangeException(
"cbData",
this.cbData,
"cannot be greater than the length of the pvData buffer");
}
}
///
/// Gets the NATIVE_RETRIEVECOLUMN structure that represents the object.
///
/// The NATIVE_RETRIEVECOLUMN structure to fill in.
///
/// This takes a reference because a NATIVE_RETRIEVECOLUMN is quite large (40 bytes)
/// so copying it around can be expensive.
///
internal void GetNativeRetrievecolumn(ref NATIVE_RETRIEVECOLUMN retrievecolumn)
{
retrievecolumn.columnid = this.columnid.Value;
retrievecolumn.cbData = unchecked((uint)this.cbData); // guaranteed to not be negative
retrievecolumn.grbit = (uint)this.grbit;
retrievecolumn.ibLongValue = checked((uint)this.ibLongValue);
retrievecolumn.itagSequence = checked((uint)this.itagSequence);
}
///
/// Update the output members of the class from a NATIVE_RETRIEVECOLUMN
/// structure. This should be done after the columns are retrieved.
///
///
/// The structure containing the updated output fields.
///
///
/// This takes a reference because a NATIVE_RETRIEVECOLUMN is quite large (40 bytes)
/// so copying it around can be expensive.
///
internal void UpdateFromNativeRetrievecolumn(ref NATIVE_RETRIEVECOLUMN native)
{
this.cbActual = checked((int)native.cbActual);
this.columnidNextTagged = new JET_COLUMNID { Value = native.columnidNextTagged };
this.itagSequence = checked((int)native.itagSequence);
this.err = (JET_wrn)native.err;
}
}
}