Exemplo n.º 1
0
        public static string GetColumnTypeName(DmvGenerator dmvGenerator, Column col)
        {
            var columnType = "{0}";

            if (col.IsComputed)
            {
                columnType = "Computed, {0}, " + GetNullableString(col);
            }

            return(GetTypeName(dmvGenerator, col, columnType));
        }
Exemplo n.º 2
0
        private static string GetTypeName(DmvGenerator dmvGenerator, IDataType dataType, string columnFormat, bool useBaseTypeOnly = false)
        {
            var sqlType = dmvGenerator.Types.Single(x => x.SystemTypeID == dataType.SystemTypeID && x.UserTypeID == dataType.UserTypeID);

            var baseType = dmvGenerator.Types.SingleOrDefault(x => x.SystemTypeID == dataType.SystemTypeID && x.UserTypeID == dataType.SystemTypeID) ?? sqlType;

            if (useBaseTypeOnly)
            {
                sqlType = baseType;
            }

            if (sqlType.IsUserDefined)
            {
                columnFormat = sqlType.Name + "(" + columnFormat + "), " + GetNullableString(dataType);
            }
            else
            {
                columnFormat = string.Format(columnFormat, "{0}, " + GetNullableString(dataType));
            }

            switch ((SystemType)sqlType.SystemTypeID)
            {
            case SystemType.Decimal:
            case SystemType.Numeric:
                return(string.Format(columnFormat, baseType.Name + "(" + dataType.Precision + ", " + dataType.Scale + ")"));

            case SystemType.Float:
                return(string.Format(columnFormat, baseType.Name + "(" + dataType.Precision + ")"));

            case SystemType.Datetime2:
            case SystemType.DatetimeOffset:
            case SystemType.Time:
                return(string.Format(columnFormat, baseType.Name + "(" + dataType.Scale + ")"));

            case SystemType.Datetime:
            case SystemType.Bigint:
            case SystemType.Bit:
            case SystemType.Geography:
            case SystemType.Int:
            case SystemType.Date:
            case SystemType.Money:
            case SystemType.Real:
            case SystemType.Smallint:
            case SystemType.Smallmoney:
            case SystemType.Smalldatetime:
            case SystemType.Uniqueidentifier:
            case SystemType.Xml:
                return(string.Format(columnFormat, baseType.Name));

            default:
                return(string.Format(columnFormat, baseType.Name + "(" + (dataType.MaxLength == -1 ? "max" : (new[] { SystemType.Nchar, SystemType.Nvarchar }.Cast <byte>().Contains(baseType.SystemTypeID) ? dataType.MaxLength / 2 :  dataType.MaxLength).ToString()) + ")"));
            }
        }
Exemplo n.º 3
0
        private DataExtractorHelper(IReadOnlyCollection <DataColumn> sourceColumns, DmvGenerator dmvGenerator, SystemInternalsPartitionColumn[] partitionColumns, SysDefaultConstraint[] defaultConstraints)
        {
            _cachedDefaultValues = new Dictionary <int, object>();
            var newOrderedColumns = new List <DataColumn>();
            var columns           = sourceColumns.ToList();

            if (partitionColumns != null)
            {
                columns = (from pc in partitionColumns
                           join col in sourceColumns on pc.PartitionColumnID equals col.ColumnID into cols
                           from cc in cols.DefaultIfEmpty()
                           select cc ?? new DataColumn($"<<DROPPED{pc.PartitionColumnID}>>", DatabaseMetaData.GetTypeName(dmvGenerator, pc), pc.IsNullable)).ToList();

                foreach (var dataColumn in sourceColumns.Where(x => x.Type == ColumnType.Computed))
                {
                    columns.Insert(dataColumn.ColumnID - 1 ?? 0, dataColumn);
                }

                _defaultConstraints = defaultConstraints?.ToDictionary(x => x.ParentColumnId) ?? new Dictionary <int, SysDefaultConstraint>();
            }

            newOrderedColumns.AddRange(columns);

            Schema = new Schema(newOrderedColumns);

            BitColumnsCount = newOrderedColumns.Count(x => x.UnderlyingType == ColumnType.Bit);

            // Sparse columns don't have an entry in the null bitmap, thus we should only increment it if the current
            // column was not a sparse column.
            NonSparseIndexes = new Dictionary <string, int>();
            var correction = 0;
            var index      = 1;

            foreach (var dataRowColumn in newOrderedColumns)
            {
                if (dataRowColumn.UnderlyingType == ColumnType.Computed || dataRowColumn.IsSparse)
                {
                    NonSparseIndexes.Add(dataRowColumn.Name, -1);
                    ++correction;
                }
                else
                {
                    NonSparseIndexes.Add(dataRowColumn.Name, index - 1 - correction);
                }

                ++index;
            }
        }
Exemplo n.º 4
0
 public static string GetTypeName(DmvGenerator dmvGenerator, IDataType dataType, bool useBaseTypeOnly = false)
 {
     return(GetTypeName(dmvGenerator, dataType, "{0}", useBaseTypeOnly));
 }
Exemplo n.º 5
0
 public DataExtractorHelper(Row dataRow, DmvGenerator dmvGenerator, IndexColumn[] clusteredIndexColumns,
                            SystemInternalsPartitionColumn[] partitionColumns, SysDefaultConstraint[] defaultConstraints) : this(dataRow.Columns, dmvGenerator, partitionColumns, defaultConstraints)
 {
     this._dataRow = dataRow;
 }