private void DoRead(IDataQueue queue) { try { int page = 0; do { while (page < m_directory.Count) { lock (m_directory) { BinaryReader br = new BinaryReader(m_cache); m_cache.Seek(m_directory[page], SeekOrigin.Begin); ChunkInfo info = ChunkInfo.LoadInfo(br); for (int i = 0; i < info.Count; i++) { queue.PutRecord(BedTool.LoadRecord(br, m_table)); } } page++; } if (State == TabularDataViewState.Loading) { System.Threading.Thread.Sleep(100); } } while (State == TabularDataViewState.Loading); queue.PutEof(); } finally { queue.CloseWriting(); } }
internal void SaveRecord(IBedRecord rec) { long pos0 = Data.Length; BedTool.SaveRecord(rec.FieldCount, rec, m_writer); Lengths.Add((int)(Data.Length - pos0)); }
public IEnumerable <IBedRecord> EnumRows(TableDataSetProperties props) { int page = 0; do { while (page < m_directory.Count) { lock (m_directory) { BinaryReader br = new BinaryReader(m_cache); m_cache.Seek(m_directory[page], SeekOrigin.Begin); ChunkInfo info = ChunkInfo.LoadInfo(br); for (int i = 0; i < info.Count; i++) { yield return(BedTool.LoadRecord(br, m_table)); } } page++; } if (State == TabularDataViewState.Loading) { System.Threading.Thread.Sleep(100); } } while (State == TabularDataViewState.Loading); }
public void SaveToXml(XmlElement xml) { using (XmlWriter xw = xml.CreateNavigator().AppendChild()) { BedTool.SaveToXml(m_structure, Rows, xw); xw.Flush(); } }
public override void FillTable(ITableStructure table, IDataQueue queue, TableCopyOptions opts) { var name = new NameWithSchema(table.FullName.Schema, table.FullName.Name, false); var entry = m_zip.PutNextEntry(XmlTool.NormalizeIdentifier(name.ToString()) + ".drs"); BedDataStats stats = new BedDataStats(); BedTool.WriteQueueToStream(queue, m_zip, stats); ProgressInfo.LogMessage("s_export", LogLevel.Info, Texts.Get("s_exported$table$rows$bytes", "rows", stats.Rows, "bytes", stats.Bytes, "table", table.FullName)); //ZipEntry entry = new ZipEntry(XmlTool.NormalizeIdentifier(table.FullName.ToString()) + ".xml"); //m_zip.PutNextEntry(entry); //XmlTool.WriteQueueToXml(queue, m_zip, "DataSet", "DataRow"); }
public static RowType FindRow <RowType>(this IInMemoryTable <RowType> table, string[] pkcols, object[] pkvals) where RowType : class, IBedRecord { foreach (var row in table.Rows) { if (BedTool.EqualRecords(row.GetValuesByCols(pkcols), pkvals)) { return(row); } } return(null); }
public InMemoryTable(ITableStructure table, XmlElement xml) { Initialize(); m_structure = new TableStructure(table); using (XmlNodeReader xr = new XmlNodeReader(xml)) { foreach (var rec in BedTool.LoadFromXml(m_structure, xr)) { m_rows.Add(new ArrayDataRecord(rec)); } } }
public static void WriteQueueToStream(IDataQueue queue, Stream fw, BedDataStats stats) { BinaryWriter bw = new BinaryWriter(fw); bw.Write(SIGNATURE); bw.Write((int)2); // version var ts = queue.GetRowFormat; bw.Write7BitEncodedInt(ts.Columns.Count); var pk = ts.FindConstraint <IPrimaryKey>(); foreach (IColumnStructure col in ts.Columns) { bw.Write(col.ColumnName); bw.Write((byte)col.DataType.DefaultStorage); ColFlags flags = 0; if (pk != null && pk.Columns.IndexOfIf(c => c.ColumnName == col.ColumnName) >= 0) { flags |= ColFlags.ISPK; } bw.Write((byte)flags); } MemoryStream rowdata = new MemoryStream(); BinaryWriter bwrow = new BinaryWriter(rowdata); try { while (!queue.IsEof) { rowdata.Position = 0; rowdata.SetLength(0); IBedRecord row = queue.GetRecord(); BedTool.SaveRecord(ts.Columns.Count, row, bwrow); bw.Write7BitEncodedInt((int)rowdata.Length); rowdata.WriteTo(bw.BaseStream); if (stats != null) { stats.Rows++; stats.Bytes += (int)rowdata.Length; stats.Bytes += 4; } } } finally { queue.CloseReading(); } // write EOF mark bw.Write7BitEncodedInt(-1); }
public BedTable LoadTableData(TablePageProperties props) { lock (m_directory) { BedTable table = new BedTable(m_table); int start = 0; int count = m_serializedRows; if (props.Count != null) { count = props.Count.Value; } if (props.Start != null) { start = props.Start.Value; } if (start >= m_serializedRows) { return(table); } int curdic = start / BUFFER_SIZE, skiprec = start % BUFFER_SIZE; Errors.Assert(curdic < m_directory.Count); m_cache.Seek(m_directory[curdic], SeekOrigin.Begin); int availtables = m_directory.Count - curdic; BinaryReader br = new BinaryReader(m_cache); while (table.Rows.Count < count && availtables >= 1) { ChunkInfo info = ChunkInfo.LoadInfo(br); if (skiprec > 0) { int skipbytes = 0; for (int i = 0; i < skiprec; i++) { skipbytes += info.Lengths[i]; } m_cache.Seek(skipbytes, SeekOrigin.Current); } int rec = skiprec; while (rec < info.Count) { table.AddRowInternal(BedTool.LoadRecord(br, m_table)); rec++; } availtables--; skiprec = 0; } return(table); } }
private void DoReadTable(NameWithSchema table, IDataQueue queue) { try { string fnbase = XmlTool.NormalizeIdentifier(table.ToString()); ZipEntry xmlEntry; try { xmlEntry = m_zip[fnbase + ".xml"]; } catch { xmlEntry = null; } ZipEntry drsEntry; try { drsEntry = m_zip[fnbase + ".drs"]; } catch { drsEntry = null; } if (drsEntry == null && xmlEntry == null) { var dbs = GetStructure(); if (dbs.Tables.GetIndex(table) < 0) { throw new InternalError("DAE-00019 Table not found in data archive:" + table.ToString()); } // table is empty, only has no drs nor xml file queue.PutEof(); return; } using (Stream fr = (drsEntry ?? xmlEntry).OpenReader()) { if (drsEntry != null) { BedTool.LoadQueue(fr, queue); } else if (xmlEntry != null) { using (XmlReader reader = XmlReader.Create(fr, new XmlReaderSettings { CheckCharacters = false })) { XmlDataTool.ReadXmlToQueue(reader, queue, "DataRow"); } } } } finally { queue.CloseWriting(); } }
public override bool DmlfEquals(DmlfBase obj) { var o = (DmlfLiteralExpression)obj; string xtype1 = "", xdata1 = ""; string xtype2 = "", xdata2 = ""; bool b1 = BedTool.GetValueAsXml(Value, ref xtype1, ref xdata1); bool b2 = BedTool.GetValueAsXml(Value, ref xtype2, ref xdata2); if (b1 != b2) { return(false); } if (xtype1 != xtype2) { return(false); } if (xdata1 != xdata2) { return(false); } return(true); }
public override void LoadFromXml(XmlElement xml) { base.LoadFromXml(xml); Value = BedTool.LoadValueFromXml(xml); }
public override void SaveToXml(XmlElement xml) { base.SaveToXml(xml); BedTool.SaveValueToXml(Value, xml); }
public static DataScript AlterFixedData(InMemoryTable oldData, InMemoryTable newData, InMemoryTableOperation ops, DbDiffOptions opts) { if (newData == null) { return(null); } IPrimaryKey newpk = newData.Structure.FindConstraint <IPrimaryKey>(); if (newpk == null) { return(null); } string[] newcolnames = newData.Structure.Columns.GetNames(); DataScript script = new DataScript(); if (oldData == null) { foreach (var row in newData.Rows) { script.Insert(newcolnames, row.GetValues()); } } else { if (ops != null) { oldData = new InMemoryTable(oldData, ops); } IPrimaryKey oldpk = oldData.Structure.FindConstraint <IPrimaryKey>(); if (oldpk == null) { return(null); } string[] newpkcols = newpk.Columns.GetNames(); string[] oldpkcols = oldpk.Columns.GetNames(); string[] newnopkcols = newData.Structure.GetNoPkColumns().GetNames(); string[] oldnopkcols = oldData.Structure.GetNoPkColumns().GetNames(); foreach (var row in newData.Rows) { object[] newpkvals = row.GetValuesByCols(newpkcols); ArrayDataRecord oldrow = oldData.FindRow(oldpkcols, newpkvals); if (oldrow != null) { object[] oldnopkvals = oldrow.GetValuesByCols(oldnopkcols); object[] newnopkvals = row.GetValuesByCols(newnopkcols); if (BedTool.EqualRecords(oldnopkvals, newnopkvals)) { continue; } // UPDATE List <string> changedcols = new List <string>(); List <object> changedvals = new List <object>(); for (int i = 0; i < oldnopkcols.Length; i++) { if (!BedTool.EqualValues(oldnopkvals[i], newnopkvals[i])) { changedcols.Add(newnopkcols[i]); changedvals.Add(newnopkvals[i]); } } script.Update(newpkcols.ToArray(), newpkvals.ToArray(), changedcols.ToArray(), changedvals.ToArray()); } else { script.Insert(newcolnames, row.GetValues()); } } } if (script.IsEmpty()) { return(null); } return(script); }