private void OkCommand_Executed(object state) { DcSpace space = mainVM.Space; if (IsNew) { // Create a new table using parameters in the dialog TableCsv table = (TableCsv)space.CreateTable(DcSchemaKind.Csv, TableName, Schema.Root); table.GetData().WhereFormula = TableFormula; table.FilePath = FilePath; table.HasHeaderRecord = HasHeaderRecord; table.Delimiter = Delimiter; table.CultureInfo.NumberFormat.NumberDecimalSeparator = Decimal; // Load (read-only) column descriptions from CSV to schema //var columns = table.LoadSchema(); //var columns = ((SchemaCsv)Schema).LoadSchema(table); Table = table; } else { TableCsv table = (TableCsv)Table; table.Name = TableName; table.GetData().WhereFormula = TableFormula; table.FilePath = FilePath; table.HasHeaderRecord = HasHeaderRecord; table.Delimiter = Delimiter; table.CultureInfo.NumberFormat.NumberDecimalSeparator = Decimal; foreach (DcColumn col in table.Columns.ToArray()) { if (!col.IsSuper) { space.DeleteColumn(col); } } // Load (read-only) column descriptions from CSV to schema //var columns = table.LoadSchema(); //var columns = ((SchemaCsv)Schema).LoadSchema(table); } ((Com.Schema.Table)Table).NotifyPropertyChanged(""); this.DialogResult = true; }
public virtual DcTable CreateTable(DcSchemaKind schemaType, string name, DcTable parent) { DcSchema schema = parent.Schema; //DcSchemaKind schemaType = schema.GetSchemaKind(); DcTable table; Column column; string colName; if (parent is DcSchema) { colName = "Top"; } else { colName = "Super"; } if (schemaType == DcSchemaKind.Dc) { table = new Table(name, this); column = new Column(colName, table, parent, true, true); } else if (schemaType == DcSchemaKind.Csv) { table = new TableCsv(name, this); column = new ColumnCsv(colName, table, parent, true, true); } else if (schemaType == DcSchemaKind.Oledb) { table = new TableRel(name, this); column = new ColumnRel(colName, table, parent, true, true); } else if (schemaType == DcSchemaKind.Rel) { table = new TableRel(name, this); column = new ColumnRel(colName, table, parent, true, true); } else { throw new NotImplementedException("This schema type is not implemented."); } _tables.Add(table); NotifyAdd(table); _columns.Add(column); NotifyAdd(column); return(table); }
public void CsvReadTest() // Load Csv schema and data as a result of evaluation { DcSpace space = new Space(); // Create schema for a remote db SchemaCsv top = (SchemaCsv)space.CreateSchema("My Files", DcSchemaKind.Csv); // Create a remote file description TableCsv table = (TableCsv)space.CreateTable(DcSchemaKind.Csv, "Products", top.Root); table.FilePath = CsvRead; var columns = top.LoadSchema(table); Assert.AreEqual(1, top.Root.SubTables.Count); Assert.AreEqual(15, top.GetSubTable("Products").Columns.Count); Assert.AreEqual("String", top.GetSubTable("Products").GetColumn("Product Name").Output.Name); Assert.AreEqual("3", ((ColumnCsv)top.GetSubTable("Products").GetColumn("ID")).SampleValues[1]); // // Configure import // DcSchema schema = space.CreateSchema("My Schema", DcSchemaKind.Dc); DcTable productsTable = space.CreateTable(DcSchemaKind.Dc, "Products", schema.Root); // Manually create column to be imported (we need an automatic mechanism for appending missing columns specified in the formula) DcColumn p1 = space.CreateColumn("ID", productsTable, schema.GetPrimitiveType("Integer"), true); DcColumn p2 = space.CreateColumn("Product Code", productsTable, schema.GetPrimitiveType("String"), false); DcColumn p3 = space.CreateColumn("Custom Product Name", productsTable, schema.GetPrimitiveType("String"), false); DcColumn p4 = space.CreateColumn("List Price", productsTable, schema.GetPrimitiveType("Double"), false); DcColumn p5 = space.CreateColumn("Constant Column", productsTable, schema.GetPrimitiveType("Double"), false); // Define import column DcColumn col = space.CreateColumn("Import", top.GetSubTable("Products"), productsTable, false); col.GetData().IsAppendData = true; col.GetData().Formula = "(( [Integer] [ID] = this.[ID], [String] [Product Code] = [Product Code], [String] [Custom Product Name] = [Product Name], [Double] [List Price] = [List Price], [Double] [Constant Column] = 20.02 ))"; // Tuple structure corresponds to output table col.GetData().IsAppendData = true; col.GetData().IsAppendSchema = true; productsTable.GetData().Populate(); Assert.AreEqual(45, productsTable.GetData().Length); Assert.AreEqual("Northwind Traders Dried Pears", p3.GetData().GetValue(5)); Assert.AreEqual(20.02, p5.GetData().GetValue(5)); }
public void CsvWriteTest() // Store schema and data to a CSV file as a result of evaluation { DcSpace space = new Space(); DcSchema schema = space.CreateSchema("My Schema", DcSchemaKind.Dc); CoreTest.CreateSampleSchema(schema); CoreTest.CreateSampleData(schema); DcTable t2 = schema.GetSubTable("Table 2"); DcColumn c21 = t2.GetColumn("Column 21"); DcColumn c22 = t2.GetColumn("Column 22"); DcColumn c23 = t2.GetColumn("Column 23"); // // Create schema for a remote db // SchemaCsv top = (SchemaCsv)space.CreateSchema("My Files", DcSchemaKind.Csv); // Create a remote file description TableCsv table = (TableCsv)space.CreateTable(DcSchemaKind.Csv, "Table_1", top.Root); table.FilePath = CsvWrite; // Manually create column to be imported (we need an automatic mechanism for appending missing columns specified in the formula) DcColumn p1 = space.CreateColumn("Column 11", table, top.GetPrimitiveType("String"), true); DcColumn p2 = space.CreateColumn("Column 12", table, top.GetPrimitiveType("String"), true); DcColumn p3 = space.CreateColumn("Custom Column 13", table, top.GetPrimitiveType("String"), true); DcColumn p4 = space.CreateColumn("Constant Column", table, top.GetPrimitiveType("String"), true); // Define export column DcColumn col = space.CreateColumn("Export", schema.GetSubTable("Table 1"), table, false); col.GetData().IsAppendData = true; col.GetData().Formula = "(( [String] [Column 11] = this.[Column 11], [String] [Column 12] = [Column 12], [String] [Custom Column 13] = [Column 13], [String] [Constant Column] = 20.02 ))"; // Tuple structure corresponds to output table col.GetData().IsAppendData = true; col.GetData().IsAppendSchema = true; table.Populate(); }