/// <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));
        }
Example #2
0
        /// <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 ReadColumn(MDTable table, uint rid, ColumnInfo column, out uint value)
        {
            if (table == null || table.IsInvalidRID(rid))
            {
                value = 0;
                return(false);
            }
            var cr = columnReader;

            if (cr != null && cr.ReadColumn(table, rid, column, out value))
            {
                return(true);
            }
#if THREAD_SAFE
            theLock.EnterWriteLock(); try {
#endif
            var reader = GetReader_NoLock(table, rid);
            reader.Position += column.Offset;
            value            = column.Read(reader);
#if THREAD_SAFE
        }

        finally { theLock.ExitWriteLock(); }
#endif
            return(true);
        }
Example #3
0
        /// <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)
        {
#if THREAD_SAFE
            tablesStream.theLock.EnterWriteLock(); try {
#endif
            uint startRid = BinarySearch_NoLock(tableSource, keyColIndex, key);
            if (tableSource.IsInvalidRID(startRid))
            {
                return(RidList.Empty);
            }
            uint endRid = startRid + 1;
            var column  = tableSource.TableInfo.Columns[keyColIndex];
            for (; startRid > 1; startRid--)
            {
                uint key2;
                if (!tablesStream.ReadColumn_NoLock(tableSource, startRid - 1, column, out key2))
                {
                    break;                      // Should never happen since startRid is valid
                }
                if (key != key2)
                {
                    break;
                }
            }
            for (; endRid <= tableSource.Rows; endRid++)
            {
                uint key2;
                if (!tablesStream.ReadColumn_NoLock(tableSource, endRid, column, out key2))
                {
                    break;                      // Should never happen since endRid is valid
                }
                if (key != key2)
                {
                    break;
                }
            }
            return(new ContiguousRidList(startRid, endRid - startRid));

#if THREAD_SAFE
        }

        finally { tablesStream.theLock.ExitWriteLock(); }
#endif
        }
Example #4
0
        /// <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);
        }
Example #5
0
        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);
        }
Example #6
0
        /// <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 == null || tableSource.IsInvalidRID(startRid))
            {
                return(ContiguousRidList.Empty);
            }
            uint endRid = startRid + 1;

            for (; startRid > 1; startRid--)
            {
                uint key2;
                if (!tablesStream.ReadColumn(tableSource, startRid - 1, keyColIndex, out key2))
                {
                    break;                      // Should never happen since startRid is valid
                }
                if (key != key2)
                {
                    break;
                }
            }
            for (; endRid <= tableSource.Rows; endRid++)
            {
                uint key2;
                if (!tablesStream.ReadColumn(tableSource, endRid, keyColIndex, out key2))
                {
                    break;                      // Should never happen since endRid is valid
                }
                if (key != key2)
                {
                    break;
                }
            }
            return(new ContiguousRidList(startRid, endRid - startRid));
        }
Example #7
0
 /// <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)
 {
     #if THREAD_SAFE
     tablesStream.theLock.EnterWriteLock(); try {
     #endif
     uint startRid = BinarySearch_NoLock(tableSource, keyColIndex, key);
     if (tableSource.IsInvalidRID(startRid))
         return RidList.Empty;
     uint endRid = startRid + 1;
     var column = tableSource.TableInfo.Columns[keyColIndex];
     for (; startRid > 1; startRid--) {
         uint key2;
         if (!tablesStream.ReadColumn_NoLock(tableSource, startRid - 1, column, out key2))
             break;	// Should never happen since startRid is valid
         if (key != key2)
             break;
     }
     for (; endRid <= tableSource.Rows; endRid++) {
         uint key2;
         if (!tablesStream.ReadColumn_NoLock(tableSource, endRid, column, out key2))
             break;	// Should never happen since endRid is valid
         if (key != key2)
             break;
     }
     return new ContiguousRidList(startRid, endRid - startRid);
     #if THREAD_SAFE
     } finally { tablesStream.theLock.ExitWriteLock(); }
     #endif
 }
		/// <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 == null || tableSource.IsInvalidRID(startRid))
				return RidList.Empty;
			uint endRid = startRid + 1;
			for (; startRid > 1; startRid--) {
				uint key2;
				if (!tablesStream.ReadColumn(tableSource, startRid - 1, keyColIndex, out key2))
					break;	// Should never happen since startRid is valid
				if (key != key2)
					break;
			}
			for (; endRid <= tableSource.Rows; endRid++) {
				uint key2;
				if (!tablesStream.ReadColumn(tableSource, endRid, keyColIndex, out key2))
					break;	// Should never happen since endRid is valid
				if (key != key2)
					break;
			}
			return new ContiguousRidList(startRid, endRid - startRid);
		}
Example #9
0
		/// <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>
		internal bool ReadColumn_NoLock(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 = GetReader_NoLock(table, rid);
			reader.Position += column.Offset;
			value = column.Read(reader);
			return true;
		}
Example #10
0
		/// <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 ReadColumn(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;
#if THREAD_SAFE
			theLock.EnterWriteLock(); try {
#endif
			var reader = GetReader_NoLock(table, rid);
			reader.Position += column.Offset;
			value = column.Read(reader);
#if THREAD_SAFE
			} finally { theLock.ExitWriteLock(); }
#endif
			return true;
		}