//-----------------------------------------------------------------------
// 
//     Copyright (c) Microsoft Corporation.
// 
//-----------------------------------------------------------------------
namespace Microsoft.Isam.Esent.Interop
{
    /// 
    /// Enumerate columns in a table specified by a tableid.
    /// 
    internal sealed class TableidIndexInfoEnumerator : IndexInfoEnumerator
    {
        /// 
        /// The table to get the column information from.
        /// 
        private readonly JET_TABLEID tableid;
        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// 
        /// The session to use.
        /// 
        /// 
        /// The table to get column information from.
        /// 
        public TableidIndexInfoEnumerator(JET_SESID sesid, JET_TABLEID tableid)
            : base(sesid)
        {
            this.tableid = tableid;
        }
        /// 
        /// Open the table to be enumerated. This should set .
        /// 
        protected override void OpenTable()
        {
            JET_INDEXLIST indexlist;
            Api.JetGetTableIndexInfo(this.Sesid, this.tableid, string.Empty, out indexlist, JET_IdxInfo.List);
            this.Indexlist = indexlist;
            this.TableidToEnumerate = this.Indexlist.tableid;
        }
        /// 
        /// Retrieves information about indexes on a table.
        /// 
        /// The session to use.
        /// The name of the index.
        /// Filled in with information about indexes on the table.
        /// The type of information to retrieve.
        protected override void GetIndexInfo(
                JET_SESID sesid,
                string indexname,
                out string result,
                JET_IdxInfo infoLevel)
        {
            Api.JetGetTableIndexInfo(sesid, this.tableid, indexname, out result, infoLevel);
        }
    }
}