Exemplo n.º 1
0
        private InMemoryTable ChartDataToTable(ChartData data)
        {
            var ts = new TableStructure();

            ts.AddColumn(Texts.Get("s_label"), new DbTypeString());
            foreach (var item in data.ValueDefs)
            {
                ts.AddColumn(item.Label, new DbTypeFloat {
                    Bytes = 8
                });
            }
            var res = new InMemoryTable(ts);

            foreach (var item in data.Items)
            {
                var rec = new ArrayDataRecord(ts);
                rec.SeekValue(0);
                rec.SetString(item.Label);
                for (int i = 0; i < data.ValueDefs.Length; i++)
                {
                    rec.SeekValue(i + 1);
                    rec.SetDouble(item.Values[i]);
                }
                res.Rows.Add(rec);
            }
            return(res);
        }
Exemplo n.º 2
0
 public static void LoadRecord(BinaryReader fr, ArrayDataRecord record)
 {
     for (int i = 0; i < record.FieldCount; i++)
     {
         record.SeekValue(i);
         record.ReadValue(fr);
     }
 }
Exemplo n.º 3
0
        private IEnumerable <IBedRecord> EnumUpgradeGridRows(GridTable srcgrid, GridTable dstgrid, ITableStructure ts)
        {
            var ensrc  = srcgrid.EnumRows(new TableDataSetProperties()).GetEnumerator();
            var endst  = dstgrid.EnumRows(new TableDataSetProperties()).GetEnumerator();
            var holder = new BedValueHolder();

            for (; ;)
            {
                if (!ensrc.MoveNext())
                {
                    break;
                }
                if (!endst.MoveNext())
                {
                    break;
                }
                var newrec = new ArrayDataRecord(ts);

                for (int i = 0; i < m_srcInfo.KeyCols.Length; i++)
                {
                    newrec.SeekValue(i);
                    ensrc.Current.ReadValue(i);
                    ensrc.Current.WriteTo(newrec);
                }

                for (int i = 0; i < m_srcInfo.DataCols.Length; i++)
                {
                    newrec.SeekValue(m_srcInfo.KeyCols.Length + i);
                    ensrc.Current.ReadValue(m_srcInfo.KeyCols.Length + i);
                    ensrc.Current.WriteTo(newrec);
                }

                for (int i = 0; i < m_dstInfo.DataCols.Length; i++)
                {
                    newrec.SeekValue(m_srcInfo.KeyCols.Length + m_srcInfo.DataCols.Length + i);
                    endst.Current.ReadValue(m_srcInfo.KeyCols.Length + i);
                    endst.Current.WriteTo(newrec);
                }

                yield return(newrec);
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public InMemoryTable GetTable(bool wantdata)
        {
            List <DataRecord> records = new List <DataRecord>();

            foreach (string row in EnumRows())
            {
                records.Add(FieldAnalyser.AnalyseRecord(row));
            }
            var ts = new TableStructure();
            Dictionary <string, int> colindexes = new Dictionary <string, int>();

            // get column collection
            foreach (var rec in records)
            {
                foreach (var fld in rec.Fields)
                {
                    if (colindexes.ContainsKey(fld.Name))
                    {
                        continue;
                    }
                    var col = new ColumnStructure();
                    col.ColumnName       = fld.Name;
                    col.DataType         = new DbTypeString();
                    colindexes[fld.Name] = ts._Columns.Count;
                    ts._Columns.Add(col);
                }
            }
            if (!wantdata)
            {
                return(new InMemoryTable(ts));
            }
            var recs = new List <ArrayDataRecord>();

            foreach (var rec in records)
            {
                var row = new ArrayDataRecord(ts);
                foreach (var fld in rec.Fields)
                {
                    row.SeekValue(colindexes[fld.Name]);
                    row.SetString(fld.Value);
                }
                recs.Add(row);
            }
            return(InMemoryTable.FromEnumerable(ts, recs));
        }
Exemplo n.º 6
0
 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);
             }
         }
     }
 }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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,
                DisableConstraints = DisableConstraints,
            };

            var table = source.GetRowFormat(context);

            context.Info(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++;
                    }
                }
            }
        }