Ejemplo n.º 1
0
 public SqlType Resolve(SqlTypeResolveInfo resolveInfo)
 {
     return(ResolvePrimitive(resolveInfo));
 }
Ejemplo n.º 2
0
        private static SqlType ResolvePrimitive(SqlTypeResolveInfo resolveInfo)
        {
            if (resolveInfo == null)
            {
                throw new ArgumentNullException(nameof(resolveInfo));
            }

            if (!IsPrimitive(resolveInfo.TypeName))
            {
                return(null);
            }

            switch (resolveInfo.TypeName.ToUpperInvariant())
            {
            // Booleans
            case "BIT":
                return(Bit());

            case "BOOL":
            case "BOOLEAN":
                return(Boolean());

            // Numerics
            case "TINYINT":
                return(TinyInt());

            case "SMALLINT":
                return(SmallInt());

            case "INT":
            case "INTEGER":
                return(Integer());

            case "BIGINT":
                return(BigInt());

            case "REAL":
            case "FLOAT":
                return(Float());

            case "DOUBLE":
                return(Double());

            case "DECIMAL":
                return(Decimal());

            case "NUMBER":
            case "NUMERIC": {
                var precision = resolveInfo.Properties.GetValue <int?>("Precision");
                var scale     = resolveInfo.Properties.GetValue <int?>("Scale");

                if (precision == null)
                {
                    throw new ArgumentException("No precision specified to resolve NUMERIC");
                }
                if (scale == null)
                {
                    throw new ArgumentException("No scale specified to resolve NUMERIC");
                }

                return(Numeric(precision.Value, scale.Value));
            }

            case "NUMERIC VARYING":
            case "VARNUMERIC":
                return(VarNumeric());

            // Strings
            case "CHAR": {
                var size         = resolveInfo.Properties.GetValue <int?>("Size") ?? SqlCharacterType.DefaultMaxSize;
                var localeString = resolveInfo.Properties.GetValue <string>("Locale");
                var locale       = System.String.IsNullOrEmpty(localeString) ? null : new CultureInfo(localeString);
                return(Char(size, locale));
            }

            case "VARCHAR":
            case "CHARACTER VARYING":
            case "STRING": {
                var maxSize      = resolveInfo.Properties.GetValue <int?>("MaxSize") ?? -1;
                var localeString = resolveInfo.Properties.GetValue <string>("Locale");
                var locale       = System.String.IsNullOrEmpty(localeString) ? null : new CultureInfo(localeString);
                var typeCode     = System.String.Equals(resolveInfo.TypeName, "STRING", StringComparison.OrdinalIgnoreCase)
                                        ? SqlTypeCode.String
                                        : SqlTypeCode.VarChar;

                return(String(typeCode, maxSize, locale));
            }

            case "LONG VARCHAR":
            case "LONGVARCHAR":
            case "LONG CHARACTER VARYING":
                return(LongVarChar());

            case "TEXT":
            case "CLOB": {
                var size = resolveInfo.Properties.GetValue <int?>("Size") ?? -1;
                return(Clob(size));
            }

            // Date-Time
            case "DATE":
                return(Date());

            case "DATETIME":
                return(DateTime());

            case "TIMESTAMP":
                return(TimeStamp());

            case "TIME":
                return(Time());

            // Intervals
            case "DAY TO SECOND":
                return(DayToSecond());

            case "YEAR TO MONTH":
                return(YearToMonth());

            // Binary
            case "BINARY": {
                var size = resolveInfo.Properties.GetValue <int?>("Size") ?? SqlBinaryType.DefaultMaxSize;
                return(Binary(size));
            }

            case "VARBINARY":
            case "BINARY VARYING": {
                var size = resolveInfo.Properties.GetValue <int?>("MaxSize") ?? -1;
                return(VarBinary(size));
            }

            case "LONGVARBINARY":
            case "LONG VARBINARY":
            case "LONG BINARY VARYING":
                return(LongVarBinary());

            case "BLOB": {
                var size = resolveInfo.Properties.GetValue <int?>("Size") ?? -1;
                return(Blob(size));
            }

            default:
                return(null);
            }
        }