コード例 #1
0
    public string ToStringObsolete()
    {
        if (SqlTypes.IsCharType(TypeName))
        {
            var charLength = MaximumCharLength.HasValue && MaximumCharLength.Value > 0
                ? MaximumCharLength.Value.ToString()
                : "MAX";

            return($"{TypeName}({charLength})");
        }
        if (SqlTypes.IsApproximateNumeric(TypeName))
        {
            return(TypeName + (Mantissa.HasValue ? $"({Mantissa.Value})" : string.Empty));
        }
        if (SqlTypes.IsExactNumeric(TypeName))
        {
            if (NumericPrecision.HasValue && NumericScale.HasValue)
            {
                return($"{TypeName}({NumericPrecision},{NumericScale})");
            }
            if (NumericPrecision.HasValue)
            {
                return($"{TypeName}({NumericPrecision})");
            }
            return(TypeName);
        }
        if (SqlTypes.IsDateTime(TypeName))
        {
            return(FractionalSecondsPrecision.HasValue && SqlTypes.IsDateTimeWithPrecision(TypeName)
                ? $"{TypeName}({FractionalSecondsPrecision})"
                : TypeName);
        }
        return(TypeName);

        throw new ArgumentException($"Conversion for the type {TypeName} is not defined.");
    }
コード例 #2
0
    public static SqlType FromInformationSchemaColumn(SISColumn col)
    {
        if (SqlTypes.IsDateTime(col.DATA_TYPE))
        {
            return(SqlType.DateTime(col.DATA_TYPE, col.DATETIME_PRECISION));
        }
        if (SqlTypes.IsApproximateNumeric(col.DATA_TYPE))
        {
            if (col.DATA_TYPE == "float")
            {
                return(SqlTypeFactory.Float(col.NUMERIC_PRECISION.Value));
            }
            if (col.DATA_TYPE == "real")
            {
                return(SqlTypeFactory.Real());
            }
        }
        if (SqlTypes.IsExactNumeric(col.DATA_TYPE))
        {
            return(SqlType.ExactNumericType(col.DATA_TYPE, col.NUMERIC_PRECISION, col.NUMERIC_PRECISION_RADIX));
        }
        if (SqlTypes.IsCharType(col.DATA_TYPE))
        {
            return(SqlType.TextType(col.DATA_TYPE, col.CHARACTER_MAXIMUM_LENGTH));
        }

        if (col.DATA_TYPE.Equals("uniqueidentifier", StringComparison.InvariantCultureIgnoreCase))
        {
            return(SqlType.Type(col.DATA_TYPE));
        }
        if (col.DATA_TYPE.Equals("varbinary", StringComparison.InvariantCultureIgnoreCase))
        {
            return(SqlType.Type(col.DATA_TYPE));
        }
        throw new NotImplementedException($"Unknown type {col.DATA_TYPE}");
    }