public static BedTable ToBinaryTable(this IBedReader reader, int?maximumRecords) { //ITableStructure ts = reader.GetTableStructure(); BedTable dt = new BedTable(reader.Structure); int allow_recs = maximumRecords != null ? maximumRecords.Value : -1; while (reader.Read() && (maximumRecords == null || allow_recs > 0)) { dt.AddRow(reader); allow_recs--; } return(dt); }
public BedTable Filter(Func <BedRow, bool> filter) { BedTable res = new BedTable(m_structure); res.m_convertor = m_convertor; foreach (var row in Rows) { if (filter(row)) { res.AddRow(row); } } return(res); }
public BedTable LoadTableData(int?start, int?count, string queryInstance) { int skipcount = 0; if (start != null) { skipcount = start.Value; } string sql = queryInstance; if (m_conn.Dialect.DialectCaps.RangeSelect && (skipcount > 0 || count != null)) { sql = m_conn.Dialect.GetRangeSelect(queryInstance, skipcount, count.Value); skipcount = 0; } else if (m_conn.Dialect.DialectCaps.LimitSelect && count != null) { sql = m_conn.Dialect.GetLimitSelect(queryInstance, skipcount + count.Value); } //WantMetadata(); using (DbCommand cmd = m_conn.SystemConnection.CreateCommand()) { try { lock (m_currentCommandLock) m_currentCommand = cmd; cmd.CommandText = sql; CommandBehavior behaviour = CommandBehavior.Default; if (!HasMetaData) { behaviour |= CommandBehavior.KeyInfo; } using (IBedReader reader = m_dda.AdaptReader(cmd.ExecuteReader(behaviour))) { if (!HasMetaData) { m_structure = reader.Structure; } if (m_structure == null) { return(null); } BedTable res = new BedTable(m_structure); while (skipcount > 0) { if (!reader.Read()) { return(res); } skipcount--; } while (count == null || res.Rows.Count < count.Value) { if (!reader.Read()) { return(res); } res.AddRow(reader); } return(res); } } catch (Exception err) { err.Data["sql"] = sql; m_conn.FillInfo(err.Data); throw; } finally { lock (m_currentCommandLock) m_currentCommand = null; } } }