JetMove() public static method

Navigate through an index. The cursor can be positioned at the start or end of the index and moved backwards and forwards by a specified number of index entries. Also see TryMoveFirst, TryMoveLast, TryMoveNext, TryMovePrevious.
public static JetMove ( JET_SESID sesid, JET_TABLEID tableid, JET_Move numRows, MoveGrbit grbit ) : void
sesid JET_SESID The session to use for the call.
tableid JET_TABLEID The cursor to position.
numRows JET_Move An offset which indicates how far to move the cursor.
grbit MoveGrbit Move options.
return void
コード例 #1
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);
        }
コード例 #2
0
        /// <summary>
        /// Create an array of IndexSegment objects from the data in the current JET_INDEXLIST entry.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="indexlist">The indexlist to take the data from.</param>
        /// <returns>An array of IndexSegment objects containing the information for the current index.</returns>
        private static IndexSegment[] GetIndexSegmentsFromIndexlist(JET_SESID sesid, JET_INDEXLIST indexlist)
        {
            var numSegments = (int)Api.RetrieveColumnAsInt32(sesid, indexlist.tableid, indexlist.columnidcColumn);

            Debug.Assert(numSegments > 0, "Index has zero index segments");

            var segments = new IndexSegment[numSegments];

            for (int i = 0; i < numSegments; ++i)
            {
                string columnName = Api.RetrieveColumnAsString(
                    sesid,
                    indexlist.tableid,
                    indexlist.columnidcolumnname,
                    NativeMethods.Encoding,
                    RetrieveColumnGrbit.None);
                columnName = StringCache.TryToIntern(columnName);
                var coltyp = (JET_coltyp)Api.RetrieveColumnAsInt32(sesid, indexlist.tableid, indexlist.columnidcoltyp);
                var grbit  =
                    (IndexKeyGrbit)Api.RetrieveColumnAsInt32(sesid, indexlist.tableid, indexlist.columnidgrbitColumn);
                bool isAscending = IndexKeyGrbit.Ascending == grbit;
                var  cp          = (JET_CP)Api.RetrieveColumnAsInt16(sesid, indexlist.tableid, indexlist.columnidCp);
                bool isASCII     = JET_CP.ASCII == cp;

                segments[i] = new IndexSegment(columnName, coltyp, isAscending, isASCII);

                if (i < numSegments - 1)
                {
                    Api.JetMove(sesid, indexlist.tableid, JET_Move.Next, MoveGrbit.None);
                }
            }

            return(segments);
        }
コード例 #3
0
        public IEnumerable <List <object> > GetRows(string tableName, string indexName = null, int startRow = 0, int rowCount = -1)
        {
            if (!m_tableDefs.ContainsKey(tableName))
            {
                LoadTableDef(tableName);
            }

            using (var table = new Table(m_sesid, m_dbid, tableName, OpenTableGrbit.ReadOnly)) {
                var colspec = new List <KeyValuePair <string, Type> >();

                try {
                    Esent.JetSetCurrentIndex2(m_sesid, table, indexName, SetCurrentIndexGrbit.MoveFirst);

                    if (startRow != 0)
                    {
                        Esent.JetMove(m_sesid, table, startRow, MoveGrbit.None);
                    }
                }
                catch (EsentNoCurrentRecordException) {
                    // Return an empty set.
                    yield break;
                }

                int rowNumber = 0;
                do
                {
                    var values = new List <object>();

                    object value = null;

                    foreach (var column in m_tableDefs[tableName])
                    {
                        try {
                            value = column.Retriever(m_sesid, table, column.ColumnId);
                        }
                        catch (Microsoft.Isam.Esent.Interop.EsentNoCurrentRecordException) {
                            // If we get this on row 0, it means there are no rows.
                            if (rowNumber == 0)
                            {
                                yield break;
                            }
                            else
                            {
                                throw;
                            }
                        }
                        values.Add(value);
                    }

                    yield return(values);

                    rowNumber++;
                    if (rowNumber == rowCount)
                    {
                        yield break;
                    }
                }while (Esent.TryMoveNext(m_sesid, table));
            }
        } // GetRows
コード例 #4
0
        /// <summary>
        /// Create an array of IndexSegment objects from the data in the current JET_INDEXLIST entry.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="indexlist">The indexlist to take the data from.</param>
        /// <returns>An array of IndexSegment objects containing the information for the current index.</returns>
        private static IndexSegment[] GetIndexSegmentsFromIndexlist(JET_SESID sesid, JET_INDEXLIST indexlist)
        {
            var numSegments = (int)Api.RetrieveColumnAsInt32(sesid, indexlist.tableid, indexlist.columnidcColumn);

            Debug.Assert(numSegments > 0, "Index has zero index segments");

            // If we use the wide API (Vista+), then the temp table will be in UTF-16.
            Encoding encodingOfTextColumns = EsentVersion.SupportsVistaFeatures ? Encoding.Unicode : LibraryHelpers.EncodingASCII;

            var segments = new IndexSegment[numSegments];

            for (int i = 0; i < numSegments; ++i)
            {
                string columnName = Api.RetrieveColumnAsString(
                    sesid,
                    indexlist.tableid,
                    indexlist.columnidcolumnname,
                    encodingOfTextColumns,
                    RetrieveColumnGrbit.None);
                columnName = StringCache.TryToIntern(columnName);
                var coltyp = (JET_coltyp)Api.RetrieveColumnAsInt32(sesid, indexlist.tableid, indexlist.columnidcoltyp);
                var grbit  =
                    (IndexKeyGrbit)Api.RetrieveColumnAsInt32(sesid, indexlist.tableid, indexlist.columnidgrbitColumn);
                bool isAscending = IndexKeyGrbit.Ascending == grbit;
                var  cp          = (JET_CP)Api.RetrieveColumnAsInt16(sesid, indexlist.tableid, indexlist.columnidCp);
                bool isASCII     = JET_CP.ASCII == cp;

                segments[i] = new IndexSegment(columnName, coltyp, isAscending, isASCII);

                if (i < numSegments - 1)
                {
                    Api.JetMove(sesid, indexlist.tableid, JET_Move.Next, MoveGrbit.None);
                }
            }

            return(segments);
        }