public static SqlType Convert(AmbiguousSqlType ambiguousSqlType) { var typeName = ambiguousSqlType.TypeName; return(typeName switch { "int" => SqlTypeFactory.Int(), "tinyint" => SqlTypeFactory.TinyInt(), "smallint" => SqlTypeFactory.SmallInt(), "decimal" => SqlTypeFactory.Decimal(ambiguousSqlType.NumericPrecision.Value, ambiguousSqlType.NumericScale), "numeric" => SqlTypeFactory.Numeric(ambiguousSqlType.NumericPrecision.Value, ambiguousSqlType.NumericScale), "float" => SqlTypeFactory.Float(ambiguousSqlType.NumericPrecision.Value), "real" => SqlTypeFactory.Real(), "money" => SqlTypeFactory.Money(), "smallmoney" => SqlTypeFactory.SmallMoney(), "date" => SqlTypeFactory.Date(), "time" => SqlTypeFactory.Time(), "datetime" => SqlTypeFactory.DateTime(), "datetime2" => SqlTypeFactory.DateTime2(ambiguousSqlType.FractionalSecondsPrecision), "char" => SqlTypeFactory.Char(SqlTextLengthFactory.FromAmbiguousSqlType(ambiguousSqlType)), "varchar" => SqlTypeFactory.VarChar(SqlTextLengthFactory.FromAmbiguousSqlType(ambiguousSqlType)), "nchar" => SqlTypeFactory.NChar(SqlTextLengthFactory.FromAmbiguousSqlType(ambiguousSqlType)), "nvarchar" => SqlTypeFactory.NVarChar(SqlTextLengthFactory.FromAmbiguousSqlType(ambiguousSqlType)), "xml" => SqlTypeFactory.Xml(), _ => SqlType.Type(typeName) });
private static AmbiguousSqlType FromInformationSchemaColumn(SISColumn column) { var ambigiousSqlType = new AmbiguousSqlType() { TypeName = column.DATA_TYPE, NumericPrecision = column.NUMERIC_PRECISION, NumericScale = column.NUMERIC_SCALE, FractionalSecondsPrecision = column.DATETIME_PRECISION, MaxCharacterLength = column.CHARACTER_OCTET_LENGTH, }; return(ambigiousSqlType); }
private static AmbiguousSqlType GetAmbiguousSqlType(DescribeResultSetContainer resultSetContainer) { var describeResultSetRow = resultSetContainer.DescribeResultSetRow; var userType = resultSetContainer.UserDefinedType; var systemType = resultSetContainer.SystemType; var ambigiousType = new AmbiguousSqlType() { TypeName = systemType.name, NumericPrecision = describeResultSetRow.precision, NumericScale = describeResultSetRow.scale, MaxCharacterLength = describeResultSetRow.max_length, FractionalSecondsPrecision = describeResultSetRow.scale }; if (resultSetContainer.UserDefinedType != null) { ambigiousType.MaxCharacterText = userType.max_length == -1 ? "max" : string.Empty; } return(ambigiousType); }
public static SqlTextLength FromAmbiguousSqlType(AmbiguousSqlType ambiguousSqlType) { return(new SqlTextLength(ambiguousSqlType.MaxCharacterText.InsensitiveEquals("max") ? int.MaxValue : ambiguousSqlType.MaxCharacterLength.Value)); }