コード例 #1
0
        public static SqlType Resolve(SqlTypeCode typeCode, string typeName, DataTypeMeta[] metadata, ITypeResolver resolver)
        {
            if (PrimitiveTypes.IsPrimitive(typeCode))
                return PrimitiveTypes.Resolve(typeCode, typeName, metadata);

            if (resolver == null)
                throw new NotSupportedException(String.Format("Cannot resolve type '{0}' without context.", typeName));

            var resolveCcontext = new TypeResolveContext(typeCode, typeName, metadata);
            return resolver.ResolveType(resolveCcontext);
        }
コード例 #2
0
ファイル: TypeManager.cs プロジェクト: meikeric/deveeldb
        SqlType ITypeResolver.ResolveType(TypeResolveContext context)
        {
            var fullTypeName = Transaction.ResolveObjectName(context.TypeName);

            if (fullTypeName == null)
            {
                return(null);
            }

            return(GetUserType(fullTypeName));
        }
コード例 #3
0
        public static SqlType ResolveType(this ISystemContext context, string typeName, params DataTypeMeta[] meta)
        {
            var resolvers = context.ResolveAllServices<ITypeResolver>();
            var resolveContext = new TypeResolveContext(SqlTypeCode.Type, typeName, meta);
            foreach (var typeResolver in resolvers) {
                var type = typeResolver.ResolveType(resolveContext);
                if (type != null)
                    return type;
            }

            return null;
        }
コード例 #4
0
        public SqlType ResolveType(TypeResolveContext context)
        {
            try {
                var srid = -1;
                if (context.HasMeta("SRID")) {
                    var sridMeta = context.GetMeta("SRID");
                    srid = Convert.ToInt32(sridMeta.ToInt32());
                }

                return new SpatialType(srid);
            } catch (Exception) {
                return null;
            }
        }
コード例 #5
0
        public static SqlType Resolve(SqlTypeCode typeCode, string typeName, DataTypeMeta[] metadata, ITypeResolver resolver)
        {
            if (PrimitiveTypes.IsPrimitive(typeCode))
            {
                return(PrimitiveTypes.Resolve(typeCode, typeName, metadata));
            }

            if (resolver == null)
            {
                throw new NotSupportedException(String.Format("Cannot resolve type '{0}' without context.", typeName));
            }

            var resolveCcontext = new TypeResolveContext(typeCode, typeName, metadata);

            return(resolver.ResolveType(resolveCcontext));
        }
コード例 #6
0
        public static SqlType ResolveType(this ISystemContext context, string typeName, params DataTypeMeta[] meta)
        {
            var resolvers      = context.ResolveAllServices <ITypeResolver>();
            var resolveContext = new TypeResolveContext(SqlTypeCode.Type, typeName, meta);

            foreach (var typeResolver in resolvers)
            {
                var type = typeResolver.ResolveType(resolveContext);
                if (type != null)
                {
                    return(type);
                }
            }

            return(null);
        }
