public void PutRecord(ICdlRecord record) { object[] values = new object[record.FieldCount]; record.GetValues(values); ICdlRecord copy = new ArrayDataRecord(Format, values); m_queue.Put(new Element { Record = copy }); }
public ICdlRecord AdaptRecord(ICdlRecord record) { var res = new ArrayDataRecord(record.Structure); for (int i = 0; i < Math.Min(res.FieldCount, record.FieldCount); i++) { var targetColumn = _columnMap.GetTargetColumnBySourceIndex(i); if (targetColumn == null) continue; record.ReadValue(i); res.SeekValue(i); _dda.AdaptValue(record, targetColumn.CommonType, res, _outputConv); } return res; }
public ICdlRecord AdaptRecord(ICdlRecord record) { var res = new ArrayDataRecord(record.Structure); for (int i = 0; i < Math.Min(res.FieldCount, record.FieldCount); i++) { var targetColumn = _columnMap.GetTargetColumnBySourceIndex(i); if (targetColumn == null) { continue; } record.ReadValue(i); res.SeekValue(i); _dda.AdaptValue(record, targetColumn.CommonType, res, _outputConv); } return(res); }
public IEnumerable<ICdlRecord> EnumRows(ArrayDataRecord record) { int page = 0; while (page < _directory.Count) { lock (_directory) { BinaryReader br = new BinaryReader(_cache); _cache.Seek(_directory[page], SeekOrigin.Begin); ChunkInfo info = ChunkInfo.LoadInfo(br); for (int i = 0; i < info.Count; i++) { if (record == null) { yield return CdlTool.LoadRecord(br, _table); } else { CdlTool.LoadRecord(br, record); yield return record; } } } page++; } }
protected override void DoRun(IShellContext context) { ITabularDataSource source; ITabularDataTarget target; if (Source != null && SourceExpression != null) throw new Exception("DBSH-00087 CopyTable: Both Source and SourceExpression are set"); if (Source == null && SourceExpression == null) throw new Exception("DBSH-00088 CopyTable: None Source and SourceExpression are set"); if (Target != null && TargetExpression != null) throw new Exception("DBSH-00089 CopyTable: Both Target and TargetExpression are set"); if (Target == null && TargetExpression == null) throw new Exception("DBSH-00090 CopyTable: None Target and TargetExpression are set"); if (SourceExpression != null) { source = (ITabularDataSource) context.Evaluate(SourceExpression); } else { source = Source; } if (TargetExpression != null) { target = (ITabularDataTarget) context.Evaluate(TargetExpression); } else { target = Target; } var options = new CopyTableTargetOptions { TruncateBeforeCopy = CleanTarget, TargetMapMode = TargetMapMode, AllowBulkCopy = AllowBulkCopy, }; var table = source.GetRowFormat(context); _log.InfoFormat("Copy table data {0}=>{1}", Source.ToStringCtx(context), Target.ToStringCtx(context)); context.OutputMessage(String.Format("Copy table data {0}=>{1}", Source.ToStringCtx(context), Target.ToStringCtx(context))); var transformedInputTable = table; var counts = new List<int>(); if (ColumnMap.Count > 0) { transformedInputTable = new TableInfo(null); foreach (var mapItem in ColumnMap) { var newCols = mapItem.GetOutputColumns(table, context); counts.Add(newCols.Length); transformedInputTable.Columns.AddRange(newCols); } } using (var reader = source.CreateReader(context)) { using (var writer = target.CreateWriter(transformedInputTable, options, context, source.GetSourceFormat(context))) { int rowNumber = 0; while (reader.Read()) { if (ColumnMap.Count > 0) { var outputRecord = new ArrayDataRecord(transformedInputTable); int columnIndex = 0; for (int i = 0; i < ColumnMap.Count; i++) { var map = ColumnMap[i]; int count = counts[i]; for (int j = 0; j < count; j++, columnIndex++) { outputRecord.SeekValue(columnIndex); map.ProcessMapping(j, rowNumber, reader, outputRecord, context); } } writer.Write(outputRecord); } else { writer.Write(reader); } rowNumber++; } } } }
public IEnumerable<ICdlRecord> EnumRows(ArrayDataRecord record, string query, int subSetColumnCount) { using (var selcmd = _conn.CreateCommand()) { selcmd.CommandText = query; using (var reader = selcmd.ExecuteReader()) { while (reader.Read()) { for (int i = 0; i < subSetColumnCount; i++) { record.SeekValue(i); var type = (TypeStorage)reader.GetInt32(i * 2); StorageTool.ReadValue(reader, i * 2 + 1, type, record); } yield return record; } } } }
//private string CreateQuery(int start = 0, int? count = null) //{ // var sb = new StringBuilder(); // sb.AppendFormat("select {0} from {1} order by rowid", ColumnsText, TABLE_NAME); // if (count != null) sb.AppendFormat(" limit {0},{1}", start, count); // return sb.ToString(); //} public CdlTable LoadTableData(string query) { var table = new CdlTable(_table); using (var selcmd = _conn.CreateCommand()) { selcmd.CommandText = query; using (var reader = selcmd.ExecuteReader()) { while (reader.Read()) { var row = new ArrayDataRecord(_table); for (int i = 0; i < _table.ColumnCount; i++) { row.SeekValue(i); var type = (TypeStorage)reader.GetInt32(i * 2); StorageTool.ReadValue(reader, i * 2 + 1, type, row); } table.AddRowInternal(row); } } } return table; }
public static void LoadRecord(BinaryReader fr, ArrayDataRecord record) { for (int i = 0; i < record.FieldCount; i++) { record.SeekValue(i); record.ReadValue(fr); } }
public static ArrayDataRecord LoadRecord(BinaryReader fr, TableInfo table) { var res = new ArrayDataRecord(table); for (int i = 0; i < table.Columns.Count; i++) { res.SeekValue(i); res.ReadValue(fr); } return res; }