Пример #1
0
        private void ReadTableColumnData(DbDataReader reader, ref ColumnReaderState <Table> state)
        {
            var columnIndex = reader.GetInt16(2);

            if (columnIndex <= state.LastColumnIndex)
            {
                state.Owner = state.Schema.Tables[reader.GetString(1).Trim()];
            }
            state.LastColumnIndex = columnIndex;
            var column = state.Owner.CreateColumn(reader.GetString(3));

            column.DataType   = CreateValueType(reader, 4, 5, 7, 8, 9);
            column.IsNullable = ReadBool(reader, 10);
            var defaultValue = ReadStringOrNull(reader, 11);

            if (!string.IsNullOrEmpty(defaultValue))
            {
                defaultValue = defaultValue.TrimStart(' ');
                if (defaultValue.StartsWith("DEFAULT", StringComparison.OrdinalIgnoreCase))
                {
                    defaultValue = defaultValue.Substring(7).TrimStart(' ');
                }
                if (!string.IsNullOrEmpty(defaultValue))
                {
                    column.DefaultValue = SqlDml.Native(defaultValue);
                }
            }
        }
Пример #2
0
        private void ExtractViewColumns(ExtractionContext context)
        {
            using var reader = ExecuteReader(context.PerformReplacements(GetExtractViewColumnsQuery()));
            var state = new ColumnReaderState <View>(context.Catalog);

            while (reader.Read())
            {
                ReadViewColumnData(reader, ref state);
            }
        }
Пример #3
0
        private static void ReadViewColumnData(DbDataReader reader, ref ColumnReaderState <View> state)
        {
            var columnIndex = reader.GetInt16(3);

            if (columnIndex <= state.LastColumnIndex)
            {
                state.Owner = state.Schema.Views[reader.GetString(1).Trim()];
            }
            state.LastColumnIndex = columnIndex;
            _ = state.Owner.CreateColumn(reader.GetString(2).Trim());
        }
Пример #4
0
        private void ExtractViewColumns(Catalog catalog)
        {
            using var command = Connection.CreateCommand(GetExtractViewColumnsQuery());
            using var reader  = command.ExecuteReader(CommandBehavior.SingleResult);
            var readerState = new ColumnReaderState <View>(catalog.DefaultSchema);

            while (reader.Read())
            {
                ReadViewColumnData(reader, ref readerState);
            }
        }
Пример #5
0
        //---- ReadViewColumnData
        //   0      table_schema,
        //   1      table_name,
        //   2      column_name,
        //   3      ordinal_position,
        //   4      view_definition
        private static void ReadViewColumnData(DbDataReader reader, ref ColumnReaderState <View> state)
        {
            var columnIndex = ReadInt(reader, 3);

            if (columnIndex <= state.LastColumnIndex)
            {
                var schema = state.Catalog.Schemas[reader.GetString(0)];
                state.Owner = schema.Views[reader.GetString(1)];
            }

            state.Owner.CreateColumn(reader.GetString(2));
            state.LastColumnIndex = columnIndex;
        }
Пример #6
0
        private void ExtractViewColumns(ExtractionContext context)
        {
            var query = context.PerformReplacements(GetExtractViewColumnsQuery());

            using var command = Connection.CreateCommand(query);
            using var reader  = command.ExecuteReader();
            var state = new ColumnReaderState <View>(context.Catalog);

            while (reader.Read())
            {
                ReadViewColumnData(reader, ref state);
            }
        }
Пример #7
0
        private async Task ExtractViewColumnsAsync(ExtractionContext context, CancellationToken token)
        {
            var query  = context.PerformReplacements(GetExtractViewColumnsQuery());
            var reader = await ExecuteReaderAsync(query, token).ConfigureAwait(false);

            await using (reader.ConfigureAwait(false)) {
                var state = new ColumnReaderState <View>(context.Catalog);
                while (await reader.ReadAsync(token).ConfigureAwait(false))
                {
                    ReadViewColumnData(reader, ref state);
                }
            }
        }
Пример #8
0
        private async Task ExtractViewColumnsAsync(Catalog catalog, CancellationToken token)
        {
            var command = Connection.CreateCommand(GetExtractViewColumnsQuery());

            await using (command.ConfigureAwait(false)) {
                var reader = await command.ExecuteReaderAsync(CommandBehavior.SingleResult, token).ConfigureAwait(false);

                await using (reader.ConfigureAwait(false)) {
                    var readerState = new ColumnReaderState <View>(catalog.DefaultSchema);
                    while (await reader.ReadAsync(token).ConfigureAwait(false))
                    {
                        ReadViewColumnData(reader, ref readerState);
                    }
                }
            }
        }