コード例 #7
0
ファイル: PrimitiveTypes.cs プロジェクト: furesoft/deveeldb
        public static SqlType Resolve(TypeResolveContext context)
        {
            if (!context.IsPrimitive)
                return null;

            var sqlType = context.TypeCode;

            if (sqlType == SqlTypeCode.BigInt ||
                sqlType == SqlTypeCode.Boolean)
                return Boolean(sqlType);

            if (sqlType == SqlTypeCode.Numeric ||
                sqlType == SqlTypeCode.TinyInt ||
                sqlType == SqlTypeCode.SmallInt ||
                sqlType == SqlTypeCode.Integer ||
                sqlType == SqlTypeCode.BigInt ||
                sqlType == SqlTypeCode.Real ||
                sqlType == SqlTypeCode.Double ||
                sqlType == SqlTypeCode.Float ||
                sqlType == SqlTypeCode.Decimal) {
                if (!context.HasAnyMeta)
                    return Numeric(sqlType);

                var precisionMeta = context.GetMeta("Precision");
                var scaleMeta = context.GetMeta("Scale");

                if (precisionMeta == null)
                    return Numeric(sqlType);

                if (scaleMeta == null)
                    return Numeric(sqlType, precisionMeta.ToInt32());

                return Numeric(sqlType, precisionMeta.ToInt32(), (byte) scaleMeta.ToInt32());
            }

            if (sqlType == SqlTypeCode.Char ||
                sqlType == SqlTypeCode.VarChar ||
                sqlType == SqlTypeCode.LongVarChar ||
                sqlType == SqlTypeCode.String ||
                sqlType == SqlTypeCode.Clob) {
                if (!context.HasAnyMeta)
                    return String(sqlType);

                var maxSizeMeta = context.GetMeta("MaxSize");
                var localeMeta = context.GetMeta("Locale");
                var encodingMeta = context.GetMeta("Encoding");

                int maxSize = StringType.DefaultMaxSize;
                CultureInfo locale = null;
                var encoding = Encoding.Unicode;

                if (maxSizeMeta != null)
                    maxSize = maxSizeMeta.ToInt32();
                if (localeMeta != null)
                    locale = new CultureInfo(localeMeta.Value);
                if (encodingMeta != null)
                    encoding = Encoding.GetEncoding(encodingMeta.Value);

                return new StringType(sqlType, maxSize, encoding, locale);
            }

            if (sqlType == SqlTypeCode.Binary ||
                sqlType == SqlTypeCode.VarBinary ||
                sqlType == SqlTypeCode.LongVarBinary ||
                sqlType == SqlTypeCode.Blob) {
                if (!context.HasAnyMeta)
                    return Binary(sqlType);

                var maxSize = BinaryType.DefaultMaxSize;
                var maxSizeMeta = context.GetMeta("MaxSize");
                if (maxSizeMeta != null)
                    maxSize = maxSizeMeta.ToInt32();

                return Binary(sqlType, maxSize);
            }

            if (sqlType == SqlTypeCode.Date ||
                sqlType == SqlTypeCode.Time ||
                sqlType == SqlTypeCode.TimeStamp ||
                sqlType == SqlTypeCode.DateTime)
                return DateTime(sqlType);

            if (sqlType == SqlTypeCode.Null)
                return Null(sqlType);

            if (sqlType == SqlTypeCode.RowType) {
                if (!context.HasAnyMeta)
                    throw new ArgumentException("Invalid number of arguments for %ROWTYPE type");

                var tableNameMeta = context.GetMeta("TableName");
                if (tableNameMeta == null)
                    throw new ArgumentException();

                var tableName = ObjectName.Parse(tableNameMeta.Value);
                return RowType(tableName);
            }

            if (sqlType == SqlTypeCode.ColumnType) {
                if (!context.HasAnyMeta)
                    throw new ArgumentException("Invalid number of arguments for %TYPE type");

                var columnNameMeta = context.GetMeta("ColumnName");
                if (columnNameMeta == null)
                    throw new ArgumentException();

                var columnName = ObjectName.Parse(columnNameMeta.Value);
                return ColumnType(columnName);
            }

            throw new ArgumentException(System.String.Format("The SQL type {0} is not primitive.", sqlType));
        }
コード例 #8
0
ファイル: XmlTypeResolver.cs プロジェクト: prepare/deveeldb
 public DataType ResolveType(TypeResolveContext context)
 {
     if (String.Equals(context.TypeName, "XMLNODE", StringComparison.OrdinalIgnoreCase))
         return new XmlNodeType();
     return null;
 }
