/// <summary> /// Finds all rows owned by <paramref name="key"/> in table <paramref name="tableSource"/> /// whose index is <paramref name="keyColIndex"/> /// </summary> /// <param name="tableSource">Table to search</param> /// <param name="keyColIndex">Key column index</param> /// <param name="key">Key</param> /// <returns>A <see cref="RidList"/> instance</returns> protected RidList FindAllRows(MDTable tableSource, int keyColIndex, uint key) { uint startRid = BinarySearch(tableSource, keyColIndex, key); if (tableSource.IsInvalidRID(startRid)) { return(RidList.Empty); } uint endRid = startRid + 1; var column = tableSource.TableInfo.Columns[keyColIndex]; for (; startRid > 1; startRid--) { if (!tablesStream.TryReadColumn24(tableSource, startRid - 1, column, out uint key2)) { break; // Should never happen since startRid is valid } if (key != key2) { break; } } for (; endRid <= tableSource.Rows; endRid++) { if (!tablesStream.TryReadColumn24(tableSource, endRid, column, out uint key2)) { break; // Should never happen since endRid is valid } if (key != key2) { break; } } return(RidList.Create(startRid, endRid - startRid)); }
/// <summary> /// Reads a column /// </summary> /// <param name="table">The table</param> /// <param name="rid">Row ID</param> /// <param name="column">Column</param> /// <param name="value">Result is put here or 0 if we return <c>false</c></param> /// <returns><c>true</c> if we could read the column, <c>false</c> otherwise</returns> public bool TryReadColumn(MDTable table, uint rid, ColumnInfo column, out uint value) { if (table.IsInvalidRID(rid)) { value = 0; return(false); } var cr = columnReader; if (cr != null && cr.ReadColumn(table, rid, column, out value)) { return(true); } var reader = table.DataReader; reader.Position = (rid - 1) * (uint)table.TableInfo.RowSize + (uint)column.Offset; value = column.Read(ref reader); return(true); }
internal bool TryReadColumn24(MDTable table, uint rid, ColumnInfo column, out uint value) { Debug.Assert(column.Size == 2 || column.Size == 4); if (table.IsInvalidRID(rid)) { value = 0; return(false); } var cr = columnReader; if (cr != null && cr.ReadColumn(table, rid, column, out value)) { return(true); } var reader = table.DataReader; reader.Position = (rid - 1) * (uint)table.TableInfo.RowSize + (uint)column.Offset; value = column.Size == 2 ? reader.Unsafe_ReadUInt16() : reader.Unsafe_ReadUInt32(); return(true); }