示例#1
0
        public List <DcColumn> LoadSchema() // Table object is created to store all necessary parameters which are individual for each table
        {
            TableCsv        table   = this;
            List <DcColumn> columns = new List <DcColumn>();

            if (table.FilePath == null || !File.Exists(table.FilePath)) // File might not have been created (e.g., if it is an export file)
            {
                return(columns);
            }

            // TODO: We should not use connection - use TableReader/TableWriter where necessary (connection is hidden within them)
            ConnectionCsv connection = new ConnectionCsv();

            connection.OpenReader(table);

            List <string>   names      = connection.ReadColumns();
            List <string[]> sampleRows = connection.ReadSampleValues();

            for (int i = 0; i < names.Count; i++)
            {
                string    columnName = names[i];
                DcTable   type       = this.Schema.GetPrimitiveType("String");
                ColumnCsv column     = (ColumnCsv)Space.CreateColumn(DcSchemaKind.Csv, columnName, table, type, false);
                //DcColumn column = Space.CreateColumn(columnName, table, type, false);
                columns.Add(column);

                // Properties specific to this column type
                column.ColumnIndex = i;
                var values = new List <string>();
                foreach (var row in sampleRows)
                {
                    values.Add(row[i]);
                }
                column.SampleValues = values;
            }

            connection.CloseReader();

            return(columns);
        }
示例#2
0
        public ConnectionCsv connection; // Connection object for access to the native engine functions

        // Use name of the connection for setting schema name

        #endregion

        #region Schema methods

        public List <DcColumn> LoadSchema(TableCsv table) // Table object is created to store all necessary parameters which are individual for each table
        {
            List <DcColumn> columns = new List <DcColumn>();

            if (table.FilePath == null || !File.Exists(table.FilePath)) // File might not have been created (e.g., if it is an export file)
            {
                return(columns);
            }

            connection.OpenReader(table);

            List <string>   names      = connection.ReadColumns();
            List <string[]> sampleRows = connection.ReadSampleValues();

            for (int i = 0; i < names.Count; i++)
            {
                string    columnName = names[i];
                DcTable   type       = this.GetPrimitiveType("String");
                ColumnCsv column     = (ColumnCsv)Space.CreateColumn(DcSchemaKind.Csv, columnName, table, type, false);
                column.ColumnIndex = i;
                columns.Add(column);

                var values = new List <string>();
                foreach (var row in sampleRows)
                {
                    values.Add(row[i]);
                }

                column.SampleValues = values;
            }

            //AddTable(table, null, null);

            connection.CloseReader();

            return(columns);
        }