コード例 #9
0
ファイル: PrimitiveTypes.cs プロジェクト: meikeric/deveeldb
        public static SqlType Resolve(TypeResolveContext context)
        {
            if (!context.IsPrimitive)
            {
                return(null);
            }

            var sqlType = context.TypeCode;

            if (sqlType == SqlTypeCode.BigInt ||
                sqlType == SqlTypeCode.Boolean)
            {
                return(Boolean(sqlType));
            }

            if (sqlType == SqlTypeCode.Numeric ||
                sqlType == SqlTypeCode.TinyInt ||
                sqlType == SqlTypeCode.SmallInt ||
                sqlType == SqlTypeCode.Integer ||
                sqlType == SqlTypeCode.BigInt ||
                sqlType == SqlTypeCode.Real ||
                sqlType == SqlTypeCode.Double ||
                sqlType == SqlTypeCode.Float ||
                sqlType == SqlTypeCode.Decimal)
            {
                if (!context.HasAnyMeta)
                {
                    return(Numeric(sqlType));
                }

                var precisionMeta = context.GetMeta("Precision");
                var scaleMeta     = context.GetMeta("Scale");

                if (precisionMeta == null)
                {
                    return(Numeric(sqlType));
                }

                if (scaleMeta == null)
                {
                    return(Numeric(sqlType, precisionMeta.ToInt32()));
                }

                return(Numeric(sqlType, precisionMeta.ToInt32(), (byte)scaleMeta.ToInt32()));
            }

            if (sqlType == SqlTypeCode.Char ||
                sqlType == SqlTypeCode.VarChar ||
                sqlType == SqlTypeCode.LongVarChar ||
                sqlType == SqlTypeCode.String ||
                sqlType == SqlTypeCode.Clob)
            {
                if (!context.HasAnyMeta)
                {
                    return(String(sqlType));
                }

                var maxSizeMeta  = context.GetMeta("MaxSize");
                var localeMeta   = context.GetMeta("Locale");
                var encodingMeta = context.GetMeta("Encoding");

                int         maxSize  = StringType.DefaultMaxSize;
                CultureInfo locale   = null;
                var         encoding = Encoding.Unicode;

                if (maxSizeMeta != null)
                {
                    maxSize = maxSizeMeta.ToInt32();
                }
                if (localeMeta != null)
                {
                    locale = new CultureInfo(localeMeta.Value);
                }
                if (encodingMeta != null)
                {
                    encoding = Encoding.GetEncoding(encodingMeta.Value);
                }

                return(new StringType(sqlType, maxSize, encoding, locale));
            }

            if (sqlType == SqlTypeCode.Binary ||
                sqlType == SqlTypeCode.VarBinary ||
                sqlType == SqlTypeCode.LongVarBinary ||
                sqlType == SqlTypeCode.Blob)
            {
                if (!context.HasAnyMeta)
                {
                    return(Binary(sqlType));
                }

                var maxSize     = BinaryType.DefaultMaxSize;
                var maxSizeMeta = context.GetMeta("MaxSize");
                if (maxSizeMeta != null)
                {
                    maxSize = maxSizeMeta.ToInt32();
                }

                return(Binary(sqlType, maxSize));
            }

            if (sqlType == SqlTypeCode.Date ||
                sqlType == SqlTypeCode.Time ||
                sqlType == SqlTypeCode.TimeStamp ||
                sqlType == SqlTypeCode.DateTime)
            {
                return(DateTime(sqlType));
            }

            if (sqlType == SqlTypeCode.Null)
            {
                return(Null(sqlType));
            }

            if (sqlType == SqlTypeCode.RowType)
            {
                if (!context.HasAnyMeta)
                {
                    throw new ArgumentException("Invalid number of arguments for %ROWTYPE type");
                }

                var tableNameMeta = context.GetMeta("TableName");
                if (tableNameMeta == null)
                {
                    throw new ArgumentException();
                }

                var tableName = ObjectName.Parse(tableNameMeta.Value);
                return(RowType(tableName));
            }

            if (sqlType == SqlTypeCode.ColumnType)
            {
                if (!context.HasAnyMeta)
                {
                    throw new ArgumentException("Invalid number of arguments for %TYPE type");
                }

                var columnNameMeta = context.GetMeta("ColumnName");
                if (columnNameMeta == null)
                {
                    throw new ArgumentException();
                }

                var columnName = ObjectName.Parse(columnNameMeta.Value);
                return(ColumnType(columnName));
            }

            throw new ArgumentException(System.String.Format("The SQL type {0} is not primitive.", sqlType));
        }
コード例 #10
0
 public DataType ResolveType(TypeResolveContext context)
 {
     return queryContext.ResolveType(context.TypeName, context.GetMeta());
 }
コード例 #11
0
 public SqlType ResolveType(TypeResolveContext context)
 {
     return(queryContext.ResolveType(context.TypeName, context.GetMeta()));
 }
コード例 #12
0
ファイル: TypeManager.cs プロジェクト: prepare/deveeldb
        DataType ITypeResolver.ResolveType(TypeResolveContext context)
        {
            var fullTypeName = Transaction.ResolveObjectName(context.TypeName);
            if (fullTypeName == null)
                return null;

            return GetUserType(fullTypeName);
        }