Пример #9
0
        // ---- ReadTableColumnData
        //    0     table_schema
        //    1     table_name
        //    2     ordinal_position
        //    3     column_name
        //    4     data_type
        //    5     is_nullable
        //    6     column_type
        //    7     character_maximum_length
        //    8     numeric_precision
        //    9     numeric_scale
        //   10    collation_name
        //   11    column_key
        //   12    column_default
        //   13    Extra
        private void ReadTableColumnData(DbDataReader reader, ref ColumnReaderState <Table> state)
        {
            var columnIndex = ReadInt(reader, 2);

            if (columnIndex <= state.LastColumnIndex)
            {
                //Schema
                state.Schema = state.Catalog.Schemas[reader.GetString(0)];

                //Table
                state.Owner = state.Schema.Tables[reader.GetString(1)];
            }

            //Column
            var column = state.Owner.CreateColumn(reader.GetString(3));

            //Collation
            var collationName = ReadStringOrNull(reader, 10);

            if (!string.IsNullOrEmpty(collationName))
            {
                column.Collation = state.Schema.Collations[collationName] ?? state.Schema.CreateCollation(collationName);
            }

            //Data type
            column.DataType = CreateValueType(reader, 4, 8, 9, 7);

            //Nullable
            column.IsNullable = ReadBool(reader, 5);

            //Default
            var defaultValue = ReadStringOrNull(reader, 12);

            if (!string.IsNullOrEmpty(defaultValue))
            {
                column.DefaultValue = SqlDml.Native(defaultValue);
            }

            // AutoIncrement
            if (ReadAutoIncrement(reader, 13))
            {
                column.SequenceDescriptor = new SequenceDescriptor(column, ReadInt(reader, 14), 1);
            }

            //Column number.
            state.LastColumnIndex = columnIndex;
        }
Пример #10
0
        private async Task ExtractTableColumnsAsync(ExtractionContext context, CancellationToken token)
        {
            var query   = context.PerformReplacements(GetExtractTableColumnsQuery());
            var command = Connection.CreateCommand(query);

            await using (command.ConfigureAwait(false)) {
                var reader = await command.ExecuteReaderAsync(token).ConfigureAwait(false);

                await using (reader.ConfigureAwait(false)) {
                    var state = new ColumnReaderState <Table>(context.Catalog);
                    while (await reader.ReadAsync(token).ConfigureAwait(false))
                    {
                        ReadTableColumnData(reader, ref state);
                    }
                }
            }
        }
Пример #11
0
        private void ReadTableColumnData(DbDataReader reader, ref ColumnReaderState <Table> state)
        {
            var columnIndex = reader.GetInt16(2);

            if (columnIndex <= state.LastColumnIndex)
            {
                state.Owner = state.Schema.Tables[reader.GetString(1).Trim()];
            }
            state.LastColumnIndex = columnIndex;
            var column = state.Owner.CreateColumn(reader.GetString(3));

            column.DataType   = CreateValueType(reader, 4, 5, 7, 8, 9);
            column.IsNullable = ReadBool(reader, 10);
            var defaultValue = ReadStringOrNull(reader, 11);

            if (!string.IsNullOrEmpty(defaultValue))
            {
                column.DefaultValue = SqlDml.Native(defaultValue);
            }
        }
Пример #12
0
        private void ReadTableColumnData(DbDataReader reader, ref ColumnReaderState <Table> state)
        {
            var columnIndex = ReadInt(reader, 9);

            if (columnIndex <= state.LastColumnIndex)
            {
                var schema = state.Catalog.Schemas[reader.GetString(0)];
                state.Owner = schema.Tables[reader.GetString(1)];
            }

            var column = state.Owner.CreateColumn(reader.GetString(2));

            column.DataType   = CreateValueType(reader, 3, 4, 5, 6);
            column.IsNullable = ReadBool(reader, 7);
            var defaultValue = ReadStringOrNull(reader, 8);

            if (!string.IsNullOrEmpty(defaultValue))
            {
                column.DefaultValue = SqlDml.Native(defaultValue);
            }

            state.LastColumnIndex = columnIndex;
        }