JetSetCurrentIndex2() публичный статический Метод

Set the current index of a cursor.
public static JetSetCurrentIndex2 ( JET_SESID sesid, JET_TABLEID tableid, string index, SetCurrentIndexGrbit grbit ) : void
sesid JET_SESID The session to use.
tableid JET_TABLEID The cursor to set the index on.
index string /// The name of the index to be selected. If this is null or empty the primary /// index will be selected. ///
grbit SetCurrentIndexGrbit /// Set index options. ///
Результат void
Пример #1
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
Пример #2
0
        public int GetRowCount(string tableName, string indexName = null)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                return(0);
            }

            using (var table = new Table(m_sesid, m_dbid, tableName, OpenTableGrbit.ReadOnly)) {
                if (!string.IsNullOrEmpty(indexName))
                {
                    // This is needed because an index can be over a nullable column and exclude
                    // the nulls, resulting in fewer records than when not using the index.
                    Esent.JetSetCurrentIndex2(m_sesid, table, indexName, SetCurrentIndexGrbit.MoveFirst);
                }

                int numRecords;
                Esent.JetIndexRecordCount(m_sesid, table, out numRecords, 0);
                return(numRecords);
            }
        }