private static void DoUpdate(Table table, TypedDataSource source, SchemaNode tableSchema, RowLimitClause rowLimitClause)
        {
            table.Partitions[0].Name  = tableSchema.Name;
            table.Partitions[0].Query = tableSchema.GetSql(true, source.UseThreePartName);
            table.Partitions[0].SetAnnotation("TabularEditor_TableSchema", tableSchema.ToJson());

            var schemaTable    = source.GetSchemaTable(tableSchema);
            var updatedColumns = new HashSet <TOMWrapper.DataColumn>();

            foreach (DataRow row in schemaTable.Rows)
            {
                var sourceColumn = row["ColumnName"].ToString();
                var dataTypeName =
                    schemaTable.Columns.Contains("DataTypeName") ?
                    row["DataTypeName"].ToString() :
                    (row["DataType"] as Type).Name;
                var column = table.DataColumns.FirstOrDefault(c => c.SourceColumn.EqualsI(sourceColumn));
                if (column == null)
                {
                    column = table.AddDataColumn(sourceColumn, sourceColumn);
                }
                column.DataType           = TableMetadata.DataTypeMap(dataTypeName);
                column.SourceProviderType = dataTypeName;

                updatedColumns.Add(column);
            }
            foreach (var col in table.DataColumns.Except(updatedColumns).ToList())
            {
                col.Delete();
            }
        }
示例#2
0
        private static void DoImport(Pages.ImportMode importMode, Model model, TypedDataSource source, IEnumerable <SchemaNode> schemaNodes, RowLimitClause rowLimitClause, IdentifierQuoting identifierQuoting)
        {
            foreach (var tableSchema in schemaNodes)
            {
                var newTable = model.AddTable(tableSchema.Name);
                if (newTable.Partitions[0] is MPartition)
                {
                    Partition.CreateNew(newTable);
                    newTable.Partitions[0].Delete();
                }
                newTable.Partitions[0].Name  = tableSchema.Name;
                newTable.Partitions[0].Query = tableSchema.GetSql(identifierQuoting, true, source.UseThreePartName);
                if (source?.TabularDsName != null && model.DataSources.Contains(source.TabularDsName))
                {
                    newTable.Partitions[0].DataSource = model.DataSources[source.TabularDsName];
                }

                if (importMode != Pages.ImportMode.UseTempDs && !(source is SqlDataSource))
                {
                    newTable.SetRowLimitClause(rowLimitClause);
                    newTable.SetIdentifierQuoting(identifierQuoting);
                }

                var schemaTable = source.GetSchemaTable(tableSchema, identifierQuoting);
                foreach (DataRow row in schemaTable.Rows)
                {
                    var sourceColumn = row["ColumnName"].ToString();
                    var dataType     =
                        schemaTable.Columns.Contains("DataTypeName") ?
                        row["DataTypeName"].ToString() :
                        (row["DataType"] as Type).Name;
                    var col = newTable.AddDataColumn(
                        sourceColumn, sourceColumn,
                        null,
                        TableMetadata.DataTypeMap(dataType)
                        );
                    col.SourceProviderType = dataType;
                }
                newTable.SetTableSchema(tableSchema);
                newTable.Select();
                if (UIController.Current.TreeModel.Perspective != null)
                {
                    newTable.InPerspective[UIController.Current.TreeModel.Perspective] = true;
                }
            }
        }
        private static void DoImport(Pages.ImportMode importMode, Model model, TypedDataSource source, IEnumerable <SchemaNode> schemaNodes, RowLimitClause rowLimitClause)
        {
            foreach (var tableSchema in schemaNodes)
            {
                var newTable = model.AddTable(tableSchema.Name);
                if (newTable.Partitions[0] is MPartition)
                {
                    Partition.CreateNew(newTable);
                    newTable.Partitions[0].Delete();
                }
                newTable.Partitions[0].Name  = tableSchema.Name;
                newTable.Partitions[0].Query = tableSchema.GetSql(true, source.UseThreePartName);
                if (importMode != Pages.ImportMode.UseTempDs)
                {
                    newTable.Partitions[0].DataSource = model.DataSources[source.TabularDsName];
                    model.DataSources[source.TabularDsName].SetAnnotation("TabularEditor_RowLimitClause", ((int)rowLimitClause).ToString());
                }

                var schemaTable = source.GetSchemaTable(tableSchema);
                foreach (DataRow row in schemaTable.Rows)
                {
                    var sourceColumn = row["ColumnName"].ToString();
                    var dataType     =
                        schemaTable.Columns.Contains("DataTypeName") ?
                        row["DataTypeName"].ToString() :
                        (row["DataType"] as Type).Name;
                    var col = newTable.AddDataColumn(
                        sourceColumn, sourceColumn,
                        null,
                        TableMetadata.DataTypeMap(dataType)
                        );
                    col.SourceProviderType = dataType;
                }
                newTable.Partitions[0].SetAnnotation("TabularEditor_TableSchema", tableSchema.ToJson());
                newTable.Select();
            }
        }