/// <exception cref="System.IO.IOException"></exception> protected internal Index(ByteBuffer tableBuffer, IList <IndexData> indexDatas, JetFormat format) { ByteUtil.Forward(tableBuffer, format.SKIP_BEFORE_INDEX_SLOT); //Forward past Unknown _indexNumber = tableBuffer.GetInt(); int indexDataNumber = tableBuffer.GetInt(); // read foreign key reference info byte relIndexType = tableBuffer.Get(); int relIndexNumber = tableBuffer.GetInt(); int relTablePageNumber = tableBuffer.GetInt(); byte cascadeUpdatesFlag = tableBuffer.Get(); byte cascadeDeletesFlag = tableBuffer.Get(); _indexType = tableBuffer.Get(); if ((_indexType == FOREIGN_KEY_INDEX_TYPE) && (relIndexNumber != INVALID_INDEX_NUMBER )) { _reference = new Index.ForeignKeyReference(relIndexType, relIndexNumber, relTablePageNumber , (cascadeUpdatesFlag == CASCADE_UPDATES_FLAG), (cascadeDeletesFlag == CASCADE_DELETES_FLAG )); } else { _reference = null; } ByteUtil.Forward(tableBuffer, format.SKIP_AFTER_INDEX_SLOT); //Skip past Unknown _data = indexDatas[indexDataNumber]; _data.AddIndex(this); }
/// <returns> /// the Index referenced by this Index's ForeignKeyReference (if it /// has one), otherwise /// <code>null</code> /// . /// </returns> /// <exception cref="System.IO.IOException"></exception> public virtual HealthMarketScience.Jackcess.Index GetReferencedIndex() { if (_reference == null) { return(null); } Table refTable = GetTable().GetDatabase().GetTable(_reference.GetOtherTablePageNumber ()); if (refTable == null) { throw new IOException("Reference to missing table " + _reference.GetOtherTablePageNumber ()); } HealthMarketScience.Jackcess.Index refIndex = null; int idxNumber = _reference.GetOtherIndexNumber(); foreach (HealthMarketScience.Jackcess.Index idx in refTable.GetIndexes()) { if (idx.GetIndexNumber() == idxNumber) { refIndex = idx; break; } } if (refIndex == null) { throw new IOException("Reference to missing index " + idxNumber + " on table " + refTable.GetName()); } // finally verify that we found the expected index (should reference this // index) Index.ForeignKeyReference otherRef = refIndex.GetReference(); if ((otherRef == null) || (otherRef.GetOtherTablePageNumber() != GetTable().GetTableDefPageNumber ()) || (otherRef.GetOtherIndexNumber() != _indexNumber)) { throw new IOException("Found unexpected index " + refIndex.GetName() + " on table " + refTable.GetName() + " with reference " + otherRef); } return(refIndex); }