JetCloseTable() public static method

Close an open table.
public static JetCloseTable ( JET_SESID sesid, JET_TABLEID tableid ) : void
sesid JET_SESID The session which opened the table.
tableid JET_TABLEID The table to close.
return void
Exemplo n.º 1
0
        /// <summary>
        /// Intersect a group of index ranges and return the bookmarks of the records which are found
        /// in all the index ranges.
        /// Also see <see cref="JetIntersectIndexes"/>.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableids">
        /// The tableids to use. Each tableid must be from a different index on the same table and
        /// have an active index range. Use <see cref="JetSetIndexRange"/>
        /// to create an index range.
        /// </param>
        /// <returns>
        /// The bookmarks of the records which are found in all the index ranges. The bookmarks
        /// are returned in primary key order.
        /// </returns>
        public static IEnumerable <byte[]> IntersectIndexes(JET_SESID sesid, params JET_TABLEID[] tableids)
        {
            if (null == tableids)
            {
                throw new ArgumentNullException("tableids");
            }

            JET_RECORDLIST recordlist;

            var ranges = new JET_INDEXRANGE[tableids.Length];

            for (int i = 0; i < tableids.Length; ++i)
            {
                ranges[i] = new JET_INDEXRANGE {
                    tableid = tableids[i]
                };
            }

            Api.JetIntersectIndexes(sesid, ranges, ranges.Length, out recordlist, IntersectIndexesGrbit.None);

            try
            {
                if (Api.TryMoveFirst(sesid, recordlist.tableid))
                {
                    do
                    {
                        yield return(Api.RetrieveColumn(sesid, recordlist.tableid, recordlist.columnidBookmark));
                    }while (Api.TryMoveNext(sesid, recordlist.tableid));
                }
            }
            finally
            {
                Api.JetCloseTable(sesid, recordlist.tableid);
            }
        }
Exemplo n.º 2
0
        public IEnumerable <DBRow> GetIndexInfo(string tableName, string indexName)
        {
            IEnumerable <ColSpec> tableDef = GetIndexTableDef(tableName, indexName);

            JET_INDEXLIST indexList;

            Esent.JetGetIndexInfo(m_sesid, m_dbid, tableName, indexName, out indexList, JET_IdxInfo.List);

            var columnsByName = new Dictionary <string, int>();
            int i             = 0;

            foreach (ColSpec column in tableDef)
            {
                columnsByName.Add(column.Name, i++);
            }

            Esent.JetMove(m_sesid, indexList.tableid, JET_Move.First, MoveGrbit.None);

            i = 0;
            do
            {
                var row = new List <object>();

                foreach (ColSpec column in tableDef)
                {
                    row.Add(column.Retriever(m_sesid, indexList.tableid, column.ColumnId));
                }

                yield return(new DBRow(columnsByName, row, i++));
            }while (Esent.TryMoveNext(m_sesid, indexList.tableid));

            Esent.JetCloseTable(m_sesid, indexList.tableid);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Closes the table being enumerated.
        /// </summary>
        protected virtual void CloseTable()
        {
            if (JET_TABLEID.Nil != this.TableidToEnumerate)
            {
                Api.JetCloseTable(this.Sesid, this.TableidToEnumerate);
            }

            this.TableidToEnumerate = JET_TABLEID.Nil;
        }
Exemplo n.º 4
0
        private IEnumerable <ColSpec> GetIndexTableDef(string tableName, string indexName)
        {
            JET_INDEXLIST indexList;

            Esent.JetGetIndexInfo(m_sesid, m_dbid, tableName, indexName, out indexList, JET_IdxInfo.List);

            // Unfortunately, Esent.GetTableColumns doesn't work on the temporary table returned by
            // JetGetIndexInfo, but the JET_INDEXLIST and the documentation have all the
            // information we need.
            var tableDef = new ColSpec[] {
                new ColSpec
                {
                    Name     = "Columns",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidcColumn
                },
                new ColSpec
                {
                    Name     = "Entries",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidcEntry
                },
                new ColSpec
                {
                    Name     = "UniqueKeys",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidcKey
                },
                new ColSpec {
                    Name     = "Coltyp",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidcoltyp
                },
                new ColSpec {
                    Name     = "ColumnId",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidcolumnid
                },
                new ColSpec {
                    Name     = "ColumnName",
                    Type     = typeof(string),
                    ColumnId = indexList.columnidcolumnname
                },
                new ColSpec {
                    Name     = "CodePage",
                    Type     = typeof(Int16?),
                    ColumnId = indexList.columnidCp
                },
                new ColSpec {
                    Name     = "NumPages",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidcPage
                },
                new ColSpec {
                    Name     = "grbitColumn",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidgrbitColumn
                },
                new ColSpec {
                    Name     = "grbitIndex",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidgrbitIndex
                },
                new ColSpec {
                    Name     = "iColumn",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidiColumn
                },
                new ColSpec {
                    Name     = "IndexName",
                    Type     = typeof(string),
                    ColumnId = indexList.columnidindexname
                },
                new ColSpec {
                    Name     = "LangId",
                    Type     = typeof(Int16?),
                    ColumnId = indexList.columnidLangid
                },
                new ColSpec {
                    Name     = "LCMapFlags",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidLCMapFlags
                }
            };

            for (int i = 0, n = tableDef.Length; i < n; i++)
            {
                tableDef[i].Retriever = ColumnRetrievers.ForType(tableDef[i].Type);
            }

            Esent.JetCloseTable(m_sesid, indexList.tableid);

            return(tableDef);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Called when the object is being disposed or finalized.
 /// </summary>
 /// <param name="disposing">True if the function was called from Dispose.</param>
 protected virtual void Dispose(bool disposing)
 {
     Api.JetCloseTable(this.sesid, this.tableid);
 }