SqlType ITypeResolver.ResolveType(TypeResolveContext context) { var fullTypeName = ResolveName(ObjectName.Parse(context.TypeName), true); if (fullTypeName == null) { return(null); } return(GetUserType(fullTypeName)); }
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); }
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)); }
SqlType ITypeResolver.ResolveType(TypeResolveContext context) { var fullTypeName = ResolveName(ObjectName.Parse(context.TypeName), true); if (fullTypeName == null) return null; return GetUserType(fullTypeName); }
public SqlType ResolveType(TypeResolveContext context) { return queryContext.ResolveType(context.TypeName, context.GetMeta()); }
public static SqlType Resolve(TypeResolveContext context) { if (!context.IsPrimitive) { return(null); } var sqlType = context.TypeCode; if (sqlType == SqlTypeCode.Bit || 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 = -1; CultureInfo locale = null; var encoding = Encoding.Unicode; if (maxSizeMeta != null) { if (maxSizeMeta.Value == "MAX") { maxSize = StringType.DefaultMaxSize; } else { 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) { if (maxSizeMeta.Value == "MAX") { maxSize = BinaryType.DefaultMaxSize; } else { 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.YearToMonth || sqlType == SqlTypeCode.DayToSecond) { return(Interval(sqlType)); } if (sqlType == SqlTypeCode.Null) { return(Null(sqlType)); } // Ref types if (sqlType == SqlTypeCode.FieldRef) { var meta = context.GetMeta("FieldName"); if (meta == null) { throw new InvalidOperationException("Invalid construction of a %TYPE reference"); } var fieldName = ObjectName.Parse(meta.Value); return(new FieldRefType(fieldName)); } if (sqlType == SqlTypeCode.RowRef) { var meta = context.GetMeta("ObjectName"); if (meta == null) { throw new InvalidOperationException("Invalid construction of a %ROWTYPE reference"); } var objName = ObjectName.Parse(meta.Value); return(new RowRefType(objName)); } throw new ArgumentException(System.String.Format("The SQL type {0} is not primitive.", sqlType)); }
public static SqlType Resolve(TypeResolveContext context) { if (!context.IsPrimitive) return null; var sqlType = context.TypeCode; if (sqlType == SqlTypeCode.Bit || 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 = -1; CultureInfo locale = null; var encoding = Encoding.Unicode; if (maxSizeMeta != null) { if (maxSizeMeta.Value == "MAX") { maxSize = StringType.DefaultMaxSize; } else { 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) { if (maxSizeMeta.Value == "MAX") { maxSize = BinaryType.DefaultMaxSize; } else { 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.YearToMonth || sqlType == SqlTypeCode.DayToSecond) return Interval(sqlType); if (sqlType == SqlTypeCode.Null) return Null(sqlType); // Ref types if (sqlType == SqlTypeCode.FieldRef) { var meta = context.GetMeta("FieldName"); if (meta == null) throw new InvalidOperationException("Invalid construction of a %TYPE reference"); var fieldName = ObjectName.Parse(meta.Value); return new FieldRefType(fieldName); } if (sqlType == SqlTypeCode.RowRef) { var meta = context.GetMeta("ObjectName"); if (meta == null) throw new InvalidOperationException("Invalid construction of a %ROWTYPE reference"); var objName = ObjectName.Parse(meta.Value); return new RowRefType(objName); } throw new ArgumentException(System.String.Format("The SQL type {0} is not primitive.", sqlType)); }
public SqlType ResolveType(TypeResolveContext context) { return(queryContext.ResolveType(context.TypeName, context.GetMeta())); }