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 = Transaction.ResolveObjectName(context.TypeName); if (fullTypeName == null) { return(null); } return(GetUserType(fullTypeName)); }
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; }
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; } }
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 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); }
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)); }
public DataType ResolveType(TypeResolveContext context) { if (String.Equals(context.TypeName, "XMLNODE", StringComparison.OrdinalIgnoreCase)) return new XmlNodeType(); return null; }
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)); }
public DataType ResolveType(TypeResolveContext context) { return queryContext.ResolveType(context.TypeName, context.GetMeta()); }
public SqlType ResolveType(TypeResolveContext context) { return(queryContext.ResolveType(context.TypeName, context.GetMeta())); }
DataType ITypeResolver.ResolveType(TypeResolveContext context) { var fullTypeName = Transaction.ResolveObjectName(context.TypeName); if (fullTypeName == null) return null; return GetUserType(fullTypeName); }